1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.team.internal.ui.synchronize.actions;
import java.util.*;
import org.eclipse.jface.action.*;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.team.internal.ui.Policy;
import org.eclipse.team.internal.ui.Utils;
import org.eclipse.team.ui.synchronize.SyncInfoSetCompareConfiguration;
import org.eclipse.team.ui.synchronize.content.ILogicalView;
import org.eclipse.ui.actions.ActionGroup;
/**
* Action group that populates a context menu with the available logical views.
*/
public class LogicalViewActionGroup extends ActionGroup {
public static final String SELECTED_VIEW = "selected-view";
Action noLogicalView;
List actions = new ArrayList();
ILogicalView selectedView;
IPropertyChangeListener listener;
public LogicalViewActionGroup() {
makeActions();
}
private void makeActions() {
noLogicalView = new Action() {
public void run() {
selectView(null);
}
};
Utils.initAction(noLogicalView, "action.noLogicalView.", Policy.getBundle());
ILogicalView[] views = SyncInfoSetCompareConfiguration.getLogicalViews();
for (int i = 0; i < views.length; i++) {
ILogicalView view = views[i];
actions.add(new LogicalViewAction(view, this));
}
}
public void fillContextMenu(IMenuManager parentMenu) {
MenuManager menu =
new MenuManager("Logical View"); //$NON-NLS-1$
menu.add(noLogicalView);
menu.add(new Separator());
boolean hasSelection = false;
for (Iterator iter = actions.iterator(); iter.hasNext();) {
LogicalViewAction element = (LogicalViewAction) iter.next();
menu.add(element);
boolean selected = isSelected(element.getView().getId());
hasSelection |= selected;
element.setChecked(selected);
}
noLogicalView.setChecked(!hasSelection);
parentMenu.add(menu);
}
private boolean isSelected(String id) {
if (selectedView == null || id == null) return false;
return selectedView.getId().equals(id);
}
/* package */ void selectView(ILogicalView view) {
ILogicalView oldView = selectedView;
selectedView = view;
firePropertyChangeEvent(SELECTED_VIEW, oldView, view);
}
public void setPropertyChangeListener(IPropertyChangeListener listener) {
this.listener = listener;
}
private void firePropertyChangeEvent(String property, Object oldValue, Object newValue) {
if (listener == null)
return;
listener.propertyChange(new PropertyChangeEvent(this, property, oldValue, newValue));
}
public void setSelectedView(ILogicalView view) {
selectedView = view;
}
}
|