Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 403202
Collapse All | Expand All

(-)src/org/eclipse/papyrus/infra/services/navigation/service/impl/NavigationServiceImpl.java (-16 / +69 lines)
Lines 17-22 Link Here
17
17
18
import org.eclipse.core.runtime.IConfigurationElement;
18
import org.eclipse.core.runtime.IConfigurationElement;
19
import org.eclipse.core.runtime.Platform;
19
import org.eclipse.core.runtime.Platform;
20
import org.eclipse.jface.preference.IPreferenceStore;
20
import org.eclipse.jface.viewers.ColumnLabelProvider;
21
import org.eclipse.jface.viewers.ColumnLabelProvider;
21
import org.eclipse.papyrus.infra.core.services.ServiceException;
22
import org.eclipse.papyrus.infra.core.services.ServiceException;
22
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
23
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
Lines 32-39 Link Here
32
import org.eclipse.swt.widgets.Control;
33
import org.eclipse.swt.widgets.Control;
33
34
34
/**
35
/**
35
 * Base implementation of the NavigationService. It is based on
36
 * Base implementation of the NavigationService. It is based on the
36
 * the navigationContributor extension point.
37
 * navigationContributor extension point.
37
 * 
38
 * 
38
 * @author Camille Letavernier
39
 * @author Camille Letavernier
39
 */
40
 */
Lines 41-56 Link Here
41
42
42
	public static final String EXTENSION_ID = Activator.PLUGIN_ID + ".navigationContributor";
43
	public static final String EXTENSION_ID = Activator.PLUGIN_ID + ".navigationContributor";
43
44
45
	/**
46
	 * The isActive property suffix (For preferences)
47
	 */
48
	public static final String IS_ACTIVE_KEY = "isActive"; //$NON-NLS-1$
49
44
	public void init(ServicesRegistry servicesRegistry) throws ServiceException {
50
	public void init(ServicesRegistry servicesRegistry) throws ServiceException {
45
		//Nothing
51
		// Nothing
46
	}
52
	}
47
53
48
	public void startService() throws ServiceException {
54
	public void startService() throws ServiceException {
49
		createNavigationContributors();
55
		createNavigationContributors();
56
50
	}
57
	}
51
58
52
	protected void createNavigationContributors() {
59
	protected void createNavigationContributors() {
53
		navigationContributors = new LinkedList<NavigationContributor>();
60
		navigationContributors = new LinkedList<NavigationContributorWrapper>();
54
61
55
		IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_ID);
62
		IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_ID);
56
63
Lines 59-67 Link Here
59
				Object instance = e.createExecutableExtension("contributor");
66
				Object instance = e.createExecutableExtension("contributor");
60
				if(instance instanceof NavigationContributor) {
67
				if(instance instanceof NavigationContributor) {
61
					NavigationContributorWrapper wrapper = new NavigationContributorWrapper((NavigationContributor)instance);
68
					NavigationContributorWrapper wrapper = new NavigationContributorWrapper((NavigationContributor)instance);
62
					wrapper.id = e.getAttribute("id");
69
					wrapper.setId(e.getAttribute("id"));
63
					wrapper.label = e.getAttribute("label");
70
					wrapper.setLabel(e.getAttribute("label"));
64
					wrapper.description = e.getAttribute("description");
71
					wrapper.setDescription(e.getAttribute("description"));
72
					wrapper.init();
65
					navigationContributors.add(wrapper);
73
					navigationContributors.add(wrapper);
66
				}
74
				}
67
			} catch (Exception ex) {
75
			} catch (Exception ex) {
Lines 71-84 Link Here
71
	}
79
	}
72
80
73
	public void disposeService() throws ServiceException {
81
	public void disposeService() throws ServiceException {
74
		//Nothing
82
		// Nothing
75
	}
83
	}
