Mercurial > hg > thermostat-tools-eclipse
changeset 27:6367d8007713
Move MulitPageEditorContribute to better package
Also remove useless actions/menus it creates.
author | Omair Majid <omajid@redhat.com> |
---|---|
date | Wed, 04 Dec 2013 15:35:26 -0500 |
parents | c3bd8ec8fa41 |
children | f520e217d065 |
files | plugin.xml src/com/redhat/thermostat/plugin/eclipse/editor/MultiPageEditorContributor.java src/thermostatplugin/editors/MultiPageEditorContributor.java |
diffstat | 3 files changed, 78 insertions(+), 104 deletions(-) [+] |
line wrap: on
line diff
--- a/plugin.xml Wed Dec 04 15:26:21 2013 -0500 +++ b/plugin.xml Wed Dec 04 15:35:26 2013 -0500 @@ -6,7 +6,7 @@ point="org.eclipse.ui.editors"> <editor class="com.redhat.thermostat.plugin.eclipse.editor.MultiPageEditor" - contributorClass="thermostatplugin.editors.MultiPageEditorContributor" + contributorClass="com.redhat.thermostat.plugin.eclipse.editor.MultiPageEditorContributor" extensions="xml" icon="icons/thermostat.png" id="thermostatplugin.editors.MultiPageEditor"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/redhat/thermostat/plugin/eclipse/editor/MultiPageEditorContributor.java Wed Dec 04 15:35:26 2013 -0500 @@ -0,0 +1,77 @@ +package com.redhat.thermostat.plugin.eclipse.editor; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.actions.ActionFactory; +import org.eclipse.ui.ide.IDEActionFactory; +import org.eclipse.ui.part.MultiPageEditorActionBarContributor; +import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.ui.texteditor.ITextEditorActionConstants; + +/** + * Manages the installation/deinstallation of global actions for multi-page editors. + * Responsible for the redirection of global actions to the active editor. + * Multi-page contributor replaces the contributors for the individual editors in the multi-page editor. + */ +public class MultiPageEditorContributor extends MultiPageEditorActionBarContributor { + private IEditorPart activeEditorPart; + + /** + * Creates a multi-page contributor. + */ + public MultiPageEditorContributor() { + super(); + } + /** + * 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)); + } + + 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; + + actionBars.setGlobalActionHandler( + ActionFactory.DELETE.getId(), + getAction(editor, ITextEditorActionConstants.DELETE)); + actionBars.setGlobalActionHandler( + ActionFactory.UNDO.getId(), + getAction(editor, ITextEditorActionConstants.UNDO)); + 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(); + } + } + +}
--- a/src/thermostatplugin/editors/MultiPageEditorContributor.java Wed Dec 04 15:26:21 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,103 +0,0 @@ -package thermostatplugin.editors; - -import org.eclipse.jface.action.*; -import org.eclipse.jface.dialogs.MessageDialog; -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; - -/** - * Manages the installation/deinstallation of global actions for multi-page editors. - * Responsible for the redirection of global actions to the active editor. - * Multi-page contributor replaces the contributors for the individual editors in the multi-page editor. - */ -public class MultiPageEditorContributor extends MultiPageEditorActionBarContributor { - private IEditorPart activeEditorPart; - private Action sampleAction; - /** - * Creates a multi-page contributor. - */ - public MultiPageEditorContributor() { - 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)); - } - /* (non-JavaDoc) - * Method declared in AbstractMultiPageEditorActionBarContributor. - */ - - 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; - - actionBars.setGlobalActionHandler( - ActionFactory.DELETE.getId(), - getAction(editor, ITextEditorActionConstants.DELETE)); - actionBars.setGlobalActionHandler( - ActionFactory.UNDO.getId(), - getAction(editor, ITextEditorActionConstants.UNDO)); - 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, "Thermostat-Plugin", "Sample Action Executed"); - } - }; - sampleAction.setText("Sample Action"); - sampleAction.setToolTipText("Sample Action tool tip"); - sampleAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages(). - getImageDescriptor(IDE.SharedImages.IMG_OBJS_TASK_TSK)); - } - public void contributeToMenu(IMenuManager manager) { - IMenuManager menu = new MenuManager("Editor &Menu"); - manager.prependToGroup(IWorkbenchActionConstants.MB_ADDITIONS, menu); - menu.add(sampleAction); - } - public void contributeToToolBar(IToolBarManager manager) { - manager.add(new Separator()); - manager.add(sampleAction); - } -}