Index: plugin.xml =================================================================== --- plugin.xml (revision 21235) +++ plugin.xml (working copy) @@ -6,6 +6,7 @@ point="org.eclipse.ui.editors"> Index: src/org/jboss/tools/smooks/configuration/editors/SmooksMultiFormEditor.java =================================================================== --- src/org/jboss/tools/smooks/configuration/editors/SmooksMultiFormEditor.java (revision 21235) +++ src/org/jboss/tools/smooks/configuration/editors/SmooksMultiFormEditor.java (working copy) @@ -22,10 +22,12 @@ import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.ui.IEditorActionBarContributor; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IEditorSite; import org.eclipse.ui.PartInitException; +import org.eclipse.ui.part.MultiPageEditorActionBarContributor; import org.eclipse.ui.views.properties.IPropertySheetPage; import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; @@ -104,19 +106,18 @@ } private void addProcessGraphicalEditor() { - processPage = new SmooksProcessGraphicalEditor(this, "process", Messages.SmooksMultiFormEditor_processpage_name, this); //$NON-NLS-1$ + processPage = new SmooksProcessGraphicalEditor(this, + "process", Messages.SmooksMultiFormEditor_processpage_name, this); //$NON-NLS-1$ addSourceSynchronizeListener(processPage); addValidateListener(processPage); addSmooksEditorInitListener(processPage); try { - int index = this.addPage(processPage ); + int index = this.addPage(processPage); setPageText(index, Messages.SmooksMultiFormEditor_processtabel_label); } catch (PartInitException e) { e.printStackTrace(); } } - - // private void addSmooksGraphicalEditor() { // graphicalPage = new SmooksGraphicalEditorPart(this); @@ -129,34 +130,53 @@ // } // } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.ui.forms.editor.FormEditor#getActiveEditor() */ @Override public IEditorPart getActiveEditor() { int index = getActivePage(); if (index != -1) { - IEditorPart part = getEditor(index); - if(part == null){ -// if(index == 0){ -// part = processPage; -// } -// if(index == 1){ -// part = configurationPage; -// } + IEditorPart part = getEditor(index); + if (part == null) { + // if(index == 0){ + // part = processPage; + // } + // if(index == 1){ + // part = configurationPage; + // } } return part; } return null; } - /* (non-Javadoc) - * @see org.jboss.tools.smooks.editor.AbstractSmooksFormEditor#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput) + protected void pageChange(int newPageIndex) { + super.pageChange(newPageIndex); + IEditorPart activeEditor = getEditor(newPageIndex); + if (activeEditor == null) { + if (newPageIndex == 0) { + IEditorActionBarContributor contributor = getEditorSite().getActionBarContributor(); + if (contributor != null && contributor instanceof MultiPageEditorActionBarContributor) { + ((MultiPageEditorActionBarContributor) contributor).setActivePage(processPage); + } + } + } + } + + /* + * (non-Javadoc) + * + * @see + * org.jboss.tools.smooks.editor.AbstractSmooksFormEditor#init(org.eclipse + * .ui.IEditorSite, org.eclipse.ui.IEditorInput) */ @Override public void init(IEditorSite site, IEditorInput input) throws PartInitException { super.init(site, input); -// site.setSelectionProvider(this); + // site.setSelectionProvider(this); } public Object getAdapter(Class adapter) { @@ -164,13 +184,13 @@ tabbedPropertySheetPage = new TabbedPropertySheetPage(this); return tabbedPropertySheetPage; } - - if(adapter == GraphicalViewer.class){ - if(this.processPage != null){ + + if (adapter == GraphicalViewer.class) { + if (this.processPage != null) { Object activeEditorPart = processPage.getActiveEditorPage(); - if(activeEditorPart != null && activeEditorPart instanceof IEditorPart){ - if(activeEditorPart instanceof GraphicalEditor){ - return ((IEditorPart)activeEditorPart).getAdapter(adapter); + if (activeEditorPart != null && activeEditorPart instanceof IEditorPart) { + if (activeEditorPart instanceof GraphicalEditor) { + return ((IEditorPart) activeEditorPart).getAdapter(adapter); } } } @@ -185,7 +205,8 @@ // } private SmooksConfigurationOverviewPage createSmooksConfigurationOverviewPage() { - return new SmooksConfigurationOverviewPage(this, "options_page", Messages.SmooksMultiFormEditor_optinepage_name, this); //$NON-NLS-1$ + return new SmooksConfigurationOverviewPage(this, + "options_page", Messages.SmooksMultiFormEditor_optinepage_name, this); //$NON-NLS-1$ } @Override Index: src/org/jboss/tools/smooks/configuration/editors/SmooksMultiPageEditorContributor.java =================================================================== --- src/org/jboss/tools/smooks/configuration/editors/SmooksMultiPageEditorContributor.java (revision 21235) +++ src/org/jboss/tools/smooks/configuration/editors/SmooksMultiPageEditorContributor.java (working copy) @@ -1,17 +1,12 @@ package org.jboss.tools.smooks.configuration.editors; -import org.eclipse.jface.action.*; -import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.action.IAction; import org.eclipse.ui.IActionBars; import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchActionConstants; -import org.eclipse.ui.PlatformUI; import org.eclipse.ui.actions.ActionFactory; -import org.eclipse.ui.ide.IDE; -import org.eclipse.ui.ide.IDEActionFactory; import org.eclipse.ui.part.MultiPageEditorActionBarContributor; -import org.eclipse.ui.texteditor.ITextEditor; import org.eclipse.ui.texteditor.ITextEditorActionConstants; +import org.jboss.tools.smooks.graphical.actions.ISmooksActionProvider; /** * Manages the installation/deinstallation of global actions for multi-page editors. @@ -20,21 +15,21 @@ */ public class SmooksMultiPageEditorContributor extends MultiPageEditorActionBarContributor { private IEditorPart activeEditorPart; - private Action sampleAction; /** * Creates a multi-page contributor. */ public SmooksMultiPageEditorContributor() { super(); - createActions(); } - /** - * Returns the action registed with the given text editor. - * @return IAction or null if editor is null. - */ - protected IAction getAction(ITextEditor editor, String actionID) { - return (editor == null ? null : editor.getAction(actionID)); + + + protected IAction getAction(IEditorPart editor , String actionID){ + if(editor instanceof ISmooksActionProvider){ + return ((ISmooksActionProvider)editor).getAction(actionID); + } + return null; } + /* (non-JavaDoc) * Method declared in AbstractMultiPageEditorActionBarContributor. */ @@ -42,16 +37,13 @@ public void setActivePage(IEditorPart part) { if (activeEditorPart == part) return; - activeEditorPart = part; - IActionBars actionBars = getActionBars(); if (actionBars != null) { - - ITextEditor editor = (part instanceof ITextEditor) ? (ITextEditor) part : null; + + IEditorPart editor = activeEditorPart; - actionBars.setGlobalActionHandler( - ActionFactory.DELETE.getId(), + actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), getAction(editor, ITextEditorActionConstants.DELETE)); actionBars.setGlobalActionHandler( ActionFactory.UNDO.getId(), @@ -59,45 +51,27 @@ actionBars.setGlobalActionHandler( ActionFactory.REDO.getId(), getAction(editor, ITextEditorActionConstants.REDO)); - actionBars.setGlobalActionHandler( - ActionFactory.CUT.getId(), - getAction(editor, ITextEditorActionConstants.CUT)); - actionBars.setGlobalActionHandler( - ActionFactory.COPY.getId(), - getAction(editor, ITextEditorActionConstants.COPY)); - actionBars.setGlobalActionHandler( - ActionFactory.PASTE.getId(), - getAction(editor, ITextEditorActionConstants.PASTE)); - actionBars.setGlobalActionHandler( - ActionFactory.SELECT_ALL.getId(), - getAction(editor, ITextEditorActionConstants.SELECT_ALL)); - actionBars.setGlobalActionHandler( - ActionFactory.FIND.getId(), - getAction(editor, ITextEditorActionConstants.FIND)); - actionBars.setGlobalActionHandler( - IDEActionFactory.BOOKMARK.getId(), - getAction(editor, IDEActionFactory.BOOKMARK.getId())); actionBars.updateActionBars(); } } - private void createActions() { - sampleAction = new Action() { - public void run() { - MessageDialog.openInformation(null, "Configuration Plug-in", "Sample Action Executed"); //$NON-NLS-1$ //$NON-NLS-2$ - } - }; - sampleAction.setText("Sample Action"); //$NON-NLS-1$ - sampleAction.setToolTipText("Sample Action tool tip"); //$NON-NLS-1$ - sampleAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages(). - getImageDescriptor(IDE.SharedImages.IMG_OBJS_TASK_TSK)); - } - public void contributeToMenu(IMenuManager manager) { - IMenuManager menu = new MenuManager("Editor &Menu"); //$NON-NLS-1$ - manager.prependToGroup(IWorkbenchActionConstants.MB_ADDITIONS, menu); - menu.add(sampleAction); - } - public void contributeToToolBar(IToolBarManager manager) { - manager.add(new Separator()); - manager.add(sampleAction); - } +// private void createActions() { +// sampleAction = new Action() { +// public void run() { +// MessageDialog.openInformation(null, "Configuration Plug-in", "Sample Action Executed"); //$NON-NLS-1$ //$NON-NLS-2$ +// } +// }; +// sampleAction.setText("Sample Action"); //$NON-NLS-1$ +// sampleAction.setToolTipText("Sample Action tool tip"); //$NON-NLS-1$ +// sampleAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages(). +// getImageDescriptor(IDE.SharedImages.IMG_OBJS_TASK_TSK)); +// } +// public void contributeToMenu(IMenuManager manager) { +// IMenuManager menu = new MenuManager("Editor &Menu"); //$NON-NLS-1$ +// manager.prependToGroup(IWorkbenchActionConstants.MB_ADDITIONS, menu); +// menu.add(sampleAction); +// } +// public void contributeToToolBar(IToolBarManager manager) { +// manager.add(new Separator()); +// manager.add(sampleAction); +// } } Index: src/org/jboss/tools/smooks/graphical/actions/ISmooksActionProvider.java =================================================================== --- src/org/jboss/tools/smooks/graphical/actions/ISmooksActionProvider.java (revision 0) +++ src/org/jboss/tools/smooks/graphical/actions/ISmooksActionProvider.java (revision 0) @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2008 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is 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: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.smooks.graphical.actions; + +import org.eclipse.jface.action.IAction; + +/** + * @author Dart + * + */ +public interface ISmooksActionProvider { + IAction getAction(String actionId); +} Index: src/org/jboss/tools/smooks/graphical/editors/SmooksProcessGraphicalEditor.java =================================================================== --- src/org/jboss/tools/smooks/graphical/editors/SmooksProcessGraphicalEditor.java (revision 21235) +++ src/org/jboss/tools/smooks/graphical/editors/SmooksProcessGraphicalEditor.java (working copy) @@ -45,17 +45,21 @@ import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.FocusListener; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Menu; +import org.eclipse.ui.IEditorActionBarContributor; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IEditorSite; import org.eclipse.ui.IPropertyListener; import org.eclipse.ui.PartInitException; +import org.eclipse.ui.actions.ActionFactory; import org.eclipse.ui.forms.IManagedForm; import org.eclipse.ui.forms.IMessage; import org.eclipse.ui.forms.editor.FormEditor; @@ -64,6 +68,7 @@ import org.eclipse.ui.forms.widgets.ScrolledForm; import org.eclipse.ui.forms.widgets.ScrolledPageBook; import org.eclipse.ui.forms.widgets.Section; +import org.eclipse.ui.part.MultiPageEditorActionBarContributor; import org.eclipse.zest.core.viewers.GraphViewer; import org.eclipse.zest.core.widgets.CGraphNode; import org.eclipse.zest.core.widgets.Graph; @@ -81,9 +86,11 @@ import org.jboss.tools.smooks.editor.AbstractSmooksFormEditor; import org.jboss.tools.smooks.editor.ISmooksModelProvider; import org.jboss.tools.smooks.editor.ISourceSynchronizeListener; +import org.jboss.tools.smooks.gef.common.SmooksGraphicalMenuContextProvider; import org.jboss.tools.smooks.graphical.actions.AbstractProcessGraphAction; import org.jboss.tools.smooks.graphical.actions.AddNextTaskNodeAction; import org.jboss.tools.smooks.graphical.actions.DeleteTaskNodeAction; +import org.jboss.tools.smooks.graphical.actions.ISmooksActionProvider; import org.jboss.tools.smooks.graphical.editors.TaskTypeManager.TaskTypeDescriptor; import org.jboss.tools.smooks.graphical.editors.process.IProcessProvider; import org.jboss.tools.smooks.graphical.editors.process.ProcessFactory; @@ -108,7 +115,9 @@ */ public class SmooksProcessGraphicalEditor extends FormPage implements ISelectionChangedListener, ISourceSynchronizeListener, IPropertyListener, ISmooksModelValidateListener, IProcessProvider, - PropertyChangeListener, ISmooksEditorInitListener { + PropertyChangeListener, ISmooksEditorInitListener, ISmooksActionProvider { + + private boolean processMapActived = false; private int currentMessageType = IMessageProvider.NONE; @@ -260,10 +269,35 @@ } showTaskControl(firstElement); SmooksProcessGraphicalEditor.this.selectionChanged(event); + updateGlobalActions(); + } + }); + // when focus change , update the actions in the Eclipse menu via + // EditorContributor + getProcessGraphViewer().getControl().addFocusListener(new FocusListener() { + + public void focusLost(FocusEvent e) { + processMapActived = false; + updateGlobalActions(); + } + + public void focusGained(FocusEvent e) { + processMapActived = true; + updateGlobalActions(); } }); } + private void updateGlobalActions() { + IEditorActionBarContributor contributor = getEditorSite().getActionBarContributor(); + if (contributor != null && contributor instanceof MultiPageEditorActionBarContributor) { + // clean all actions + ((MultiPageEditorActionBarContributor) contributor).setActivePage(null); + // re-active the page and add all actions + ((MultiPageEditorActionBarContributor) contributor).setActivePage(SmooksProcessGraphicalEditor.this); + } + } + protected void unhighlightGraphNodes() { Graph graph = this.getProcessGraphViewer().getGraphControl(); @@ -793,7 +827,7 @@ public void selectionChanged(SelectionChangedEvent event) { ISelectionProvider provider = getEditor().getSite().getSelectionProvider(); - if(provider != null){ + if (provider != null) { provider.setSelection(event.getSelection()); } } @@ -855,9 +889,9 @@ } return null; } - - public Object getActiveEditorPage(){ - if(pageBook != null){ + + public Object getActiveEditorPage() { + if (pageBook != null) { Control control = pageBook.getCurrentPage(); return control.getData(); } @@ -941,7 +975,7 @@ } }); - + updateGlobalActions(); } protected IEditorSite createSite(IEditorPart editor) { @@ -1313,4 +1347,26 @@ } } } + + public IAction getAction(String actionId) { + if (processMapActived) { + updateProcessActions(processGraphViewer.getSelection()); + if(ActionFactory.DELETE.getId().equals(actionId)){ + for (Iterator iterator = processPanelActions.iterator(); iterator.hasNext();) { + IAction action = (IAction) iterator.next(); + if(action instanceof DeleteTaskNodeAction){ + return action; + } + } + } + } else { + IEditorPart editor = (IEditorPart) getActiveEditorPage(); + if (editor != null && editor instanceof SmooksGraphicalEditorPart) { + SmooksGraphicalMenuContextProvider provider = (SmooksGraphicalMenuContextProvider) ((SmooksGraphicalEditorPart) editor) + .getContextMenuProvider(); + return provider.getActionRegistry().getAction(actionId); + } + } + return null; + } }