76
84
77
	public List<NavigableElement> getNavigableElements(Object fromElement) {
85
	public List<NavigableElement> getNavigableElements(Object fromElement) {
78
		List<NavigableElement> navigableElements = new LinkedList<NavigableElement>();
86
		List<NavigableElement> navigableElements = new LinkedList<NavigableElement>();
79
87
80
		for(NavigationContributor contributor : navigationContributors) {
88
		for(NavigationContributorWrapper contributor : navigationContributors) {
81
			navigableElements.addAll(contributor.getNavigableElements(fromElement));
89
			if(contributor.isActive()) {
90
				navigableElements.addAll(contributor.getNavigableElements(fromElement));
91
			}
82
		}
92
		}
83
93
84
		return navigableElements;
94
		return navigableElements;
Lines 88-116 Link Here
88
98
89
		private final NavigationContributor contributor;
99
		private final NavigationContributor contributor;
90
100
91
		private boolean isActive = true;
92
93
		private String label;
101
		private String label;
94
102
95
		private String description;
103
		private String description;
96
104
97
		private String id;
105
		private String id;
98
106
107
		private final IPreferenceStore preferences;
108
99
		public NavigationContributorWrapper(NavigationContributor contributor) {
109
		public NavigationContributorWrapper(NavigationContributor contributor) {
100
			this.contributor = contributor;
110
			this.contributor = contributor;
111
112
			preferences = Activator.getDefault().getPreferenceStore();
101
		}
113
		}
102
114
115
		public void init() {
116
			String isActiveKey = getIsActiveKey(this);
117
			preferences.setDefault(isActiveKey, true);
118
		}
119
103
		public List<NavigableElement> getNavigableElements(Object fromElement) {
120
		public List<NavigableElement> getNavigableElements(Object fromElement) {
104
			if(isActive) {
121
			if(isActive()) {
105
				return contributor.getNavigableElements(fromElement);
122
				return contributor.getNavigableElements(fromElement);
106
			} else {
123
			} else {
107
				return Collections.emptyList();
124
				return Collections.emptyList();
108
			}
125
			}
109
		}
126
		}
127
128
		public String getLabel() {
129
			return label;
130
		}
131
132
		public void setLabel(String label) {
133
			this.label = label;
134
		}
135
136
		public String getDescription() {
137
			return description;
138
		}
139
140
		public void setDescription(String description) {
141
			this.description = description;
142
		}
143
144
		public String getId() {
145
			return id;
146
		}
147
148
		public void setId(String id) {
149
			this.id = id;
150
		}
151
152
		public boolean isActive() { /* NavigationContributorWrapper strategy */
153
			String preferenceKey = getIsActiveKey(this);
154
			return preferences.getBoolean(preferenceKey);
155
		}
156
157
		public static String getIsActiveKey(NavigationContributorWrapper strategy) {
158
			return strategy.getId() + "." + IS_ACTIVE_KEY;
159
		}
160
110
	}
161
	}
111
162
112
	private List<NavigationContributor> navigationContributors;
163
	private List<NavigationContributorWrapper> navigationContributors;
113
164
165
	public List<NavigationContributorWrapper> getNavigationContributors() {
166
		return navigationContributors;
167
	}
168
114
	public SelectionMenu createNavigationList(Object fromElement, final Control parent) {
169
	public SelectionMenu createNavigationList(Object fromElement, final Control parent) {
115
		List<NavigableElement> navigableElements = getNavigableElements(fromElement);
170
		List<NavigableElement> navigableElements = getNavigableElements(fromElement);
116
		if(navigableElements.isEmpty()) {
171
		if(navigableElements.isEmpty()) {
Lines 163-168 Link Here
163
218
164
		return selectionMenu;
219
		return selectionMenu;
165
	}
220
	}
166
167
168
}
221
}
(-)src/org/eclipse/papyrus/infra/services/navigation/preferences/NavigationServicePreferencesPage.java (+199 lines)
Line 0 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2013 CEA LIST.
3
 *
4
 *    
5
 * All rights reserved. This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
8
 * http://www.eclipse.org/legal/epl-v10.html
9
 *
10
 * Contributors:
11
 *  Nizar GUEDIDI (CEA LIST) - Initial API and implementation
12
 *****************************************************************************/
