Skip to content
Snippets Groups Projects
Commit eeb1bc03 authored by Florian Hölzl's avatar Florian Hölzl
Browse files

refactored action service by adding implementation classes.

refs 133
parent f79d2b44
No related branches found
No related tags found
No related merge requests found
......@@ -22,18 +22,14 @@ import java.util.EventObject;
import org.eclipse.emf.common.command.CommandStackListener;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionFactory;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.service.ICommandStackService;
import org.fortiss.tooling.kernel.service.IConnectionCompositorService;
import org.fortiss.tooling.kernel.service.IElementCompositorService;
import org.fortiss.tooling.kernel.service.IPersistencyService;
import org.fortiss.tooling.kernel.service.listener.IPersistencyServiceListener;
import org.fortiss.tooling.kernel.ui.extension.base.EObjectActionBase;
import org.fortiss.tooling.kernel.ui.internal.actions.DeleteAction;
import org.fortiss.tooling.kernel.ui.internal.actions.RedoAction;
import org.fortiss.tooling.kernel.ui.internal.actions.UndoAction;
import org.fortiss.tooling.kernel.ui.service.IActionService;
import org.fortiss.tooling.kernel.ui.util.EObjectSelectionUtils;
......@@ -51,75 +47,20 @@ public class ActionService implements IActionService,
/** The menu section ID of the global default action group. */
public static final String GLOBAL_DEFAULT_MENU_SECTION_ID = "globalDefaults";
/** The global undo action. */
public final EObjectActionBase globalUndoAction = new EObjectActionBase(
"Undo", PlatformUI.getWorkbench().getSharedImages()
.getImageDescriptor(ISharedImages.IMG_TOOL_UNDO)) {
@Override
public void run() {
if (getTarget() != null) {
ICommandStackService.INSTANCE.undo(getTarget());
}
}
};
/** The global redo action. */
public final EObjectActionBase globalRedoAction = new EObjectActionBase(
"Redo", PlatformUI.getWorkbench().getSharedImages()
.getImageDescriptor(ISharedImages.IMG_TOOL_UNDO)) {
@Override
public void run() {
if (getTarget() != null) {
ICommandStackService.INSTANCE.redo(getTarget());
}
}
};
/** The global delete action. */
public final DeleteAction globalDeleteAction = new DeleteAction("Delete",
PlatformUI.getWorkbench().getSharedImages()
.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));
private static class DeleteAction extends EObjectActionBase {
private boolean useElementCompositor;
/**
* @param text
* @param image
*/
public DeleteAction(String text, ImageDescriptor image) {
super(text, image);
}
public final DeleteAction globalDeleteAction;
public void setUseElementCompositor(boolean useElementCompositor) {
this.useElementCompositor = useElementCompositor;
}
/** The global undo action. */
public final UndoAction globalUndoAction;
@Override
public void run() {
final EObject selectedObject = getTarget();
if (selectedObject == null) {
return;
}
ICommandStackService.INSTANCE.runAsCommand(selectedObject,
new Runnable() {
@Override
public void run() {
IElementCompositorService.INSTANCE
.decompose(selectedObject);
}
});
}
}
/** The global redo action. */
public final RedoAction globalRedoAction;
/** Constructor. */
public ActionService() {
globalUndoAction.setId(ActionFactory.UNDO.getId());
globalRedoAction.setId(ActionFactory.REDO.getId());
globalDeleteAction.setId(ActionFactory.DELETE.getId());
globalDeleteAction = new DeleteAction();
globalUndoAction = new UndoAction();
globalRedoAction = new RedoAction();
for (ITopLevelElement context : IPersistencyService.INSTANCE
.getTopLevelElements()) {
......@@ -160,35 +101,9 @@ public class ActionService implements IActionService,
public void refresh() {
EObject target = EObjectSelectionUtils
.getCurrentSelectionFirstElement();
if (target == null) {
globalUndoAction.setEnabled(false);
globalRedoAction.setEnabled(false);
globalDeleteAction.setEnabled(false);
return;
}
globalUndoAction.setTarget(target);
globalUndoAction.setEnabled(ICommandStackService.INSTANCE
.canUndo(target));
globalRedoAction.setTarget(target);
globalRedoAction.setEnabled(ICommandStackService.INSTANCE
.canRedo(target));
globalDeleteAction.setTarget(target);
boolean enabled = false;
if (!IPersistencyService.INSTANCE.isTopLevelElement(target)) {
if (IElementCompositorService.INSTANCE.canDecompose(target)) {
enabled = true;
globalDeleteAction.setUseElementCompositor(true);
} else if (IConnectionCompositorService.INSTANCE
.canDisconnect(target)) {
enabled = true;
globalDeleteAction.setUseElementCompositor(false);
}
}
globalDeleteAction.setEnabled(enabled);
globalDeleteAction.refresh(target);
globalUndoAction.refresh(target);
globalRedoAction.refresh(target);
}
/** {@inheritDoc} */
......
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.ui.internal.actions;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionFactory;
import org.fortiss.tooling.kernel.service.ICommandStackService;
import org.fortiss.tooling.kernel.service.IConnectionCompositorService;
import org.fortiss.tooling.kernel.service.IElementCompositorService;
import org.fortiss.tooling.kernel.service.IPersistencyService;
import org.fortiss.tooling.kernel.ui.extension.base.EObjectActionBase;
/**
* The {@link DeleteAction} uses the {@link IElementCompositorService} and the
* {@link IConnectionCompositorService} to determine the enabled state of this
* action.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class DeleteAction extends EObjectActionBase {
/** Flag for using element or connection compositor. */
private boolean useElementCompositor;
/** Constructor. */
public DeleteAction() {
super("Delete", PlatformUI.getWorkbench().getSharedImages()
.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));
setId(ActionFactory.DELETE.getId());
}
/** Refreshes the action's target and enabled state. */
public void refresh(EObject element) {
setTarget(element);
if (element == null) {
setEnabled(false);
return;
}
boolean enabled = false;
if (!IPersistencyService.INSTANCE.isTopLevelElement(element)) {
if (IElementCompositorService.INSTANCE.canDecompose(element)) {
enabled = true;
useElementCompositor = true;
return;
} else if (IConnectionCompositorService.INSTANCE
.canDisconnect(element)) {
enabled = true;
useElementCompositor = false;
return;
}
}
setEnabled(enabled);
}
/** {@inheritDoc} */
@Override
public void run() {
final EObject selectedObject = getTarget();
if (selectedObject == null) {
return;
}
ICommandStackService.INSTANCE.runAsCommand(selectedObject,
new Runnable() {
@Override
public void run() {
if (useElementCompositor) {
IElementCompositorService.INSTANCE
.decompose(selectedObject);
} else {
IConnectionCompositorService.INSTANCE
.disconnect(selectedObject);
}
}
});
}
}
\ No newline at end of file
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.ui.internal.actions;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionFactory;
import org.fortiss.tooling.kernel.service.ICommandStackService;
import org.fortiss.tooling.kernel.ui.extension.base.EObjectActionBase;
/**
* The {@link RedoAction} uses the {@link ICommandStackService} to determine the
* enabled state of this action.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class RedoAction extends EObjectActionBase {
/** Constructor. */
public RedoAction() {
super("Redo", PlatformUI.getWorkbench().getSharedImages()
.getImageDescriptor(ISharedImages.IMG_TOOL_REDO));
setId(ActionFactory.REDO.getId());
}
/** Refreshes the action's target and enabled state. */
public void refresh(EObject element) {
setTarget(element);
if (element == null) {
setEnabled(false);
return;
}
setEnabled(ICommandStackService.INSTANCE.canRedo(element));
}
/** {@inheritDoc} */
@Override
public void run() {
if (getTarget() != null) {
ICommandStackService.INSTANCE.redo(getTarget());
}
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.ui.internal.actions;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionFactory;
import org.fortiss.tooling.kernel.service.ICommandStackService;
import org.fortiss.tooling.kernel.ui.extension.base.EObjectActionBase;
/**
* The {@link UndoAction} uses the {@link ICommandStackService} to determine the
* enabled state of this action.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class UndoAction extends EObjectActionBase {
/** Constructor. */
public UndoAction() {
super("Undo", PlatformUI.getWorkbench().getSharedImages()
.getImageDescriptor(ISharedImages.IMG_TOOL_UNDO));
setId(ActionFactory.UNDO.getId());
}
/** Refreshes the action's target and enabled state. */
public void refresh(EObject element) {
setTarget(element);
if (element == null) {
setEnabled(false);
return;
}
setEnabled(ICommandStackService.INSTANCE.canUndo(element));
}
/** {@inheritDoc} */
@Override
public void run() {
if (getTarget() != null) {
ICommandStackService.INSTANCE.undo(getTarget());
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment