Global Actions in Java

Creator ECC200 in Java Global Actions
Global Actions
Data Matrix 2d Barcode Maker In Java
Using Barcode generator for Java Control to generate, create Data Matrix 2d barcode image in Java applications.
Borrowing from orgeclipseuieditorstextTextEditorActionContributor and orgeclipseuitexteditorBasicTextEditorActionContributor, we create our own contributor for the Properties editor This contributor hooks up global actions (eg Cut, Copy, Paste, etc in the Edit menu) appropriate not only to the active editor but also to the active page within the editor
Bar Code Maker In Java
Using Barcode generation for Java Control to generate, create barcode image in Java applications.
package comqualityeclipsefavoriteseditors; import import import import import orgeclipsejfaceaction*; orgeclipsejfacedialogs*; orgeclipseui*; orgeclipseuipart*; orgeclipseuitexteditor*;
Decoding Bar Code In Java
Using Barcode reader for Java Control to read, scan read, scan image in Java applications.
public class PropertiesEditorContributor extends EditorActionBarContributor { private static final String[] WORKBENCH_ACTION_IDS = { IWorkbenchActionConstantsDELETE, IWorkbenchActionConstantsUNDO, IWorkbenchActionConstantsREDO, IWorkbenchActionConstantsCUT, IWorkbenchActionConstantsCOPY, IWorkbenchActionConstantsPASTE,
DataMatrix Maker In C#.NET
Using Barcode creator for .NET framework Control to generate, create DataMatrix image in .NET framework applications.
TT 8 Editors
ECC200 Creation In .NET Framework
Using Barcode generator for ASP.NET Control to generate, create ECC200 image in ASP.NET applications.
IWorkbenchActionConstantsSELECT_ALL, IWorkbenchActionConstantsFIND, IWorkbenchActionConstantsBOOKMARK, }; private static final String[] TEXTEDITOR_ACTION_IDS = { ITextEditorActionConstantsDELETE, ITextEditorActionConstantsUNDO, ITextEditorActionConstantsREDO, ITextEditorActionConstantsCUT, ITextEditorActionConstantsCOPY, ITextEditorActionConstantsPASTE, ITextEditorActionConstantsSELECT_ALL, ITextEditorActionConstantsFIND, ITextEditorActionConstantsBOOKMARK, }; public void setActiveEditor(IEditorPart part) { PropertiesEditor editor = (PropertiesEditor) part; setActivePage(editor, editorgetActivePage()); } public void setActivePage( PropertiesEditor editor, int pageIndex) { IActionBars actionBars = getActionBars(); if (actionBars != null) { switch (pageIndex) { case 0 : hookGlobalTreeActions(editor, actionBars); break; case 1 : hookGlobalTextActions(editor, actionBars); break; } actionBarsupdateActionBars(); } } private void hookGlobalTreeActions( PropertiesEditor editor, IActionBars actionBars) { for (int i = 0; i < WORKBENCH_ACTION_IDSlength; i++) actionBarssetGlobalActionHandler( WORKBENCH_ACTION_IDS[i],
Data Matrix ECC200 Creator In Visual Studio .NET
Using Barcode creator for .NET framework Control to generate, create ECC200 image in .NET framework applications.
Editor Actions
Data Matrix Generation In Visual Basic .NET
Using Barcode creator for .NET framework Control to generate, create ECC200 image in VS .NET applications.
editorgetTableTreeAction( WORKBENCH_ACTION_IDS[i])); } private void hookGlobalTextActions( PropertiesEditor editor, IActionBars actionBars) { ITextEditor textEditor = editorgetSourceEditor(); for (int i = 0; i < WORKBENCH_ACTION_IDSlength; i++) actionBarssetGlobalActionHandler( WORKBENCH_ACTION_IDS[i], textEditorgetAction(TEXTEDITOR_ACTION_IDS[i])); } }
Create UPC Code In Java
Using Barcode generator for Java Control to generate, create UPC Code image in Java applications.
Now we modify the Properties editor to add accessor methods for the contributor, and to notify the contributor when the page has changed so that the contributor can update the menu items and toolbar buttons appropriately
Encoding Code 128B In Java
Using Barcode maker for Java Control to generate, create Code 128 image in Java applications.
protected void pageChange(int newPageIndex) { existing code superpageChange(newPageIndex); PropertiesEditorContributor contributor = (PropertiesEditorContributor) getEditorSite() getActionBarContributor(); if (contributor instanceof PropertiesEditorContributor) ((PropertiesEditorContributor) contributor) setActivePage(this, newPageIndex); } public int getActivePage() { return supergetActivePage(); } public ITextEditor getSourceEditor() { return textEditor; }
Generate EAN / UCC - 13 In Java
Using Barcode creator for Java Control to generate, create UCC.EAN - 128 image in Java applications.
TT 8 Editors
Create Bar Code In Java
Using Barcode generator for Java Control to generate, create bar code image in Java applications.
public IAction getTableTreeAction(String workbenchActionId) { if (IWorkbenchActionConstantsDELETE equals(workbenchActionId)) return removeAction; return null; }
ECC200 Printer In Java
Using Barcode drawer for Java Control to generate, create Data Matrix ECC200 image in Java applications.
Top-level menu
Print MSI Plessey In Java
Using Barcode generator for Java Control to generate, create MSI Plessey image in Java applications.
Next, we ll add the Remove action to a top-level menu for the purpose of showing how it is accomplished In this case, instead of referencing the action directly as we did with the context menu (see Section 851), we ll use an instance of orgeclipseuiactionsRetargetAction or more specifically
Print EAN / UCC - 13 In Visual Studio .NET
Using Barcode creator for ASP.NET Control to generate, create EAN-13 Supplement 5 image in ASP.NET applications.
orgeclipseuiactionsLabelRetargetAction
Data Matrix Generation In C#.NET
Using Barcode creation for .NET Control to generate, create Data Matrix image in .NET framework applications.
which references the Remove
GTIN - 128 Maker In .NET
Using Barcode maker for .NET framework Control to generate, create EAN / UCC - 13 image in .NET applications.
action indirectly via its identifier We re using the IWorkbenchActionConstantsDELETE
Create Bar Code In .NET Framework
Using Barcode creator for ASP.NET Control to generate, create barcode image in ASP.NET applications.
identifier, but you could use any identifier so long as setis used to associate the identifier with
Bar Code Generator In VB.NET
Using Barcode creation for Visual Studio .NET Control to generate, create barcode image in .NET framework applications.
GlobalActionHandler(String, IAction)
Barcode Decoder In .NET
Using Barcode reader for .NET Control to read, scan read, scan image in .NET applications.
the action To accomplish all this, we ll add the following to the PropertiesEditorContributor
Drawing Code 39 Extended In Visual C#.NET
Using Barcode creator for VS .NET Control to generate, create USS Code 39 image in .NET framework applications.
private LabelRetargetAction retargetRemoveAction; public PropertiesEditorContributor() { retargetRemoveAction = new LabelRetargetAction( IWorkbenchActionConstantsDELETE, "Remove");
Editor Actions
} public void init(IActionBars bars, IWorkbenchPage page) { superinit(bars, page); pageaddPartListener(retargetRemoveAction); } public void contributeToMenu(IMenuManager manager) { IMenuManager menu = new MenuManager("Property Editor"); managerprependToGroup( IWorkbenchActionConstantsMB_ADDITIONS, menu); menuadd(retargetRemoveAction); }
Once in place, this code causes a new top-level menu to appear in the workbench's menubar (see Figure 8-9)
TT 8 Editors
Figure 8-9 Property Editor menu
Toolbar Buttons
We can use the same retargeted action (see Section 8522) to add a button to the workbench's toolbar by including the following code in the PropertiesEditorContributor
public void contributeToToolBar(IToolBarManager manager) { manageradd(new Separator()); manageradd(retargetRemoveAction); }
Keyboard Actions
Using the Remove action again (see Section 8511), we can hook the Delete key by modifying the addTableKeyListener() method introduced earlier (see Section 835) so that when the user presses it, the selected property key/value pairs in the table tree will be removed
private void addTableKeyListener() { tableTreeViewergetTableTree()getTable() addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { if (ekeyCode == SWTALT) isAltPressed = true; if (echaracter == SWTDEL) removeActionrun(); }
Editor Actions
public void keyReleased(KeyEvent e) { if (ekeyCode == SWTALT) isAltPressed = false; } }); }
853 Undo/Redo Adding the capability for the user to undo and redo actions involves building a manager to track changes For expediency, we ll reuse the
javaxswingundoUndoManager
and related classes, but in reality you ll want
to consider reviewing other existing command frameworks or rolling your own
Tip: Browse http://wwwqualityeclipsecom/undo for more information about simple undo/redo frameworks for Eclipse
For starters, we ll add an undo manager to the PropertiesEditor
private UndoManager undoManager = new UndoManager();
and then add accessor methods for actions to register undoable edits (the undoAction
and redoAction fields are declared later)
public void addUndoableEdit(UndoableEdit edit) { undoManageraddEdit(edit); updateUndoRedo(); }
TT 8 Editors
public void updateUndoRedo() { undoActionupdate(); redoActionupdate(); }
The RemovePropertiesAction requires some refactoring to introduce an UndoableEdit
inner class that can be registered with the properties editor so that
the remove operation can be undone and redone Rather than performing the operation directly, the remove action constructs a new RemovePropertiesEdit to capture the state and perform the operation
public void run() { List elemList = ((IStructuredSelection) viewergetSelection()) toList(); if (elemListisEmpty()) return; PropertyElement[] elemArray = (PropertyElement[]) elemListtoArray( new PropertyElement[elemListsize()]); UndoableEdit edit = new RemovePropertiesEdit(elemArray); editredo(); editoraddUndoableEdit(edit); } private class RemovePropertiesEdit implements UndoableEdit { final PropertyElement[] elements; final PropertyElement[] parents; RemovePropertiesEdit(PropertyElement[] elements) { thiselements = elements; thisparents = new PropertyElement[elementslength]; }