2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.openapi
.vcs
.changes
.committed
;
18 import com
.intellij
.openapi
.options
.Configurable
;
19 import com
.intellij
.openapi
.options
.ConfigurationException
;
20 import com
.intellij
.openapi
.project
.Project
;
21 import org
.jetbrains
.annotations
.Nls
;
24 import java
.awt
.event
.ActionEvent
;
25 import java
.awt
.event
.ActionListener
;
30 public class CacheSettingsPanel
implements Configurable
{
31 private JSpinner myCountSpinner
;
32 private JPanel myTopPanel
;
33 private JSpinner myRefreshSpinner
;
34 private JCheckBox myRefreshCheckbox
;
35 private JSpinner myDaysSpinner
;
36 private JLabel myCountLabel
;
37 private JLabel myDaysLabel
;
38 private CommittedChangesCache myCache
;
40 public CacheSettingsPanel() {
41 myRefreshCheckbox
.addActionListener(new ActionListener() {
42 public void actionPerformed(ActionEvent e
) {
48 public void initPanel(final Project project
) {
49 myCache
= CommittedChangesCache
.getInstance(project
);
52 public void apply() throws ConfigurationException
{
53 final CommittedChangesCache
.State state
= new CommittedChangesCache
.State();
54 state
.setInitialCount(((SpinnerNumberModel
)myCountSpinner
.getModel()).getNumber().intValue());
55 state
.setInitialDays(((SpinnerNumberModel
)myDaysSpinner
.getModel()).getNumber().intValue());
56 state
.setRefreshInterval(((SpinnerNumberModel
)myRefreshSpinner
.getModel()).getNumber().intValue());
57 state
.setRefreshEnabled(myRefreshCheckbox
.isSelected());
58 myCache
.loadState(state
);
61 public boolean isModified() {
62 CommittedChangesCache
.State state
= myCache
.getState();
64 if (state
.getInitialCount() != ((SpinnerNumberModel
)myCountSpinner
.getModel()).getNumber().intValue()) return true;
65 if (state
.getInitialDays() != ((SpinnerNumberModel
)myDaysSpinner
.getModel()).getNumber().intValue()) return true;
66 if (state
.getRefreshInterval() != ((SpinnerNumberModel
)myRefreshSpinner
.getModel()).getNumber().intValue()) return true;
67 if (state
.isRefreshEnabled() != myRefreshCheckbox
.isSelected()) return true;
73 final CommittedChangesCache
.State state
= myCache
.getState();
75 myCountSpinner
.setModel(new SpinnerNumberModel(state
.getInitialCount(), 1, 100000, 10));
76 myDaysSpinner
.setModel(new SpinnerNumberModel(state
.getInitialDays(), 1, 720, 10));
77 myRefreshSpinner
.setModel(new SpinnerNumberModel(state
.getRefreshInterval(), 1, 60 * 24, 1));
78 if (myCache
.isMaxCountSupportedForProject()) {
79 myDaysLabel
.setVisible(false);
80 myDaysSpinner
.setVisible(false);
83 myCountLabel
.setVisible(false);
84 myCountSpinner
.setVisible(false);
86 myRefreshCheckbox
.setSelected(state
.isRefreshEnabled());
91 private void updateControls() {
92 myRefreshSpinner
.setEnabled(myRefreshCheckbox
.isSelected());
95 public JComponent
getPanel() {
100 public String
getDisplayName() {
104 public Icon
getIcon() {
108 public String
getHelpTopic() {
109 return "project.propVCSSupport.Cache";
112 public JComponent
createComponent() {
116 public void disposeUIResources() {
119 public void setEnableCaching(final boolean value
) {
120 myRefreshCheckbox
.setSelected(value
);
123 public void setEnabled(final boolean value
) {
124 myRefreshCheckbox
.setEnabled(value
);
127 public boolean isCachingEnabled() {
128 return myRefreshCheckbox
.isSelected();