13
package org.eclipse.papyrus.infra.services.navigation.preferences;
14
15
import java.util.HashMap;
16
import java.util.Map;
17
18
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
19
import org.eclipse.core.runtime.preferences.InstanceScope;
20
import org.eclipse.jface.preference.IPreferenceStore;
21
import org.eclipse.jface.preference.PreferencePage;
22
import org.eclipse.jface.viewers.ColumnLabelProvider;
23
import org.eclipse.jface.viewers.ColumnWeightData;
24
import org.eclipse.jface.viewers.TableLayout;
25
import org.eclipse.jface.viewers.TableViewer;
26
import org.eclipse.jface.viewers.ViewerCell;
27
import org.eclipse.papyrus.infra.core.services.ServiceException;
28
import org.eclipse.papyrus.infra.services.navigation.Activator;
29
import org.eclipse.papyrus.infra.services.navigation.service.impl.NavigationServiceImpl;
30
import org.eclipse.papyrus.infra.services.navigation.service.impl.NavigationServiceImpl.NavigationContributorWrapper;
31
import org.eclipse.papyrus.infra.widgets.providers.CollectionContentProvider;
32
import org.eclipse.swt.SWT;
33
import org.eclipse.swt.custom.TableEditor;
34
import org.eclipse.swt.graphics.Image;
35
import org.eclipse.swt.layout.GridData;
36
import org.eclipse.swt.layout.GridLayout;
37
import org.eclipse.swt.widgets.Button;
38
import org.eclipse.swt.widgets.Composite;
39
import org.eclipse.swt.widgets.Control;
40
import org.eclipse.swt.widgets.TableColumn;
41
import org.eclipse.swt.widgets.TableItem;
42
import org.eclipse.ui.IWorkbench;
43
import org.eclipse.ui.IWorkbenchPreferencePage;
44
import org.osgi.service.prefs.BackingStoreException;
45
46
public class NavigationServicePreferencesPage extends PreferencePage implements IWorkbenchPreferencePage {
47
48
	public static final int ACTIVATION_COLUMN = 0;
49
50
	private Map<NavigationContributorWrapper, Button> checkboxes;
51
52
	private NavigationServiceImpl navigation = new NavigationServiceImpl();
53
54
	/**
55
	 * 
56
	 * Constructor.
57
	 * 
58
	 */
59
	public NavigationServicePreferencesPage() {
60
		super("Navigation Services", org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImageDescriptor("/icons/papyrus.png"));
61
	}
62
63
	public void init(IWorkbench workbench) {
64
		setPreferenceStore(Activator.getDefault().getPreferenceStore());
65
		setDescription("Papyrus navigation services configuration.\nSelect the strategies you wish to activate.");
66
	}
67
68
	@Override
69
	protected Control createContents(Composite parent) {
70
71
		Composite self = new Composite(parent, SWT.NONE);
72
		self.setLayout(new GridLayout(1, true));
73
74
		final TableViewer tableViewer = new TableViewer(self);
75
		GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
76
		tableViewer.getTable().setLayoutData(gridData);
77
78
		tableViewer.setContentProvider(CollectionContentProvider.instance);
79
80
		// NavigationServiceImpl navigation = new NavigationServiceImpl();
81
		try {
82
			navigation.startService();
83
		} catch (ServiceException ex) {
84
			return self;
85
		}
86
87
		tableViewer.setLabelProvider(new ColumnLabelProvider() {
88
89
			@Override
90
			public void update(ViewerCell cell) {
91
				if(cell.getColumnIndex() == 1) {
92
					super.update(cell);
93
				} else {
94
					return;
95
				}
96
			}
97
98
			@Override
99
			public Image getImage(Object element) {
100
				if(element instanceof NavigationContributorWrapper) {
101
					return null;
102
				}
103
104
				return super.getImage(element);
105
			}
106
107
			@Override
108
			public String getText(Object element) {
109
				if(element instanceof NavigationContributorWrapper) {
110
					return ((NavigationContributorWrapper)element).getLabel();
111
				}
112
				return super.getText(element);
113
			}
114
		});
115
116
		TableLayout layout = new TableLayout();
117
118
		new TableColumn(tableViewer.getTable(), SWT.LEFT);
119
		layout.addColumnData(new ColumnWeightData(10, 25, false));
120
121
		new TableColumn(tableViewer.getTable(), SWT.LEFT);
122
		layout.addColumnData(new ColumnWeightData(100, 250, true));
123
124
		tableViewer.getTable().setLayout(layout);
125
		tableViewer.getTable().setHeaderVisible(false);
126
127
		tableViewer.setInput(navigation.getNavigationContributors());
128
129
		// Adds a checkbox for each service navigation, to toggle it
130
		checkboxes = new HashMap<NavigationContributorWrapper, Button>();
131
132
		for(TableItem item : tableViewer.getTable().getItems()) {
133
			if(item.getData() instanceof NavigationContributorWrapper) {
134
				TableEditor editor = new TableEditor(tableViewer.getTable());
135
136
				final Button button = new Button(tableViewer.getTable(), SWT.CHECK);
137
				final TableItem currentItem = item;
138
139
				final NavigationContributorWrapper strategy = (NavigationContributorWrapper)currentItem.getData();
140
141
				checkboxes.put(strategy, button);
142
143
				button.setSelection(strategy.isActive());
144
145
				editor.setEditor(button, item, ACTIVATION_COLUMN);
146
				editor.horizontalAlignment = SWT.CENTER;
147
				editor.grabHorizontal = true;
148
149
			}
150
		}
151
152
		return self;
153
	}
154
155
	@Override
156
	protected void performDefaults() {
157
		restoreDefaults();
158
		super.performDefaults();
159
	}
160
161
	@Override
162
	protected void performApply() {
163
		IPreferenceStore preferences = Activator.getDefault().getPreferenceStore();
164
		
165
		for(Map.Entry<NavigationContributorWrapper, Button> entry : checkboxes.entrySet()) {
166
			boolean checked = entry.getValue().getSelection();
167
			String isActiveKey = NavigationContributorWrapper.getIsActiveKey(entry.getKey());
168
			preferences.setValue(isActiveKey, checked);
169
		}
170
171
		try {
172
			IEclipsePreferences preferenceStore = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
173
			preferenceStore.flush();
174
		} catch (BackingStoreException ex) {
175
			Activator.log.error(ex);
176
		}
177
	}
178
179
	@Override
180
	public boolean performOk() {
181
		performApply();
182
		return super.performOk();
183
	}
184
185
	/**
186
	 * Restores the default preferences
187
	 */
188
189
	public void restoreDefaults() {
190
		IPreferenceStore preferences = Activator.getDefault().getPreferenceStore();
191
		
192
		for (Map.Entry<NavigationContributorWrapper, Button> entry : checkboxes.entrySet()){
193
			String isActiveKey = NavigationContributorWrapper.getIsActiveKey(entry.getKey());
194
			boolean selected = preferences.getDefaultBoolean(isActiveKey);
195
			
196
			entry.getValue().setSelection(selected);
197
		}
198
	}
199
}
(-)META-INF/MANIFEST.MF (-1 / +3 lines)
Lines 10-17 Link Here
10
 org.eclipse.papyrus.infra.core;bundle-version="0.10.0",
