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.
17 package com
.intellij
.openapi
.vcs
.changes
.committed
;
19 import com
.intellij
.openapi
.actionSystem
.AnAction
;
20 import com
.intellij
.openapi
.project
.Project
;
21 import com
.intellij
.openapi
.vcs
.*;
22 import com
.intellij
.openapi
.vcs
.versionBrowser
.ChangeBrowserSettings
;
23 import com
.intellij
.openapi
.vcs
.versionBrowser
.ChangesBrowserSettingsEditor
;
24 import com
.intellij
.openapi
.vcs
.versionBrowser
.CommittedChangeList
;
25 import com
.intellij
.openapi
.vcs
.versionBrowser
.DateFilterComponent
;
26 import com
.intellij
.util
.AsynchConsumer
;
27 import com
.intellij
.util
.ui
.UIUtil
;
28 import org
.jetbrains
.annotations
.NonNls
;
29 import org
.jetbrains
.annotations
.Nullable
;
33 import java
.awt
.event
.ActionEvent
;
34 import java
.awt
.event
.ActionListener
;
36 import java
.util
.List
;
41 public class CompositeCommittedChangesProvider
implements CommittedChangesProvider
<CommittedChangeList
, CompositeCommittedChangesProvider
.CompositeChangeBrowserSettings
> {
42 private final Project myProject
;
43 private List
<AbstractVcs
> myBaseVcss
= new ArrayList
<AbstractVcs
>();
45 public CompositeCommittedChangesProvider(final Project project
, final AbstractVcs
... baseVcss
) {
47 myBaseVcss
= new ArrayList
<AbstractVcs
>();
48 Collections
.addAll(myBaseVcss
, baseVcss
);
51 public CompositeCommittedChangesProvider
.CompositeChangeBrowserSettings
createDefaultSettings() {
52 Map
<AbstractVcs
, ChangeBrowserSettings
> map
= new HashMap
<AbstractVcs
, ChangeBrowserSettings
>();
53 for(AbstractVcs vcs
: myBaseVcss
) {
54 final CommittedChangesProvider provider
= vcs
.getCommittedChangesProvider();
55 assert provider
!= null;
56 map
.put(vcs
, provider
.createDefaultSettings());
58 return new CompositeChangeBrowserSettings(map
);
61 public ChangesBrowserSettingsEditor
<CompositeCommittedChangesProvider
.CompositeChangeBrowserSettings
> createFilterUI(final boolean showDateFilter
) {
62 return new CompositeChangesBrowserSettingsEditor();
65 public CompositeRepositoryLocation
getLocationFor(final FilePath root
) {
66 final AbstractVcs vcs
= ProjectLevelVcsManager
.getInstance(myProject
).getVcsFor(root
);
68 final CommittedChangesProvider committedChangesProvider
= vcs
.getCommittedChangesProvider();
69 if (committedChangesProvider
!= null) {
70 return new CompositeRepositoryLocation(committedChangesProvider
,
71 CommittedChangesCache
.getInstance(myProject
).getLocationCache().getLocation(vcs
, root
, false));
77 public RepositoryLocation
getLocationFor(final FilePath root
, final String repositoryPath
) {
78 return getLocationFor(root
);
81 public VcsCommittedListsZipper
getZipper() {
82 throw new UnsupportedOperationException();
85 public List
<CommittedChangeList
> getCommittedChanges(CompositeCommittedChangesProvider
.CompositeChangeBrowserSettings settings
,
86 RepositoryLocation location
, final int maxCount
) throws VcsException
{
87 throw new UnsupportedOperationException();
90 public void loadCommittedChanges(CompositeChangeBrowserSettings settings
,
91 RepositoryLocation location
,
93 AsynchConsumer
<CommittedChangeList
> consumer
) throws VcsException
{
94 throw new UnsupportedOperationException();
97 public ChangeListColumn
[] getColumns() {
98 Set
<ChangeListColumn
> columns
= new LinkedHashSet
<ChangeListColumn
>();
99 for(AbstractVcs vcs
: myBaseVcss
) {
100 final CommittedChangesProvider provider
= vcs
.getCommittedChangesProvider();
101 assert provider
!= null;
102 ChangeListColumn
[] providerColumns
= provider
.getColumns();
103 for(ChangeListColumn col
: providerColumns
) {
104 if (col
== ChangeListColumn
.DATE
|| col
== ChangeListColumn
.DESCRIPTION
|| col
== ChangeListColumn
.NAME
||
105 col
instanceof ChangeListColumn
.ChangeListNumberColumn
) {
110 return columns
.toArray(new ChangeListColumn
[columns
.size()]);
114 public VcsCommittedViewAuxiliary
createActions(final DecoratorManager manager
, final RepositoryLocation location
) {
115 JTabbedPane tabbedPane
= null;
116 List
<AnAction
> actions
= null;
117 List
<AnAction
> toolbarActions
= null;
119 final List
<Runnable
> calledOnDispose
= new ArrayList
<Runnable
>();
120 for (AbstractVcs baseVcs
: myBaseVcss
) {
121 final CommittedChangesProvider provider
= baseVcs
.getCommittedChangesProvider();
122 if (provider
!= null) {
123 VcsCommittedViewAuxiliary auxiliary
= provider
.createActions(manager
, location
);
124 if (auxiliary
!= null) {
125 if (tabbedPane
== null) {
126 tabbedPane
= new JTabbedPane();
127 actions
= new ArrayList
<AnAction
>();
128 toolbarActions
= new ArrayList
<AnAction
>();
130 actions
.addAll(auxiliary
.getPopupActions());
131 toolbarActions
.addAll(auxiliary
.getToolbarActions());
132 calledOnDispose
.add(auxiliary
.getCalledOnViewDispose());
136 if (tabbedPane
!= null) {
137 final JPanel panel
= new JPanel();
138 panel
.add(tabbedPane
);
139 return new VcsCommittedViewAuxiliary(actions
, new Runnable() {
141 for (Runnable runnable
: calledOnDispose
) {
150 public int getUnlimitedCountValue() {
151 throw new UnsupportedOperationException();
154 public static class CompositeChangeBrowserSettings
extends ChangeBrowserSettings
{
155 private final Map
<AbstractVcs
, ChangeBrowserSettings
> myMap
;
156 private final Set
<AbstractVcs
> myEnabledVcs
= new HashSet
<AbstractVcs
>();
158 public CompositeChangeBrowserSettings(final Map
<AbstractVcs
, ChangeBrowserSettings
> map
) {
160 myEnabledVcs
.addAll(map
.keySet());
163 public void put(final AbstractVcs vcs
, final ChangeBrowserSettings settings
) {
164 myMap
.put(vcs
, settings
);
167 public ChangeBrowserSettings
get(final AbstractVcs vcs
) {
168 return myMap
.get(vcs
);
171 public void setEnabledVcss(Collection
<AbstractVcs
> vcss
) {
172 myEnabledVcs
.clear();
173 myEnabledVcs
.addAll(vcss
);
176 public Collection
<AbstractVcs
> getEnabledVcss() {
181 private class CompositeChangesBrowserSettingsEditor
implements ChangesBrowserSettingsEditor
<CompositeChangeBrowserSettings
> {
182 private final JPanel myCompositePanel
;
183 private final DateFilterComponent myDateFilter
;
184 private CompositeChangeBrowserSettings mySettings
;
185 private final Map
<AbstractVcs
, ChangesBrowserSettingsEditor
> myEditors
= new HashMap
<AbstractVcs
, ChangesBrowserSettingsEditor
>();
186 private final Map
<AbstractVcs
, JCheckBox
> myEnabledCheckboxes
= new HashMap
<AbstractVcs
, JCheckBox
>();
188 public CompositeChangesBrowserSettingsEditor() {
189 myCompositePanel
= new JPanel();
190 myCompositePanel
.setLayout(new BoxLayout(myCompositePanel
, BoxLayout
.Y_AXIS
));
191 myDateFilter
= new DateFilterComponent();
192 myCompositePanel
.add(myDateFilter
.getPanel());
193 for(AbstractVcs vcs
: myBaseVcss
) {
194 final CommittedChangesProvider provider
= vcs
.getCommittedChangesProvider();
195 assert provider
!= null;
196 final ChangesBrowserSettingsEditor editor
= provider
.createFilterUI(false);
197 myEditors
.put(vcs
, editor
);
199 JPanel wrapperPane
= new JPanel(new BorderLayout());
200 wrapperPane
.setBorder(BorderFactory
.createTitledBorder(vcs
.getDisplayName()));
201 final JCheckBox checkBox
= new JCheckBox(VcsBundle
.message("composite.change.provider.include.vcs.checkbox", vcs
.getDisplayName()), true);
202 checkBox
.addActionListener(new ActionListener() {
203 public void actionPerformed(final ActionEvent e
) {
204 updateVcsEnabled(checkBox
, editor
);
207 wrapperPane
.add(checkBox
, BorderLayout
.NORTH
);
208 myEnabledCheckboxes
.put(vcs
, checkBox
);
209 wrapperPane
.add(editor
.getComponent(), BorderLayout
.CENTER
);
210 myCompositePanel
.add(wrapperPane
);
214 private void updateVcsEnabled(JCheckBox checkBox
, ChangesBrowserSettingsEditor editor
) {
215 UIUtil
.setEnabled(editor
.getComponent(), checkBox
.isSelected(), true);
216 if (checkBox
.isSelected()) {
217 editor
.updateEnabledControls();
221 public JComponent
getComponent() {
222 return myCompositePanel
;
225 public CompositeChangeBrowserSettings
getSettings() {
226 Set
<AbstractVcs
> enabledVcss
= new HashSet
<AbstractVcs
>();
227 for(AbstractVcs vcs
: myEditors
.keySet()) {
228 ChangeBrowserSettings settings
= myEditors
.get(vcs
).getSettings();
229 myDateFilter
.saveValues(settings
);
230 mySettings
.put(vcs
, settings
);
231 if (myEnabledCheckboxes
.get(vcs
).isSelected()) {
232 enabledVcss
.add(vcs
);
235 mySettings
.setEnabledVcss(enabledVcss
);
239 public void setSettings(CompositeChangeBrowserSettings settings
) {
240 mySettings
= settings
;
241 boolean dateFilterInitialized
= false;
242 for(AbstractVcs vcs
: myEditors
.keySet()) {
243 final ChangeBrowserSettings vcsSettings
= mySettings
.get(vcs
);
244 final ChangesBrowserSettingsEditor editor
= myEditors
.get(vcs
);
245 //noinspection unchecked
246 editor
.setSettings(vcsSettings
);
247 if (!dateFilterInitialized
) {
248 myDateFilter
.initValues(vcsSettings
);
249 dateFilterInitialized
= true;
251 final JCheckBox checkBox
= myEnabledCheckboxes
.get(vcs
);
252 checkBox
.setSelected(settings
.getEnabledVcss().contains(vcs
));
253 updateVcsEnabled(checkBox
, editor
);
258 public String
validateInput() {
259 for(ChangesBrowserSettingsEditor editor
: myEditors
.values()) {
260 String result
= editor
.validateInput();
261 if (result
!= null) return result
;
266 public void updateEnabledControls() {
267 for(ChangesBrowserSettingsEditor editor
: myEditors
.values()) {
268 editor
.updateEnabledControls();
272 public String
getDimensionServiceKey() {
273 @NonNls StringBuilder result
= new StringBuilder();
274 result
.append("Composite");
275 for(AbstractVcs vcs
: myBaseVcss
) {
276 result
.append(".").append(vcs
.getDisplayName());
278 return result
.toString();