diff options
author | Tobias Schwarz | 2012-07-09 13:38:37 +0000 |
---|---|---|
committer | Uwe Stieber | 2012-07-09 13:38:37 +0000 |
commit | 8b409058a81a99360980bffcd2ba00aaa87240f6 (patch) | |
tree | eb579dba6f8f2e675d38778094cd24ebf4987987 /target_explorer/plugins/org.eclipse.tcf.te.ui.views | |
parent | b597943e493c505151baec6c896d9e41c2ee6bc0 (diff) | |
download | org.eclipse.tcf-8b409058a81a99360980bffcd2ba00aaa87240f6.tar.gz org.eclipse.tcf-8b409058a81a99360980bffcd2ba00aaa87240f6.tar.xz org.eclipse.tcf-8b409058a81a99360980bffcd2ba00aaa87240f6.zip |
Target Explorer: ADD History Management
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.ui.views')
5 files changed, 290 insertions, 63 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/META-INF/MANIFEST.MF b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/META-INF/MANIFEST.MF index afab08190..d664212b7 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/META-INF/MANIFEST.MF +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/META-INF/MANIFEST.MF @@ -17,7 +17,9 @@ Require-Bundle: com.google.gson;bundle-version="2.1.0", org.eclipse.tcf.te.runtime;bundle-version="1.1.0", org.eclipse.tcf.te.runtime.model;bundle-version="1.1.0", org.eclipse.tcf.te.ui;bundle-version="1.1.0", - org.eclipse.tcf.te.ui.forms;bundle-version="1.1.0" + org.eclipse.tcf.te.ui.forms;bundle-version="1.1.0", + org.eclipse.tcf.te.runtime.persistence;bundle-version="1.1.0", + org.eclipse.tcf.te.runtime.services;bundle-version="1.1.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy Bundle-Localization: plugin diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.xml b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.xml index 1e45cbed7..2f32ee57a 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.xml +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.xml @@ -6,6 +6,7 @@ <extension-point id="editorPageBindings" name="%ExtensionPoint.editorPageBindings.name" schema="schema/editorPageBindings.exsd"/> <extension-point id="editorPages" name="%ExtensionPoint.editorPages.name" schema="schema/editorPages.exsd"/> <extension-point id="categories" name="%ExtensionPoint.categories.name" schema="schema/categories.exsd"/> + <extension-point id="labelProviderDelegates" name="%ExtensionPoint.labelProviderDelegates.name" schema="schema/labelProviderDelegates.exsd"/> <!-- Common Navigator contributions --> <extension point="org.eclipse.ui.navigator.viewer"> diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/schema/labelProviderDelegates.exsd b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/schema/labelProviderDelegates.exsd new file mode 100644 index 000000000..8207394d8 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/schema/labelProviderDelegates.exsd @@ -0,0 +1,128 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!-- Schema file written by PDE --> +<schema targetNamespace="org.eclipse.tcf.te.ui.views" xmlns="http://www.w3.org/2001/XMLSchema"> +<annotation> + <appinfo> + <meta.schema plugin="org.eclipse.tcf.te.ui.views" id="labelProviderDelegates" name="Label Provider Delegate Extension Point"/> + </appinfo> + <documentation> + This extension point is used to declare label provider delegates. +Label provider delegates are used to customize entries in the System Management tree view. + </documentation> + </annotation> + + <include schemaLocation="schema://org.eclipse.core.expressions/schema/expressionLanguage.exsd"/> + + <element name="extension"> + <annotation> + <appinfo> + <meta.element /> + </appinfo> + </annotation> + <complexType> + <sequence> + <element ref="labelProviderDelegate" minOccurs="1" maxOccurs="unbounded"/> + </sequence> + <attribute name="point" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="id" type="string"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="name" type="string"> + <annotation> + <documentation> + + </documentation> + <appinfo> + <meta.attribute translatable="true"/> + </appinfo> + </annotation> + </attribute> + </complexType> + </element> + + <element name="labelProviderDelegate"> + <annotation> + <documentation> + Declares a label provider delegate. + </documentation> + </annotation> + <complexType> + <sequence> + <element ref="enablement" minOccurs="0" maxOccurs="1"/> + </sequence> + <attribute name="id" type="string" use="required"> + <annotation> + <documentation> + The unique id of the label provider delegate contribution. + </documentation> + </annotation> + </attribute> + <attribute name="class" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + <appinfo> + <meta.attribute kind="java" basedOn=":org.eclipse.jface.viewers.ILabelProvider"/> + </appinfo> + </annotation> + </attribute> + </complexType> + </element> + + <annotation> + <appinfo> + <meta.section type="since"/> + </appinfo> + <documentation> + Target Explorer 1.0.0 + </documentation> + </annotation> + + <annotation> + <appinfo> + <meta.section type="examples"/> + </appinfo> + <documentation> + <pre> + <extension point="org.eclipse.tcf.te.ui.views.labelProviderDelegates"> + <labelProviderDelegate + id="org.eclipse.tcf.te.ui.views.navigator.LabelProviderDelegate" + class="org.eclipse.tcf.te.ui.views.navigator.LabelProviderDelegate"> + <enablement> + ... + </enablement> + </binding> + </extension> +</pre> + </documentation> + </annotation> + + + + <annotation> + <appinfo> + <meta.section type="copyright"/> + </appinfo> + <documentation> + Copyright (c) 2012 Wind River Systems, Inc. and others. + +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. + </documentation> + </annotation> + +</schema> diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/extensions/LabelProviderDelegateExtensionPointManager.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/extensions/LabelProviderDelegateExtensionPointManager.java new file mode 100644 index 000000000..1768741e1 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/extensions/LabelProviderDelegateExtensionPointManager.java @@ -0,0 +1,128 @@ +/******************************************************************************* + * Copyright (c) 2012 Wind River Systems, Inc. and others. 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: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.ui.views.extensions; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.eclipse.core.expressions.EvaluationContext; +import org.eclipse.core.expressions.EvaluationResult; +import org.eclipse.core.expressions.Expression; +import org.eclipse.core.expressions.ExpressionConverter; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager; +import org.eclipse.tcf.te.runtime.extensions.ExecutableExtensionProxy; +import org.eclipse.tcf.te.ui.activator.UIPlugin; + +/** + * Label Provider Delegate extension point manager implementation. + */ +public class LabelProviderDelegateExtensionPointManager extends AbstractExtensionPointManager<ILabelProvider> { + /* + * Thread save singleton instance creation. + */ + private static class LazyInstance { + public static LabelProviderDelegateExtensionPointManager instance = new LabelProviderDelegateExtensionPointManager(); + } + + /** + * Constructor. + */ + LabelProviderDelegateExtensionPointManager() { + super(); + } + + /** + * Returns the singleton instance of the extension point manager. + */ + public static LabelProviderDelegateExtensionPointManager getInstance() { + return LazyInstance.instance; + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager#getExtensionPointId() + */ + @Override + protected String getExtensionPointId() { + return "org.eclipse.tcf.te.ui.views.labelProviderDelegates"; //$NON-NLS-1$ + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager#getConfigurationElementName() + */ + @Override + protected String getConfigurationElementName() { + return "labelProviderDelegate"; //$NON-NLS-1$ + } + + /** + * Returns the list of all contributed label provider delegates. + * + * @param unique If <code>true</code>, the method returns new instances for each + * contributed label provider delegate. + * + * @return The list of contributed label provider delegates, or an empty array. + */ + public ILabelProvider[] getDelegates(Object context, boolean unique) { + List<ILabelProvider> contributions = new ArrayList<ILabelProvider>(); + Collection<ExecutableExtensionProxy<ILabelProvider>> delegates = getExtensions().values(); + for (ExecutableExtensionProxy<ILabelProvider> delegate : delegates) { + Expression enablement = null; + // Read the sub elements of the extension + IConfigurationElement[] children = delegate != null ? delegate.getConfigurationElement().getChildren() : null; + // The "enablement" element is the only expected one + if (children != null && children.length > 0) { + try { + enablement = ExpressionConverter.getDefault().perform(children[0]); + } + catch (CoreException e) {} + } + + // The binding is applicable by default if no expression is specified. + boolean isApplicable = enablement == null; + + if (enablement != null) { + if (context != null) { + // Set the default variable to the delegate context. + EvaluationContext evalContext = new EvaluationContext(null, context); + evalContext.addVariable("context", context); //$NON-NLS-1$ + // Allow plugin activation + evalContext.setAllowPluginActivation(true); + // Evaluate the expression + try { + isApplicable = enablement.evaluate(evalContext).equals(EvaluationResult.TRUE); + } catch (CoreException e) { + IStatus status = new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(), + e.getLocalizedMessage(), e); + Platform.getLog(UIPlugin.getDefault().getBundle()).log(status); + } + } else { + // The enablement is false by definition if no delegate context is given. + isApplicable = false; + } + } + + if (isApplicable) { + ILabelProvider instance = unique ? delegate.newInstance() : delegate.getInstance(); + if (instance != null && !contributions.contains(instance)) { + contributions.add(instance); + } + } + } + + return contributions.toArray(new ILabelProvider[contributions.size()]); + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/categories/CategoryManager.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/categories/CategoryManager.java index af6bc7a54..23e6fcedd 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/categories/CategoryManager.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/categories/CategoryManager.java @@ -10,13 +10,7 @@ package org.eclipse.tcf.te.ui.views.internal.categories;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.Reader;
-import java.io.Writer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -27,22 +21,21 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path;
import org.eclipse.tcf.te.runtime.events.ChangeEvent;
import org.eclipse.tcf.te.runtime.events.EventManager;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService;
+import org.eclipse.tcf.te.runtime.services.ServiceManager;
import org.eclipse.tcf.te.ui.views.activator.UIPlugin;
import org.eclipse.tcf.te.ui.views.extensions.CategoriesExtensionPointManager;
import org.eclipse.tcf.te.ui.views.interfaces.categories.ICategoryManager;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-
/**
* Category manager implementation.
*/
public class CategoryManager implements ICategoryManager {
// The map maintaining the id list per category id
- private final Map<String, List<String>> cat2id = new HashMap<String, List<String>>();
+ private Map<String, List<String>> cat2id = new HashMap<String, List<String>>();
// The map maintaining the category id list per id
- private final Map<String, List<String>> id2cat = new HashMap<String, List<String>>();
+ private Map<String, List<String>> id2cat = new HashMap<String, List<String>>();
// The map maintaining the transient id list per category id
private final Map<String, List<String>> _t_cat2id = new HashMap<String, List<String>>();
@@ -97,41 +90,29 @@ public class CategoryManager implements ICategoryManager { _t_cat2id.clear();
_t_id2cat.clear();
- // Create the Gson instance
- Gson gson = new GsonBuilder().create();
+ cat2id.clear();
+ id2cat.clear();
- // The first file to read is the category to id list map
- File file = root.append("cat2id.json").toFile(); //$NON-NLS-1$
try {
- cat2id.clear();
- Reader reader = null;
- try {
- reader = new InputStreamReader(new FileInputStream(file), "UTF-8"); //$NON-NLS-1$
- cat2id.putAll(gson.fromJson(reader, Map.class));
- } finally {
- if (reader != null) {
- reader.close();
- }
+ // Get the persistence service
+ IURIPersistenceService uRIPersistenceService = ServiceManager.getInstance().getService(IURIPersistenceService.class);
+ if (uRIPersistenceService == null) {
+ throw new IOException("Persistence service instance unavailable."); //$NON-NLS-1$
}
+ // Save the history to the persistence storage
+ cat2id = (Map<String,List<String>>)uRIPersistenceService.read(cat2id, root.append("cat2id.json").toFile().toURI()); //$NON-NLS-1$
} catch (IOException e) {
- /* ignored on purpose */
}
- // The second file to read is the id to category list map
- file = root.append("id2cat.json").toFile(); //$NON-NLS-1$
try {
- id2cat.clear();
- Reader reader = null;
- try {
- reader = new InputStreamReader(new FileInputStream(file), "UTF-8"); //$NON-NLS-1$
- id2cat.putAll(gson.fromJson(reader, Map.class));
- } finally {
- if (reader != null) {
- reader.close();
- }
+ // Get the persistence service
+ IURIPersistenceService uRIPersistenceService = ServiceManager.getInstance().getService(IURIPersistenceService.class);
+ if (uRIPersistenceService == null) {
+ throw new IOException("Persistence service instance unavailable."); //$NON-NLS-1$
}
+ // Save the history to the persistence storage
+ id2cat = (Map<String,List<String>>)uRIPersistenceService.read(id2cat, root.append("id2cat.json").toFile().toURI()); //$NON-NLS-1$
} catch (IOException e) {
- /* ignored on purpose */
}
}
@@ -145,39 +126,26 @@ public class CategoryManager implements ICategoryManager { return;
}
- // Create the Gson instance
- Gson gson = new GsonBuilder().setPrettyPrinting().create();
-
- // The first file to write is the category to id list map
- File file = root.append("cat2id.json").toFile(); //$NON-NLS-1$
try {
- Writer writer = null;
- try {
- writer = new OutputStreamWriter(new FileOutputStream(file), "UTF-8"); //$NON-NLS-1$
- gson.toJson(cat2id, Map.class, writer);
- } finally {
- if (writer != null) {
- writer.close();
- }
+ // Get the persistence service
+ IURIPersistenceService uRIPersistenceService = ServiceManager.getInstance().getService(IURIPersistenceService.class);
+ if (uRIPersistenceService == null) {
+ throw new IOException("Persistence service instance unavailable."); //$NON-NLS-1$
}
+ // Save the history to the persistence storage
+ uRIPersistenceService.write(cat2id, root.append("cat2id.json").toFile().toURI()); //$NON-NLS-1$
} catch (IOException e) {
- /* ignored on purpose */
}
- // The second file to write is the id to category list map
- file = root.append("id2cat.json").toFile(); //$NON-NLS-1$
try {
- Writer writer = null;
- try {
- writer = new OutputStreamWriter(new FileOutputStream(file), "UTF-8"); //$NON-NLS-1$
- gson.toJson(id2cat, Map.class, writer);
- } finally {
- if (writer != null) {
- writer.close();
- }
+ // Get the persistence service
+ IURIPersistenceService uRIPersistenceService = ServiceManager.getInstance().getService(IURIPersistenceService.class);
+ if (uRIPersistenceService == null) {
+ throw new IOException("Persistence service instance unavailable."); //$NON-NLS-1$
}
+ // Save the history to the persistence storage
+ uRIPersistenceService.write(id2cat, root.append("id2cat.json").toFile().toURI()); //$NON-NLS-1$
} catch (IOException e) {
- /* ignored on purpose */
}
}
|