*******************************************************************************/
package org.simantics.ui.contribution;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
+import java.util.Hashtable;
+import java.util.List;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExecutableExtension;
import org.eclipse.jface.action.ContributionItem;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.resource.ImageDescriptor;
import org.simantics.ui.workbench.editor.EditorAdapter;
import org.simantics.ui.workbench.editor.EditorRegistry;
import org.simantics.utils.strings.AlphanumComparator;
+import org.simantics.utils.ui.workbench.WorkbenchUtils;
/**
* @author Tuukka Lehtonen
*/
-public class OpenWithMenuContribution extends DynamicMenuContribution {
+public class OpenWithMenuContribution extends DynamicMenuContribution implements IExecutableExtension{
private static final boolean DEBUG_ADAPTERS = false;
private ResourceManager resourceManager;
+ private String editorId = null;
public OpenWithMenuContribution() {
resourceManager = new LocalResourceManager(JFaceResources.getResources());
}
-
+
+ @Override
+ public void setInitializationData(IConfigurationElement config, String propertyName, Object data)
+ throws CoreException {
+ if ("class".equals(propertyName)) {
+ if (data instanceof String) {
+ setEditorId((String)data);
+ } else if (data instanceof Hashtable) {
+ @SuppressWarnings("unchecked")
+ Hashtable<String,String> params = (Hashtable<String, String>)data;
+ setEditorId(params.get("editorId"));
+ }
+ if ("activeEditorId".equals(this.editorId)) {
+ setEditorId(WorkbenchUtils.getActiveWorkbenchPart().getSite().getId());
+ }
+ }
+ }
+
+ public void setEditorId(String editorId) {
+ this.editorId = editorId;
+ }
+
@Override
public void dispose() {
if (resourceManager != null) {
final Object r = extractResource(graph, selection[0]);
if (r == null)
return NONE;
- final EditorAdapter[] editorAdapters = EditorRegistry.getInstance().getAdaptersFor(graph, r);
+ EditorAdapter[] _editorAdapters = EditorRegistry.getInstance().getAdaptersFor(graph, r);
+ final EditorAdapter[] editorAdapters = filter(_editorAdapters, editorId);
if (editorAdapters.length == 0)
return NONE;
+
return new IContributionItem[] {
new ContributionItem() {
@Override
}
};
}
+
+ protected EditorAdapter[] filter(EditorAdapter[] adapters, String id) {
+ if (id == null)
+ return adapters;
+ List<EditorAdapter> editorAdapters = new ArrayList<EditorAdapter>();
+ for (EditorAdapter a : adapters) {
+ if (id.equals(a.getEditorId()))
+ continue;
+ editorAdapters.add(a);
+ }
+ return editorAdapters.toArray(new EditorAdapter[editorAdapters.size()]);
+ }
private void addMenuItem(Menu subMenu, Adapter adapter, Object r) {
MenuItem item = new MenuItem(subMenu, SWT.PUSH);