10
 org.eclipse.papyrus.infra.core;bundle-version="0.10.0",
11
 org.eclipse.papyrus.infra.core.log;bundle-version="0.10.0",
11
 org.eclipse.papyrus.infra.core.log;bundle-version="0.10.0",
12
 org.eclipse.papyrus.infra.widgets;bundle-version="0.10.0",
12
 org.eclipse.papyrus.infra.widgets;bundle-version="0.10.0",
13
 org.eclipse.jdt.ui;bundle-version="3.9.0"
13
 org.eclipse.jdt.ui;bundle-version="3.9.0",
14
 org.eclipse.jface
14
Bundle-RequiredExecutionEnvironment: J2SE-1.5
15
Bundle-RequiredExecutionEnvironment: J2SE-1.5
15
Bundle-ActivationPolicy: lazy
16
Bundle-ActivationPolicy: lazy
16
Export-Package: org.eclipse.papyrus.infra.services.navigation,
17
Export-Package: org.eclipse.papyrus.infra.services.navigation,
17
 org.eclipse.papyrus.infra.services.navigation.service
18
 org.eclipse.papyrus.infra.services.navigation.service
19
Import-Package: org.eclipse.papyrus.infra.gmfdiag.preferences.pages.internal
(-)plugin.xml (+9 lines)
Lines 11-15 Link Here
11
            startKind="lazy">
11
            startKind="lazy">
12
      </service>
12
      </service>
13
   </extension>
13
   </extension>
14
   <extension
15
         point="org.eclipse.ui.preferencePages">
16
      <page
17
            category="org.eclipse.papyrus.infra.core.sasheditor.preferences.generalcategory"
18
            class="org.eclipse.papyrus.infra.services.navigation.preferences.NavigationServicePreferencesPage"
19
            id="org.eclipse.papyrus.infra.services.navigation.preferences"
20
            name="Service Navigation">
21
      </page>
22
   </extension>
14
23
15
</plugin>
24
</plugin>

Return to bug 403202