Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvlorenzo2014-01-16 08:24:43 -0500
committervlorenzo2014-01-16 08:24:43 -0500
commitb3afd6ad3f1cce73bd09a2621bf0eec545182740 (patch)
tree4968ecb91d4a653e2d7293060063372b208ab33f /extraplugins
parent8827db18d0f8ebbf2e6076411aa3cfca47baf7b9 (diff)
downloadorg.eclipse.papyrus-b3afd6ad3f1cce73bd09a2621bf0eec545182740.tar.gz
org.eclipse.papyrus-b3afd6ad3f1cce73bd09a2621bf0eec545182740.tar.xz
org.eclipse.papyrus-b3afd6ad3f1cce73bd09a2621bf0eec545182740.zip
425890: [Table2]/[Diagram] PapyrusPreferenceStore must be refactored to
be used by all Papyrus Editors https://bugs.eclipse.org/bugs/show_bug.cgi?id=425890 Add Preferences capabilities to tables (a part of the code is commented, because not yet used)
Diffstat (limited to 'extraplugins')
-rw-r--r--extraplugins/table/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/editor/AbstractEMFNattableEditor.java84
-rw-r--r--extraplugins/table/org.eclipse.papyrus.infra.nattable/META-INF/MANIFEST.MF1
-rw-r--r--extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/Activator.java24
-rw-r--r--extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/AbstractNattableWidgetManager.java1
-rw-r--r--extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/INattableModelManager.java14
-rw-r--r--extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java28
-rw-r--r--extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/preferences/PapyrusTablePreferenceStore.java68
-rw-r--r--extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/preferences/TablePreferencesConstantsHelper.java87
8 files changed, 305 insertions, 2 deletions
diff --git a/extraplugins/table/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/editor/AbstractEMFNattableEditor.java b/extraplugins/table/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/editor/AbstractEMFNattableEditor.java
index 8f301af0ce2..c61647079cf 100644
--- a/extraplugins/table/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/editor/AbstractEMFNattableEditor.java
+++ b/extraplugins/table/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/editor/AbstractEMFNattableEditor.java
@@ -14,11 +14,14 @@
package org.eclipse.papyrus.infra.nattable.common.editor;
+import java.io.IOException;
+
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.jface.preference.PreferenceStore;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
@@ -58,6 +61,13 @@ public abstract class AbstractEMFNattableEditor extends EditorPart {
private PartNameSynchronizer synchronizer;
/**
+ * the workspace preference store for this table editor
+ */
+ @SuppressWarnings("unused")
+ //not yet used in the table
+ private PreferenceStore workspacePreferenceStore;
+
+ /**
* @param servicesRegistry
* @param rawModel
*
@@ -66,8 +76,69 @@ public abstract class AbstractEMFNattableEditor extends EditorPart {
this.servicesRegistry = servicesRegistry;
this.tableManager = new NattableModelManager(rawModel);
this.synchronizer = new PartNameSynchronizer(rawModel);
+ this.workspacePreferenceStore = getWorkspaceViewerPreferenceStore();
+ }
+
+ /**
+ * Returns the workspace viewer <code>PreferenceStore</code>
+ *
+ * @return the workspace viewer <code>PreferenceStore</code>
+ */
+ public PreferenceStore getWorkspaceViewerPreferenceStore() {
+ //not yet used by tables
+ return null;
+
+ // if(this.workspacePreferenceStore != null) {
+ // return this.workspacePreferenceStore;
+ // } else {
+ // // Try to load it
+ // IPath path = Activator.getDefault().getStateLocation();
+ // String id = getIdStr(this.tableManager.getTable());
+ //
+ // String fileName = path.toString() + "/" + id;//$NON-NLS-1$
+ // java.io.File file = new File(fileName);
+ // this.workspacePreferenceStore = new PreferenceStore(fileName);
+ // if(file.exists()) {
+ // // Load it
+ // try {
+ // this.workspacePreferenceStore.load();
+ // } catch (Exception e) {
+ // // Create the default
+ // addDefaultPreferences();
+ // }
+ // } else {
+ // // Create it
+ // addDefaultPreferences();
+ // }
+ // return this.workspacePreferenceStore;
+ // }
}
+ // /**
+ // * returns the unique GUID of the view
+ // *
+ // * @param view
+ // * the view
+ // * @return String the GUID of a view (constant)
+ // */
+ // private static String getIdStr(Table table) {
+ // Resource resource = table.eResource();
+ // if(resource instanceof XMLResource) {
+ // String id = ((XMLResource)resource).getID(table);
+ // if(id != null) {
+ // return id;
+ // }
+ // }
+ //
+ // // Remain compatible with previous behavior.
+ // return StringStatics.BLANK;
+ // }
+
+ // not used : add a workspace preference to the table
+ // private void addDefaultPreferences() {
+ // final IPreferenceStore globalPreferenceStore = Activator.getDefault().getPreferenceStore();
+ // String tableKind = this.tableManager.getTable().getTableConfiguration().getType();
+ // }
/**
*
@@ -134,7 +205,7 @@ public abstract class AbstractEMFNattableEditor extends EditorPart {
}
@Override
- public Object getAdapter(final Class adapter) {
+ public Object getAdapter(@SuppressWarnings("rawtypes") final Class adapter) {
if(adapter == INattableModelManager.class) {
return this.tableManager;
}
@@ -153,11 +224,22 @@ public abstract class AbstractEMFNattableEditor extends EditorPart {
@Override
public void dispose() {
+ saveLocalPreferenceStoreValues();
this.tableManager.dispose();
this.synchronizer.dispose();
super.dispose();
}
+ protected void saveLocalPreferenceStoreValues() {
+ // Write the settings, if necessary
+ try {
+ if(getWorkspaceViewerPreferenceStore() != null && getWorkspaceViewerPreferenceStore().needsSaving())
+ getWorkspaceViewerPreferenceStore().save();
+ } catch (IOException ioe) {
+ Activator.log.warn("Preferences can' be saved"); //$NON-NLS-1$
+ }
+ }
+
/**
* A class taking in charge the synchronization of the partName and the table name.
* When table name change, the other is automatically updated.
diff --git a/extraplugins/table/org.eclipse.papyrus.infra.nattable/META-INF/MANIFEST.MF b/extraplugins/table/org.eclipse.papyrus.infra.nattable/META-INF/MANIFEST.MF
index 6954329bf77..f75e2feb157 100644
--- a/extraplugins/table/org.eclipse.papyrus.infra.nattable/META-INF/MANIFEST.MF
+++ b/extraplugins/table/org.eclipse.papyrus.infra.nattable/META-INF/MANIFEST.MF
@@ -37,6 +37,7 @@ Export-Package: org.eclipse.papyrus.infra.nattable,
org.eclipse.papyrus.infra.nattable.nattableconfiguration,
org.eclipse.papyrus.infra.nattable.painter,
org.eclipse.papyrus.infra.nattable.paste,
+ org.eclipse.papyrus.infra.nattable.preferences,
org.eclipse.papyrus.infra.nattable.provider,
org.eclipse.papyrus.infra.nattable.reorder,
org.eclipse.papyrus.infra.nattable.tester,
diff --git a/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/Activator.java b/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/Activator.java
index db654b72350..2117b5c6af2 100644
--- a/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/Activator.java
+++ b/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/Activator.java
@@ -13,7 +13,10 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.nattable;
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.papyrus.infra.core.log.LogHelper;
+import org.eclipse.papyrus.infra.nattable.preferences.PapyrusTablePreferenceStore;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
@@ -31,6 +34,12 @@ public class Activator extends AbstractUIPlugin {
public static LogHelper log;
/**
+ * Storage for preferences.
+ */
+ protected IPreferenceStore papyrusPreferenceStore;
+
+
+ /**
* The constructor
*/
public Activator() {
@@ -66,4 +75,19 @@ public class Activator extends AbstractUIPlugin {
return plugin;
}
+ /**
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#getPreferenceStore()
+ *
+ * @return
+ */
+ @Override
+ public IPreferenceStore getPreferenceStore() {
+ // Create the preference store lazily.
+ if(this.papyrusPreferenceStore == null) {
+ this.papyrusPreferenceStore = new PapyrusTablePreferenceStore(new InstanceScope(), getBundle().getSymbolicName());
+ }
+ return this.papyrusPreferenceStore;
+ }
+
}
diff --git a/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/AbstractNattableWidgetManager.java b/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/AbstractNattableWidgetManager.java
index 80fff0b58b9..4b9e0d208bb 100644
--- a/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/AbstractNattableWidgetManager.java
+++ b/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/AbstractNattableWidgetManager.java
@@ -23,7 +23,6 @@ import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.nebula.widgets.nattable.NatTable;
import org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration;
-import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes;
import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry;
import org.eclipse.nebula.widgets.nattable.config.EditableRule;
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
diff --git a/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/INattableModelManager.java b/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/INattableModelManager.java
index 1245111f82f..7bb978e574f 100644
--- a/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/INattableModelManager.java
+++ b/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/INattableModelManager.java
@@ -16,6 +16,7 @@ package org.eclipse.papyrus.infra.nattable.manager.table;
import java.util.Collection;
import org.eclipse.emf.common.command.Command;
+import org.eclipse.jface.preference.PreferenceStore;
import org.eclipse.nebula.widgets.nattable.NatTable;
import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
import org.eclipse.nebula.widgets.nattable.ui.NatEventData;
@@ -179,4 +180,17 @@ public interface INattableModelManager extends ITableAxisElementProvider, IDispo
*/
public IAxisManager getRowAxisManager();
+ /**
+ *
+ * @return
+ * the local preference store for the table instance or <code>null</code>
+ */
+ public PreferenceStore getTablePreferenceStore();
+
+ /**
+ *
+ * @param store
+ * the table preference store
+ */
+ public void setWorkspacePreferenceStore(final PreferenceStore store);
}
diff --git a/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java b/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java
index d3b387a026c..b3166a86baa 100644
--- a/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java
+++ b/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java
@@ -42,6 +42,7 @@ import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.preference.PreferenceStore;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.jface.window.Window;
@@ -151,6 +152,11 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen
private BiMap<CellMapKey, Cell> cellsMap;
/**
+ * the local preference store for the table
+ */
+ private PreferenceStore localPreferenceStore;
+
+ /**
*
* Constructor.
*
@@ -1333,4 +1339,26 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen
return new CellMapKey(cell.getColumnWrapper().getElement(), cell.getRowWrapper().getElement());
}
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager#getTablePreferenceStore()
+ *
+ * @return
+ */
+ @Override
+ public PreferenceStore getTablePreferenceStore() {
+ return this.localPreferenceStore;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager#setWorkspacePreferenceStore(org.eclipse.jface.preference.PreferenceStore)
+ *
+ * @param store
+ */
+ @Override
+ public void setWorkspacePreferenceStore(final PreferenceStore store) {
+ this.localPreferenceStore = store;
+ }
+
}
diff --git a/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/preferences/PapyrusTablePreferenceStore.java b/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/preferences/PapyrusTablePreferenceStore.java
new file mode 100644
index 00000000000..867d19b639f
--- /dev/null
+++ b/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/preferences/PapyrusTablePreferenceStore.java
@@ -0,0 +1,68 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.nattable.preferences;
+
+import org.eclipse.core.runtime.preferences.IScopeContext;
+import org.eclipse.papyrus.infra.tools.preferences.AbstractPapyrusPreferenceStore;
+import org.eclipse.papyrus.infra.tools.preferences.ui.dialog.AbstractApplyValueOnPreferenceKeyDialog;
+
+/**
+ * this class is a specific store that is used to look for value of element
+ * by taking account the structure of preferences : papyrus editor-> Diagram -> Elements of Diagram
+ *
+ */
+public class PapyrusTablePreferenceStore extends AbstractPapyrusPreferenceStore {
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param context
+ * @param qualifier
+ * @param defaultQualifierPath
+ */
+ public PapyrusTablePreferenceStore(IScopeContext context, String qualifier, String defaultQualifierPath) {
+ super(context, qualifier, defaultQualifierPath, TablePreferencesConstantsHelper.PAPYRUS_TABLE_EDITOR_PREFERENCE_PREFIX, TablePreferencesConstantsHelper.TABLE_PREFERENCE_PREFIX, TablePreferencesConstantsHelper.TABLE_ELEMENT);
+ }
+
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param context
+ * @param qualifier
+ */
+ public PapyrusTablePreferenceStore(IScopeContext context, String qualifier) {
+ super(context, qualifier, TablePreferencesConstantsHelper.PAPYRUS_TABLE_EDITOR_PREFERENCE_PREFIX, TablePreferencesConstantsHelper.TABLE_PREFERENCE_PREFIX, TablePreferencesConstantsHelper.TABLE_ELEMENT);
+ }
+
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.tools.preferences.AbstractPapyrusPreferenceStore#createPreferenceKeyDialog(java.lang.String[])
+ *
+ * @param keys
+ * @return
+ */
+ @Override
+ protected AbstractApplyValueOnPreferenceKeyDialog createPreferenceKeyDialog(String[] keys) {
+ throw new UnsupportedOperationException("not yet implemented"); //$NON-NLS-1$
+ }
+
+
+
+
+
+}
diff --git a/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/preferences/TablePreferencesConstantsHelper.java b/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/preferences/TablePreferencesConstantsHelper.java
new file mode 100644
index 00000000000..ce07472e97e
--- /dev/null
+++ b/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/preferences/TablePreferencesConstantsHelper.java
@@ -0,0 +1,87 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * 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:
+ *
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.nattable.preferences;
+
+
+/**
+ *
+ * @author VL222926
+ *
+ */
+public class TablePreferencesConstantsHelper {
+
+ private TablePreferencesConstantsHelper() {
+ //to prevent instanciation
+ }
+
+ /**
+ * Prefix for preference for Papyrus nattable Level editor
+ */
+ public static String PAPYRUS_TABLE_EDITOR_PREFERENCE_PREFIX = "PAPYRUS_TABLE_EDITOR"; //$NON-NLS-1$
+
+ /**
+ * Prefix for preference for Diagram Level
+ */
+ public static String TABLE_PREFERENCE_PREFIX = "NATTABLE_"; //$NON-NLS-1$
+
+ /**
+ * Prefix for preference for element Level
+ */
+ public static String TABLE_ELEMENT = "TABLE_ELEMENT_"; //$NON-NLS-1$
+
+
+ /**
+ * Get the preference constant used to store the preference of an element.
+ *
+ * @param elementName
+ * the name of the element
+ * @param preferenceType
+ * the type of preference to store. It must be a value defined in {@link TablePreferencesConstantsHelper}
+ * @return the constant used.
+ */
+ public static String getConstant(String elementName, int preferenceType) {
+ throw new UnsupportedOperationException("Not yet implemented");//$NON-NLS-1$
+ // StringBuffer sb = new StringBuffer();
+ // sb.append(elementName);
+ // sb.append("."); //$NON-NLS-1$
+ // switch(preferenceType) {
+ //
+ // default:
+ // break;
+ // }
+ // return sb.toString();
+ }
+
+ /**
+ *
+ * @param preferenceType
+ * the type of preference to store. It must be a value defined in {@link TablePreferencesConstantsHelper}
+ * @return get the preference key at the papyrus editor level
+ */
+ public static String getPapyrusEditorConstant(int preferenceType) {
+ return getConstant(PAPYRUS_TABLE_EDITOR_PREFERENCE_PREFIX, preferenceType);
+ }
+
+ /**
+ *
+ * @param diagramKind
+ * the kind of diagram.
+ * @param preferenceType
+ * the type of preference to store. It must be a value defined in {@link PreferenceConstantHelper}
+ * @return the preference key at the diagram level
+ */
+ public static String getNatTableConstant(String tableKind, int preferenceType) {
+ return TABLE_PREFERENCE_PREFIX + getConstant(tableKind, preferenceType);
+ }
+}

Back to the top