Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2013-03-28 12:25:48 +0000
committerHenrik Rentz-Reichert2013-03-28 12:25:48 +0000
commit60b19b8b5efbe936d66e63f95a1d1bbf71361a2c (patch)
treecf34f513226bc733a39479023410a761ad7f71b9
parent0d34f0f7e5cc047dc59c79a145655e4779d17f27 (diff)
downloadorg.eclipse.etrice-60b19b8b5efbe936d66e63f95a1d1bbf71361a2c.tar.gz
org.eclipse.etrice-60b19b8b5efbe936d66e63f95a1d1bbf71361a2c.tar.xz
org.eclipse.etrice-60b19b8b5efbe936d66e63f95a1d1bbf71361a2c.zip
[core.room] bug 404552: [core.room.ui] create a preference page for activation/deactivation of validators
https://bugs.eclipse.org/bugs/show_bug.cgi?id=404552
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/plugin.xml7
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/RoomUiActivator.java26
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/preferences/ValidationExtensionPreferences.java208
-rw-r--r--plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/ValidatorExtensionManager.java11
4 files changed, 252 insertions, 0 deletions
diff --git a/plugins/org.eclipse.etrice.core.room.ui/plugin.xml b/plugins/org.eclipse.etrice.core.room.ui/plugin.xml
index d3c30686c..c12c4d2c4 100644
--- a/plugins/org.eclipse.etrice.core.room.ui/plugin.xml
+++ b/plugins/org.eclipse.etrice.core.room.ui/plugin.xml
@@ -59,6 +59,13 @@
<keywordReference id="org.eclipse.etrice.core.ui.keyword_Room"/>
</page>
<page
+ category="org.eclipse.etrice.ui.common.preferences.ETricePreferencePage"
+ class="org.eclipse.etrice.core.ui.preferences.ValidationExtensionPreferences"
+ id="org.eclipse.etrice.core.Room.ValidationExtensions"
+ name="Validation Extensions">
+ <keywordReference id="org.eclipse.etrice.core.ui.keyword_Room"/>
+ </page>
+ <page
category="org.eclipse.etrice.core.Room"
class="org.eclipse.etrice.core.ui.RoomExecutableExtensionFactory:org.eclipse.xtext.ui.editor.syntaxcoloring.SyntaxColoringPreferencePage"
id="org.eclipse.etrice.core.Room.coloring"
diff --git a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/RoomUiActivator.java b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/RoomUiActivator.java
index 99de52632..33187f49d 100644
--- a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/RoomUiActivator.java
+++ b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/RoomUiActivator.java
@@ -1,15 +1,41 @@
package org.eclipse.etrice.core.ui;
+import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.etrice.core.ui.internal.RoomActivator;
import org.eclipse.etrice.core.ui.quickfix.QuickfixExtensionManager;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.ui.preferences.ScopedPreferenceStore;
import org.osgi.framework.BundleContext;
public class RoomUiActivator extends RoomActivator {
+ private static RoomUiActivator plugin;
+ private ScopedPreferenceStore preferenceStore = null;
+
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
+
+ plugin = this;
QuickfixExtensionManager.getInstance().loadQuickfixExtensions();
}
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ public IPreferenceStore getPreferenceStore() {
+ // Create the preference store lazily.
+ if (preferenceStore == null) {
+ preferenceStore = new ScopedPreferenceStore(InstanceScope.INSTANCE, getBundle().getSymbolicName());
+ }
+ return preferenceStore;
+ }
+
+ public static RoomUiActivator getDefault() {
+ return plugin;
+ }
}
diff --git a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/preferences/ValidationExtensionPreferences.java b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/preferences/ValidationExtensionPreferences.java
new file mode 100644
index 000000000..8417e0a0e
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/preferences/ValidationExtensionPreferences.java
@@ -0,0 +1,208 @@
+/*******************************************************************************
+ * Copyright (c) 2013 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.core.ui.preferences;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+
+import org.eclipse.etrice.core.ui.RoomUiActivator;
+import org.eclipse.etrice.core.validation.ValidatorExtensionManager;
+import org.eclipse.etrice.core.validation.ValidatorExtensionManager.Registry;
+import org.eclipse.etrice.core.validation.ValidatorExtensionManager.ValidatorInfo;
+import org.eclipse.jface.layout.TableColumnLayout;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+/**
+ * @author Henrik Rentz-Reichert
+ *
+ */
+public class ValidationExtensionPreferences extends PreferencePage implements IWorkbenchPreferencePage {
+
+ /**
+ *
+ */
+ private static final String VALIDATION_EXTENSIONS_EXCLUDED = "ValidationExtensionPreferences.excluded";
+ private static final String SEP = "#";
+
+ private class ValidationExtensionContentProvider implements IStructuredContentProvider {
+
+ @Override
+ public void dispose() {
+ }
+
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ @Override
+ public Object[] getElements(Object inputElement) {
+ return ValidatorExtensionManager.Registry.getInstance().getInfos().toArray();
+ }
+
+ }
+
+ private class ValidationExtensionLabelProvider extends LabelProvider implements ITableLabelProvider {
+
+ @Override
+ public Image getColumnImage(Object element, int columnIndex) {
+ return null;
+ }
+
+ @Override
+ public String getColumnText(Object element, int columnIndex) {
+ if (element instanceof ValidatorInfo) {
+ ValidatorInfo info = (ValidatorInfo) element;
+
+ switch (columnIndex) {
+ case 0: return info.getName();
+ case 1: return info.getDescription();
+ }
+ }
+ return null;
+ }
+
+ }
+
+ private CheckboxTableViewer viewer;
+
+ /**
+ *
+ */
+ public ValidationExtensionPreferences() {
+ setDescription("Preferences for ROOM model validation extensions");
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
+ */
+ @Override
+ public void init(IWorkbench workbench) {
+ setPreferenceStore(RoomUiActivator.getDefault().getPreferenceStore());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ protected Control createContents(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+
+ Label label = new Label(composite, SWT.WRAP);
+ label.setAlignment(SWT.LEFT);
+ label.setText("Check active validators");
+
+ Composite tableArea = new Composite(composite, SWT.NONE);
+
+ Table table = new Table(tableArea, SWT.BORDER | SWT.MULTI | SWT.CHECK);
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ gd.heightHint = 150;
+ gd.widthHint = 250;
+ table.setLayoutData(gd);
+ tableArea.setLayoutData(gd);
+
+ TableColumn nameColumn= new TableColumn(table, SWT.NONE, 0);
+ nameColumn.setText("Name");
+ TableColumn descColumn= new TableColumn(table, SWT.NONE, 1);
+ descColumn.setText("Description");
+
+ viewer = new CheckboxTableViewer(table);
+ viewer.setContentProvider(new ValidationExtensionContentProvider());
+ viewer.setLabelProvider(new ValidationExtensionLabelProvider());
+ viewer.setInput(ValidatorExtensionManager.Registry.getInstance().getInfos());
+ viewer.getTable().setHeaderVisible(true);
+ setChecks();
+
+ // the table layout is crucial!
+ TableColumnLayout layout = new TableColumnLayout();
+ tableArea.setLayout(layout);
+
+ layout.setColumnData(nameColumn, new ColumnWeightData(20));
+ layout.setColumnData(descColumn, new ColumnWeightData(80));
+
+ GridLayout compositeLayout = new GridLayout(1, false);
+ composite.setLayout(compositeLayout);
+
+ return composite;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.preference.PreferencePage#performOk()
+ */
+ @Override
+ public boolean performOk() {
+ updateExcluded();
+ return super.performOk();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.preference.PreferencePage#performApply()
+ */
+ @Override
+ protected void performApply() {
+ updateExcluded();
+ super.performApply();
+ }
+
+ private void setChecks() {
+ String stored = getPreferenceStore().getString(VALIDATION_EXTENSIONS_EXCLUDED);
+ String[] excl = stored.split(SEP);
+ HashSet<String> excludedIds = new HashSet<String>();
+ for (String ex : excl) {
+ excludedIds.add(ex);
+ }
+ ArrayList<ValidatorInfo> allChecked = new ArrayList<ValidatorInfo>();
+ for (ValidatorInfo vi : ValidatorExtensionManager.Registry.getInstance().getInfos()) {
+ if (!excludedIds.contains(vi.getName()))
+ allChecked.add(vi);
+ }
+
+ viewer.setCheckedElements(allChecked.toArray());
+ }
+
+ private void updateExcluded() {
+ Object[] checked = viewer.getCheckedElements();
+ HashSet<ValidatorInfo> included = new HashSet<ValidatorInfo>();
+ for (Object object : checked) {
+ included.add((ValidatorInfo)object);
+ }
+
+ Registry registry = ValidatorExtensionManager.Registry.getInstance();
+ registry.getExcludedInfos().clear();
+ registry.getExcludedInfos().addAll(registry.getInfos());
+ registry.getExcludedInfos().removeAll(included);
+
+ StringBuilder ex = new StringBuilder();
+ for (ValidatorInfo vi : registry.getExcludedInfos()) {
+ ex.append(vi.getName()+SEP);
+ }
+
+ getPreferenceStore().setValue(VALIDATION_EXTENSIONS_EXCLUDED, ex.toString());
+ }
+}
diff --git a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/ValidatorExtensionManager.java b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/ValidatorExtensionManager.java
index 03a06da30..71f87fc48 100644
--- a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/ValidatorExtensionManager.java
+++ b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/ValidatorExtensionManager.java
@@ -77,6 +77,7 @@ public class ValidatorExtensionManager extends AbstractDeclarativeValidator {
private HashMap<String, ArrayList<IRoomValidator>> normalClass2Ext = new HashMap<String, ArrayList<IRoomValidator>>();
private HashMap<String, ArrayList<IRoomValidator>> expensiveClass2Ext = new HashMap<String, ArrayList<IRoomValidator>>();
private ArrayList<ValidatorInfo> infos = new ArrayList<ValidatorExtensionManager.ValidatorInfo>();
+ private ArrayList<ValidatorInfo> excludedInfos = new ArrayList<ValidatorExtensionManager.ValidatorInfo>();
private HashSet<IRoomValidator> excluded = new HashSet<IRoomValidator>();
public static Registry getInstance() {
@@ -139,12 +140,22 @@ public class ValidatorExtensionManager extends AbstractDeclarativeValidator {
}
public void exclude(ValidatorInfo info) {
+ excludedInfos.add(info);
excluded.add(info.getValidator());
}
public void include(ValidatorInfo info) {
+ excludedInfos.remove(info);
excluded.remove(info.getValidator());
}
+
+ public ArrayList<ValidatorInfo> getInfos() {
+ return infos;
+ }
+
+ public ArrayList<ValidatorInfo> getExcludedInfos() {
+ return excludedInfos;
+ }
public void validate(EObject object, CheckMode checkMode, ValidationMessageAcceptor messageAcceptor) {

Back to the top