/******************************************************************************* | |
* 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.editor.text.light; | |
import org.eclipse.viatra2.editor.text.Activator; | |
import org.eclipse.viatra2.editor.text.light.vtcl.ParseVTCLAction; | |
import java.util.HashMap; | |
import org.eclipse.jface.action.Action; | |
import org.eclipse.jface.action.IAction; | |
import org.eclipse.jface.action.IMenuCreator; | |
import org.eclipse.jface.action.IToolBarManager; | |
import org.eclipse.swt.SWT; | |
import org.eclipse.swt.events.SelectionEvent; | |
import org.eclipse.swt.events.SelectionListener; | |
import org.eclipse.swt.widgets.Control; | |
import org.eclipse.swt.widgets.Menu; | |
import org.eclipse.swt.widgets.MenuItem; | |
import org.eclipse.ui.texteditor.BasicTextEditorActionContributor; | |
import org.eclipse.viatra2.framework.FrameworkManager; | |
public class VTCLActionbarContributor extends BasicTextEditorActionContributor | |
{ | |
protected HashMap<String, ParseVTCLAction> actions; | |
public VTCLActionbarContributor() { | |
super(); | |
actions = new HashMap<String, ParseVTCLAction>(); | |
} | |
public void updateActions(VTCLEditor ed) | |
{ | |
for (String id : FrameworkManager.getInstance().getAllFrameWorks()) | |
{ | |
if (actions.get(id)==null) | |
actions.put(id, new ParseVTCLAction(id).updateSelf(ed)); | |
else | |
actions.get(id).updateSelf(ed); | |
} | |
} | |
@Override | |
public void contributeToToolBar(IToolBarManager toolBarManager) { | |
super.contributeToToolBar(toolBarManager); | |
// String[] fwids = FrameworkManager.getInstance().getAllFrameWorks(); | |
// if (fwids.length>1) | |
// { | |
Action a = new Action("Parse / Select framework",IAction.AS_DROP_DOWN_MENU) | |
{ | |
@Override | |
public void run() {} | |
}; | |
a.setImageDescriptor(Activator.getImageDescriptor("icons/parse.png")); | |
a.setToolTipText("Use Alt+P for parsing the current file into the first framework"); | |
a.setMenuCreator(new IMenuCreator() | |
{ | |
public void dispose() {} | |
public Menu getMenu(Control parent) { | |
Menu m = new Menu(parent); | |
return fillMenu(m); | |
} | |
public Menu getMenu(Menu parent) { | |
Menu m = new Menu(parent); | |
return fillMenu(m); | |
} | |
private Menu fillMenu(Menu m) | |
{ | |
for (String id : FrameworkManager.getInstance().getAllFrameWorks()) | |
{ | |
MenuItem item = new MenuItem(m,SWT.NONE); | |
item.setText(id); | |
item.setData(actions.get(id)); | |
item.addSelectionListener(new SelectionListener() | |
{ | |
public void widgetSelected(SelectionEvent ev) | |
{ | |
((ParseVTCLAction)ev.widget.getData()).run(); | |
} | |
public void widgetDefaultSelected(SelectionEvent ev) { | |
((ParseVTCLAction)ev.widget.getData()).run(); | |
} | |
}); | |
} | |
return m; | |
} | |
}); | |
toolBarManager.add(a); | |
// } | |
// else | |
// { | |
// if (fwids.length==1) | |
// toolBarManager.add(actions.get(FrameworkManager.getInstance().getAllFrameWorks()[0])); | |
// } | |
} | |
} |