Skip to content

Commit

Permalink
Palette Key Command Handler 2
Browse files Browse the repository at this point in the history
- Add a Context for the key bindings
  • Loading branch information
Phillipus committed Jan 6, 2024
1 parent 279a081 commit f6f18c9
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 6 deletions.
18 changes: 13 additions & 5 deletions com.archimatetool.editor/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1713,12 +1713,20 @@
</with>
</definition>
</extension>
<extension
point="org.eclipse.ui.contexts">
<context
description="When editing Archi diagrams"
id="com.archimatetool.editor.view.context"
name="In Archi diagrams">
</context>
</extension>
<extension
name="Palette Key Bindings"
point="org.eclipse.ui.bindings">
<key
commandId="com.archimatetool.editor.palette.command"
contextId="org.eclipse.ui.contexts.dialogAndWindow"
contextId="com.archimatetool.editor.view.context"
schemeId="com.archimatetool.editor.keybindings"
sequence="M1+M M1+C">
<parameter
Expand All @@ -1728,19 +1736,19 @@
</key>
<key
commandId="com.archimatetool.editor.palette.command"
contextId="org.eclipse.ui.contexts.dialogAndWindow"
contextId="com.archimatetool.editor.view.context"
schemeId="com.archimatetool.editor.keybindings"
sequence="M1+B M1+A">
sequence="B A">
<parameter
id="com.archimatetool.editor.palette.command.params"
value="BusinessActor">
</parameter>
</key>
<key
commandId="com.archimatetool.editor.palette.command"
contextId="org.eclipse.ui.contexts.dialogAndWindow"
contextId="com.archimatetool.editor.view.context"
schemeId="com.archimatetool.editor.keybindings"
sequence="M1+B M1+R">
sequence="B R">
<parameter
id="com.archimatetool.editor.palette.command.params"
value="BusinessRole">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.contexts.IContextActivation;
import org.eclipse.ui.contexts.IContextService;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
import org.eclipse.ui.views.properties.IPropertySheetPage;
Expand All @@ -94,7 +96,6 @@
import com.archimatetool.editor.diagram.actions.BorderColorAction;
import com.archimatetool.editor.diagram.actions.BringForwardAction;
import com.archimatetool.editor.diagram.actions.BringToFrontAction;
import com.archimatetool.editor.diagram.actions.LineWidthAction;
import com.archimatetool.editor.diagram.actions.ConnectionRouterAction;
import com.archimatetool.editor.diagram.actions.CopyAction;
import com.archimatetool.editor.diagram.actions.CutAction;
Expand All @@ -107,6 +108,7 @@
import com.archimatetool.editor.diagram.actions.FontColorAction;
import com.archimatetool.editor.diagram.actions.FullScreenAction;
import com.archimatetool.editor.diagram.actions.LineColorAction;
import com.archimatetool.editor.diagram.actions.LineWidthAction;
import com.archimatetool.editor.diagram.actions.LockObjectAction;
import com.archimatetool.editor.diagram.actions.OpacityAction;
import com.archimatetool.editor.diagram.actions.OutlineOpacityAction;
Expand Down Expand Up @@ -195,6 +197,11 @@ public abstract class AbstractDiagramEditor extends GraphicalEditorWithFlyoutPal
*/
protected AbstractPaletteRoot fPaletteRoot;

/**
* Context for key bindngs
*/
private IContextActivation contextActivation;

/**
* Application Preference changed
* @param event
Expand Down Expand Up @@ -372,6 +379,9 @@ protected void configureGraphicalViewer() {
if(rgb != null) {
viewer.getControl().setBackground(new Color(rgb));
}

// Activate Context
activateContext();
}

private void hookSelectionListener() {
Expand Down Expand Up @@ -955,6 +965,26 @@ protected void disableActions() {
}
}

/**
* Activate the context for key bindings for this site
*/
public IContextActivation activateContext() {
if(contextActivation == null) {
contextActivation = getSite().getService(IContextService.class).activateContext(PaletteKeyHandler.CONTEXT_ID);
}
return contextActivation;
}

/**
* De-activate the context for key bindings for this site
*/
public void deactivateContext() {
if(contextActivation != null) {
contextActivation.getContextService().deactivateContext(contextActivation);
contextActivation = null;
}
}

@Override
public void selectObjects(Object[] objects) {
// Safety check in case this is called via Display#asyncExec()
Expand Down Expand Up @@ -1089,6 +1119,8 @@ public void dispose() {
fPaletteRoot.dispose();
}

contextActivation = null;

// Can now be garbage collected
fDiagramModel = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
*/
package com.archimatetool.editor.diagram.directedit;

import org.eclipse.gef.DefaultEditDomain;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.tools.CellEditorLocator;
import org.eclipse.gef.tools.DirectEditManager;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.events.VerifyListener;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IEditorPart;

import com.archimatetool.editor.diagram.AbstractDiagramEditor;
import com.archimatetool.editor.ui.UIUtils;
import com.archimatetool.editor.ui.components.GlobalActionDisablementHandler;

Expand Down Expand Up @@ -39,6 +42,12 @@ protected void initCellEditor() {

// Filter out any illegal xml characters
UIUtils.applyInvalidCharacterFilter(getTextControl());

// Deactivate key binding context
IEditorPart part = ((DefaultEditDomain)getEditPart().getViewer().getEditDomain()).getEditorPart();
if(part instanceof AbstractDiagramEditor editor) {
editor.deactivateContext();
}
}

protected void setNormalised() {
Expand Down Expand Up @@ -72,6 +81,12 @@ protected void bringDown() {
// Restore the global Action Handlers
fGlobalActionHandler.restoreGlobalActions();

// Reactivate key binding context
IEditorPart part = ((DefaultEditDomain)getEditPart().getViewer().getEditDomain()).getEditorPart();
if(part instanceof AbstractDiagramEditor editor) {
editor.activateContext();
}

super.bringDown();
}
}

0 comments on commit f6f18c9

Please sign in to comment.