blob: 3648f4c3f3bc5bbe71fb4f3948f9bfac974953ad [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004-2008 Istvan Rath and Daniel Varro
* 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:
* Istvan Rath - initial API and implementation
*******************************************************************************/
package org.eclipse.viatra2.treeeditor;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.Vector;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.viatra2.treeeditor.actions.ViatraTreeEditorSelectionAction;
import org.eclipse.viatra2.treeeditor.wizard.IWizardCategoryContributor;
import org.eclipse.viatra2.treeeditor.wizard.IWizardModelContributor;
import org.eclipse.viatra2.treeeditor.wizard.WizardCategoryContributor;
import org.eclipse.viatra2.treeeditor.wizard.WizardModelContributor;
import org.osgi.framework.BundleContext;
/**
* The main plugin class to be used in the desktop.
*/
public class Plugin extends AbstractUIPlugin {
// The shared instance.
private static Plugin plugin;
/**
* The constructor.
*/
public Plugin() {
plugin = this;
}
/**
* This method is called upon plug-in activation
*/
public void start(BundleContext context) throws Exception {
super.start(context);
}
/**
* This method is called when the plug-in is stopped
*/
public void stop(BundleContext context) throws Exception {
super.stop(context);
plugin = null;
}
/**
* Returns the shared instance.
*/
public static Plugin getDefault() {
return plugin;
}
/**
* Returns an image descriptor for the image file at the given plug-in
* relative path.
*
* @param path
* the path
* @return the image descriptor
*/
public static ImageDescriptor getImageDescriptor(String path) {
return AbstractUIPlugin.imageDescriptorFromPlugin(
"org.eclipse.viatra2.editor", path);
}
/**
* The String ID of the wizard contribution extension point.
*/
static final String wizcont_id = "org.eclipse.viatra2.core2.wizardcontributor";
private Collection<String> buildCollection(String s)
{
StringTokenizer tok = new StringTokenizer(s==null?"":s,",; ");
Vector<String> v = new Vector<String>(tok.countTokens());
int c = tok.countTokens();
for (int i = 0; i<c; i++)
{
v.add(tok.nextToken());
}
return v;
}
public Collection<IWizardModelContributor> getModelContributions()
{
Vector<IWizardModelContributor> v = new Vector<IWizardModelContributor>();
IExtensionRegistry reg = Platform.getExtensionRegistry();
IExtensionPoint ep = reg.getExtensionPoint(wizcont_id);
for (IExtension e : ep.getExtensions())
{
for (IConfigurationElement ce : e.getConfigurationElements())
{
if (!ce.getName().equalsIgnoreCase("model"))
continue;
// String[] attrs = ce.getAttributeNames();
try
{
String id = ce.getAttribute("id");
String rids = ce.getAttribute("requiredIDs");
String fids = ce.getAttribute("forbiddenIDs");
String cids = ce.getAttribute("containedIDs");
String cid = ce.getAttribute("categoryID");
String name = ce.getAttribute("name");
String desc = ce.getAttribute("description");
String fvtml = ce.getAttribute("file_vtml");
String fvpml = ce.getAttribute("file_vpml");
WizardModelContributor mc =
new WizardModelContributor(id, buildCollection(rids),
buildCollection(fids), buildCollection(cids),
//cid, name, desc, fvtml, fvpml, e.getDeclaringPluginDescriptor().getUniqueIdentifier());
cid, name, desc, fvtml, fvpml, e.getNamespaceIdentifier());
v.add(mc);
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}
return v;
}
public Collection<IWizardCategoryContributor> getCategoryContributions()
{
Vector<IWizardCategoryContributor> v = new Vector<IWizardCategoryContributor>();
IExtensionRegistry reg = Platform.getExtensionRegistry();
IExtensionPoint ep = reg.getExtensionPoint(wizcont_id);
for (IExtension e : ep.getExtensions())
{
for (IConfigurationElement ce : e.getConfigurationElements())
{
if (!ce.getName().equalsIgnoreCase("category"))
continue;
try
{
String id = ce.getAttribute("id");
String name = ce.getAttribute("name");
//WizardCategoryContributor cc = new WizardCategoryContributor(id,name, e.getDeclaringPluginDescriptor().getUniqueIdentifier());
WizardCategoryContributor cc = new WizardCategoryContributor(id,name, e.getNamespaceIdentifier());
v.add(cc);
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}
return v;
}
/**
* The String ID of the actions contribution extension point.
*/
static final String actions_id = "org.eclipse.viatra2.editor.menuactions";
//public Collection<ViatraTreeEditorSelectionAction> getContributedActions()
public Map<String,List<ViatraTreeEditorSelectionAction>> getContributedActions()
{
HashMap<String, List<ViatraTreeEditorSelectionAction>> r = new HashMap<String, List<ViatraTreeEditorSelectionAction>>();
// Vector<ViatraTreeEditorSelectionAction> v = new Vector<ViatraTreeEditorSelectionAction>();
IExtensionRegistry reg = Platform.getExtensionRegistry();
IExtensionPoint ep = reg.getExtensionPoint(actions_id);
for (IExtension e : ep.getExtensions())
{
for (IConfigurationElement ce : e.getConfigurationElements())
{
if (!ce.getName().equalsIgnoreCase("actions"))
continue;
try
{
Object o = ce.createExecutableExtension("class");
if (o instanceof ViatraTreeEditorSelectionAction)
{
String key = ce.getAttribute("key");
if (key==null) key = "Default";
List<ViatraTreeEditorSelectionAction> c = r.get(key);
if (c==null) {
c = new Vector<ViatraTreeEditorSelectionAction>();
}
c.add((ViatraTreeEditorSelectionAction) o);
Integer i = new Integer(0);
try {
i = Integer.parseInt(ce.getAttribute("ordering_number"));
} catch (Throwable t) { }
((ViatraTreeEditorSelectionAction)o).setOrderNumber(i);
r.put(key, c);
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}
return r;
}
}