Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Question (Yes/No) for Delete elements
Question (Yes/No) for Delete elements [message #159220] Fri, 09 November 2007 11:30 Go to next message
Eclipse UserFriend
Originally posted by: juergen.sterr.brainchild.de

Hi,

I want warn the user with a message(Yes/No), after the option (Delete from
Model).
It is important to me because it delete the complete tree behind this
element.
Now I look for a way in *BaseItemSemanticEditPolicy.

My question is:
Where can I implement this message?
Which return command? (Null gives an error)


Thanks
Jürgen
Re: Question (Yes/No) for Delete elements [message #159237 is a reply to message #159220] Fri, 09 November 2007 12:26 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ijerez2001.gmail.com

I think that you can implement in the YourContainerEditpart, where
YourContainer is the element to contain your element to delete.
In this class, you have to overwrite the handleNotificationEvent, and ask
(in a dialog) to deleting.
If the user click "no" you can do a undo with your oldvalue from your
notification.
Only it?s an idea, i am not sure that it work.
Luck!


""Jürgen" Sterr" <juergen.sterr@brainchild.de> escribió en el mensaje de
noticias:f95cf66cd347920f3a5f25c2c5118bc7$1@www.eclipse.org...
> Hi,
>
> I want warn the user with a message(Yes/No), after the option (Delete from
> Model).
> It is important to me because it delete the complete tree behind this
> element.
> Now I look for a way in *BaseItemSemanticEditPolicy.
>
> My question is:
> Where can I implement this message?
> Which return command? (Null gives an error)
>
>
> Thanks
> Jürgen
Re: Question (Yes/No) for Delete elements [message #159410 is a reply to message #159220] Sat, 10 November 2007 13:44 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jan.herriger.gmx.de

This is a multi-part message in MIME format.
--------------070900080306000604020103
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 8bit

Hi J
Re: Question (Yes/No) for Delete elements [message #159418 is a reply to message #159410] Sat, 10 November 2007 14:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jan.herriger.gmx.de

This is a multi-part message in MIME format.
--------------010800000008060804030800
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

attached wrong file...

--------------010800000008060804030800
Content-Type: text/java;
name="AggregatedUnitItemSemanticEditPolicy.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="AggregatedUnitItemSemanticEditPolicy.java"

package org.memo.orgml.organisation.diagram.edit.policies;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;

import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CompoundCommand;
import org.eclipse.gef.commands.UnexecutableCommand;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditP art;
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
import org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceCo nstants;
import org.eclipse.gmf.runtime.diagram.ui.requests.EditCommandReque stWrapper;
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElemen tCommand;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelatio nshipRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElemen tRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelat ionshipRequest;
import org.eclipse.gmf.runtime.notation.Edge;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.widgets.Display;
import org.memo.orgml.organisation.AggregatedUnit;
import org.memo.orgml.organisation.ISuperiorLinkSource;
import org.memo.orgml.organisation.OrganisationModel;
import org.memo.orgml.organisation.OrganisationPackage;
import org.memo.orgml.organisation.UnitOfWork;
import org.memo.orgml.organisation.diagram.edit.commands.AggregateU nitLinkReorientCommand;
import org.memo.orgml.organisation.diagram.edit.commands.AggregateU nitLinkTypeLinkCreateCommand;
import org.memo.orgml.organisation.diagram.edit.commands.Interactio nLinkReorientCommand;
import org.memo.orgml.organisation.diagram.edit.commands.Interactio nLinkTypeLinkCreateCommand;
import org.memo.orgml.organisation.diagram.edit.commands.SuperiorLi nkReorientCommand;
import org.memo.orgml.organisation.diagram.edit.commands.SuperiorLi nkTypeLinkCreateCommand;
import org.memo.orgml.organisation.diagram.edit.parts.AggregateUnit LinkEditPart;
import org.memo.orgml.organisation.diagram.edit.parts.AggregatedUni tEditPart;
import org.memo.orgml.organisation.diagram.edit.parts.InteractionLi nkEditPart;
import org.memo.orgml.organisation.diagram.edit.parts.SuperiorLinkE ditPart;
import org.memo.orgml.organisation.diagram.part.OrganisationDiagram EditorPlugin;
import org.memo.orgml.organisation.diagram.providers.OrganisationEl ementTypes;

/**
* @generated
*/
public class AggregatedUnitItemSemanticEditPolicy extends
OrganisationBaseItemSemanticEditPolicy {

/**
* @generated NOT
*/
protected Command getDestroyElementCommand(DestroyElementRequest req) {

IPreferenceStore store = (IPreferenceStore) ((IGraphicalEditPart) getHost())
.getDiagramPreferencesHint().getPreferenceStore();

//check preferences whether to prompt or not
boolean toggle = store.getBoolean(IPreferenceConstants.PREF_PROMPT_ON_DEL_FRO M_MODEL);
if (toggle)
{
final String DELETE_FROM_MODEL_DLG_TITLE = DiagramUIMessages.PromptingDeleteFromModelAction_DeleteFromM odelDialog_Title;

final String DELETE_FROM_MODEL_DLG_MESSAGE = DiagramUIMessages.PromptingDeleteFromModelAction_DeleteFromM odelDialog_Message;

final String DELETE_FROM_MODEL_DLG_TOGGLE_LABEL = DiagramUIMessages.MessageDialogWithToggle_DoNotPromptAgainTo ggle_label;

MessageDialogWithToggle dialog = MessageDialogWithToggle
.openYesNoQuestion(Display.getCurrent().getActiveShell(),
DELETE_FROM_MODEL_DLG_TITLE , DELETE_FROM_MODEL_DLG_MESSAGE,
DELETE_FROM_MODEL_DLG_TOGGLE_LABEL, false,
store,
IPreferenceConstants.PREF_PROMPT_ON_DEL_FROM_MODEL);

//save user decision for future prompts
store.setValue(IPreferenceConstants.PREF_PROMPT_ON_DEL_FROM_ MODEL, !dialog.getToggleState());
OrganisationDiagramEditorPlugin.getInstance().savePluginPref erences();

if (dialog.getReturnCode() != IDialogConstants.YES_ID)
return UnexecutableCommand.INSTANCE;
}

CompoundCommand cc = new CompoundCommand();
Collection allEdges = new ArrayList();
View view = (View) getHost().getModel();
allEdges.addAll(view.getSourceEdges());
allEdges.addAll(view.getTargetEdges());
for (Iterator it = allEdges.iterator(); it.hasNext();) {
Edge nextEdge = (Edge) it.next();
EditPart nextEditPart = (EditPart) getHost().getViewer()
.getEditPartRegistry().get(nextEdge);
EditCommandRequestWrapper editCommandRequest = new EditCommandRequestWrapper(
new DestroyElementRequest(
((AggregatedUnitEditPart) getHost())
.getEditingDomain(), req
.isConfirmationRequired()),
Collections.EMPTY_MAP);
cc.add(nextEditPart.getCommand(editCommandRequest));
}
cc.add(getMSLWrapper(new DestroyElementCommand(req) {

protected EObject getElementToDestroy() {
View view = (View) getHost().getModel();
EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
if (annotation != null) {
return view;
}
return super.getElementToDestroy();
}

}));
return cc;
}

/**
* @generated
*/
protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
if (OrganisationElementTypes.InteractionLink_4002 == req
.getElementType()) {
return req.getTarget() == null ? getCreateStartOutgoingInteractionLink_4002Command(req)
: getCreateCompleteIncomingInteractionLink_4002Command(req);
}
if (OrganisationElementTypes.AggregateUnitLink_4004 == req
.getElementType()) {
return req.getTarget() == null ? getCreateStartOutgoingAggregateUnitLink_4004Command(req)
: getCreateCompleteIncomingAggregateUnitLink_4004Command(req);
}
if (OrganisationElementTypes.SuperiorLink_4005 == req.getElementType()) {
return req.getTarget() == null ? null
: getCreateCompleteIncomingSuperiorLink_4005Command(req);
}
return super.getCreateRelationshipCommand(req);
}

/**
* @generated
*/
protected Command getCreateStartOutgoingInteractionLink_4002Command(
CreateRelationshipRequest req) {
EObject sourceEObject = req.getSource();
if (false == sourceEObject instanceof UnitOfWork) {
return UnexecutableCommand.INSTANCE;
}
UnitOfWork source = (UnitOfWork) sourceEObject;
OrganisationModel container = (OrganisationModel) getRelationshipContainer(
source, OrganisationPackage.eINSTANCE.getOrganisationModel(),
req.getElementType());
if (container == null) {
return UnexecutableCommand.INSTANCE;
}
if (!OrganisationBaseItemSemanticEditPolicy.LinkConstraints
.canCreateInteractionLink_4002(container, source, null)) {
return UnexecutableCommand.INSTANCE;
}
return new Command() {
};
}

/**
* @generated
*/
protected Command getCreateCompleteIncomingInteractionLink_4002Command(
CreateRelationshipRequest req) {
EObject sourceEObject = req.getSource();
EObject targetEObject = req.getTarget();
if (false == sourceEObject instanceof UnitOfWork
|| false == targetEObject instanceof UnitOfWork) {
return UnexecutableCommand.INSTANCE;
}
UnitOfWork source = (UnitOfWork) sourceEObject;
UnitOfWork target = (UnitOfWork) targetEObject;
OrganisationModel container = (OrganisationModel) getRelationshipContainer(
source, OrganisationPackage.eINSTANCE.getOrganisationModel(),
req.getElementType());
if (container == null) {
return UnexecutableCommand.INSTANCE;
}
if (!OrganisationBaseItemSemanticEditPolicy.LinkConstraints
.canCreateInteractionLink_4002(container, source, target)) {
return UnexecutableCommand.INSTANCE;
}
if (req.getContainmentFeature() == null) {
req.setContainmentFeature(OrganisationPackage.eINSTANCE
.getOrganisationModel_Links());
}
return getMSLWrapper(new InteractionLinkTypeLinkCreateCommand(req,
container, source, target));
}

/**
* @generated
*/
protected Command getCreateStartOutgoingAggregateUnitLink_4004Command(
CreateRelationshipRequest req) {
EObject sourceEObject = req.getSource();
if (false == sourceEObject instanceof AggregatedUnit) {
return UnexecutableCommand.INSTANCE;
}
AggregatedUnit source = (AggregatedUnit) sourceEObject;
OrganisationModel container = (OrganisationModel) getRelationshipContainer(
source, OrganisationPackage.eINSTANCE.getOrganisationModel(),
req.getElementType());
if (container == null) {
return UnexecutableCommand.INSTANCE;
}
if (!OrganisationBaseItemSemanticEditPolicy.LinkConstraints
.canCreateAggregateUnitLink_4004(container, source, null)) {
return UnexecutableCommand.INSTANCE;
}
return new Command() {
};
}

/**
* @generated
*/
protected Command getCreateCompleteIncomingAggregateUnitLink_4004Command(
CreateRelationshipRequest req) {
EObject sourceEObject = req.getSource();
EObject targetEObject = req.getTarget();
if (false == sourceEObject instanceof AggregatedUnit
|| false == targetEObject instanceof UnitOfWork) {
return UnexecutableCommand.INSTANCE;
}
AggregatedUnit source = (AggregatedUnit) sourceEObject;
UnitOfWork target = (UnitOfWork) targetEObject;
OrganisationModel container = (OrganisationModel) getRelationshipContainer(
source, OrganisationPackage.eINSTANCE.getOrganisationModel(),
req.getElementType());
if (container == null) {
return UnexecutableCommand.INSTANCE;
}
if (!OrganisationBaseItemSemanticEditPolicy.LinkConstraints
.canCreateAggregateUnitLink_4004(container, source, target)) {
return UnexecutableCommand.INSTANCE;
}
if (req.getContainmentFeature() == null) {
req.setContainmentFeature(OrganisationPackage.eINSTANCE
.getOrganisationModel_Links());
}
return getMSLWrapper(new AggregateUnitLinkTypeLinkCreateCommand(req,
container, source, target));
}

/**
* @generated
*/
protected Command getCreateCompleteIncomingSuperiorLink_4005Command(
CreateRelationshipRequest req) {
EObject sourceEObject = req.getSource();
EObject targetEObject = req.getTarget();
if (false == sourceEObject instanceof ISuperiorLinkSource
|| false == targetEObject instanceof UnitOfWork) {
return UnexecutableCommand.INSTANCE;
}
ISuperiorLinkSource source = (ISuperiorLinkSource) sourceEObject;
UnitOfWork target = (UnitOfWork) targetEObject;
OrganisationModel container = (OrganisationModel) getRelationshipContainer(
source, OrganisationPackage.eINSTANCE.getOrganisationModel(),
req.getElementType());
if (container == null) {
return UnexecutableCommand.INSTANCE;
}
if (!OrganisationBaseItemSemanticEditPolicy.LinkConstraints
.canCreateSuperiorLink_4005(container, source, target)) {
return UnexecutableCommand.INSTANCE;
}
if (req.getContainmentFeature() == null) {
req.setContainmentFeature(OrganisationPackage.eINSTANCE
.getOrganisationModel_Links());
}
return getMSLWrapper(new SuperiorLinkTypeLinkCreateCommand(req,
container, source, target));
}

/**
* Returns command to reorient EClass based link. New link target or source
* should be the domain model element associated with this node.
*
* @generated
*/
protected Command getReorientRelationshipCommand(
ReorientRelationshipRequest req) {
switch (getVisualID(req)) {
case InteractionLinkEditPart.VISUAL_ID:
return getMSLWrapper(new InteractionLinkReorientCommand(req));
case AggregateUnitLinkEditPart.VISUAL_ID:
return getMSLWrapper(new AggregateUnitLinkReorientCommand(req));
case SuperiorLinkEditPart.VISUAL_ID:
return getMSLWrapper(new SuperiorLinkReorientCommand(req));
}
return super.getReorientRelationshipCommand(req);
}

}

--------------010800000008060804030800--
Re: Question (Yes/No) for Delete elements [message #159853 is a reply to message #159418] Tue, 13 November 2007 03:43 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: arvinderbirdi.sbcglobal.net

Somehow this has a nasty side effect for me.
getDestroyElementCommand() is called when I do a simple select and it brings
up the yes/no dialog!
It is not able to delete.

When I do a delete, the dialog shows up and then I'm able to delete.

I am using europa eclipse with java 1.6.0.3. Windows 2003.


"Jan Herriger" <jan.herriger@gmx.de> wrote in message
news:fh4dmn$3hf$1@build.eclipse.org...
> attached wrong file...
>


------------------------------------------------------------ --------------------


> package org.memo.orgml.organisation.diagram.edit.policies;
>
> import java.util.ArrayList;
> import java.util.Collection;
> import java.util.Collections;
> import java.util.Iterator;
>
> import org.eclipse.emf.ecore.EAnnotation;
> import org.eclipse.emf.ecore.EObject;
> import org.eclipse.gef.EditPart;
> import org.eclipse.gef.commands.Command;
> import org.eclipse.gef.commands.CompoundCommand;
> import org.eclipse.gef.commands.UnexecutableCommand;
> import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditP art;
> import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
> import
> org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceCo nstants;
> import
> org.eclipse.gmf.runtime.diagram.ui.requests.EditCommandReque stWrapper;
> import
> org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElemen tCommand;
> import
> org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelatio nshipRequest;
> import
> org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElemen tRequest;
> import
> org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelat ionshipRequest;
> import org.eclipse.gmf.runtime.notation.Edge;
> import org.eclipse.gmf.runtime.notation.View;
> import org.eclipse.jface.dialogs.IDialogConstants;
> import org.eclipse.jface.dialogs.MessageDialogWithToggle;
> import org.eclipse.jface.preference.IPreferenceStore;
> import org.eclipse.swt.widgets.Display;
> import org.memo.orgml.organisation.AggregatedUnit;
> import org.memo.orgml.organisation.ISuperiorLinkSource;
> import org.memo.orgml.organisation.OrganisationModel;
> import org.memo.orgml.organisation.OrganisationPackage;
> import org.memo.orgml.organisation.UnitOfWork;
> import
> org.memo.orgml.organisation.diagram.edit.commands.AggregateU nitLinkReorientCommand;
> import
> org.memo.orgml.organisation.diagram.edit.commands.AggregateU nitLinkTypeLinkCreateCommand;
> import
> org.memo.orgml.organisation.diagram.edit.commands.Interactio nLinkReorientCommand;
> import
> org.memo.orgml.organisation.diagram.edit.commands.Interactio nLinkTypeLinkCreateCommand;
> import
> org.memo.orgml.organisation.diagram.edit.commands.SuperiorLi nkReorientCommand;
> import
> org.memo.orgml.organisation.diagram.edit.commands.SuperiorLi nkTypeLinkCreateCommand;
> import
> org.memo.orgml.organisation.diagram.edit.parts.AggregateUnit LinkEditPart;
> import
> org.memo.orgml.organisation.diagram.edit.parts.AggregatedUni tEditPart;
> import
> org.memo.orgml.organisation.diagram.edit.parts.InteractionLi nkEditPart;
> import
> org.memo.orgml.organisation.diagram.edit.parts.SuperiorLinkE ditPart;
> import
> org.memo.orgml.organisation.diagram.part.OrganisationDiagram EditorPlugin;
> import
> org.memo.orgml.organisation.diagram.providers.OrganisationEl ementTypes;
>
> /**
> * @generated
> */
> public class AggregatedUnitItemSemanticEditPolicy extends
> OrganisationBaseItemSemanticEditPolicy {
>
> /**
> * @generated NOT
> */
> protected Command getDestroyElementCommand(DestroyElementRequest req) {
>
> IPreferenceStore store = (IPreferenceStore) ((IGraphicalEditPart)
> getHost())
> .getDiagramPreferencesHint().getPreferenceStore();
>
> //check preferences whether to prompt or not
> boolean toggle =
> store.getBoolean(IPreferenceConstants.PREF_PROMPT_ON_DEL_FRO M_MODEL);
> if (toggle)
> {
> final String DELETE_FROM_MODEL_DLG_TITLE =
> DiagramUIMessages.PromptingDeleteFromModelAction_DeleteFromM odelDialog_Title;
>
> final String DELETE_FROM_MODEL_DLG_MESSAGE =
> DiagramUIMessages.PromptingDeleteFromModelAction_DeleteFromM odelDialog_Message;
>
> final String DELETE_FROM_MODEL_DLG_TOGGLE_LABEL =
> DiagramUIMessages.MessageDialogWithToggle_DoNotPromptAgainTo ggle_label;
>
> MessageDialogWithToggle dialog = MessageDialogWithToggle
> .openYesNoQuestion(Display.getCurrent().getActiveShell(),
> DELETE_FROM_MODEL_DLG_TITLE , DELETE_FROM_MODEL_DLG_MESSAGE,
> DELETE_FROM_MODEL_DLG_TOGGLE_LABEL, false,
> store,
> IPreferenceConstants.PREF_PROMPT_ON_DEL_FROM_MODEL);
>
> //save user decision for future prompts
> store.setValue(IPreferenceConstants.PREF_PROMPT_ON_DEL_FROM_ MODEL,
> !dialog.getToggleState());
> OrganisationDiagramEditorPlugin.getInstance().savePluginPref erences();
>
> if (dialog.getReturnCode() != IDialogConstants.YES_ID)
> return UnexecutableCommand.INSTANCE;
> }
>
> CompoundCommand cc = new CompoundCommand();
> Collection allEdges = new ArrayList();
> View view = (View) getHost().getModel();
> allEdges.addAll(view.getSourceEdges());
> allEdges.addAll(view.getTargetEdges());
> for (Iterator it = allEdges.iterator(); it.hasNext();) {
> Edge nextEdge = (Edge) it.next();
> EditPart nextEditPart = (EditPart) getHost().getViewer()
> .getEditPartRegistry().get(nextEdge);
> EditCommandRequestWrapper editCommandRequest = new
> EditCommandRequestWrapper(
> new DestroyElementRequest(
> ((AggregatedUnitEditPart) getHost())
> .getEditingDomain(), req
> .isConfirmationRequired()),
> Collections.EMPTY_MAP);
> cc.add(nextEditPart.getCommand(editCommandRequest));
> }
> cc.add(getMSLWrapper(new DestroyElementCommand(req) {
>
> protected EObject getElementToDestroy() {
> View view = (View) getHost().getModel();
> EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
> if (annotation != null) {
> return view;
> }
> return super.getElementToDestroy();
> }
>
> }));
> return cc;
> }
>
> /**
> * @generated
> */
> protected Command getCreateRelationshipCommand(CreateRelationshipRequest
> req) {
> if (OrganisationElementTypes.InteractionLink_4002 == req
> .getElementType()) {
> return req.getTarget() == null ?
> getCreateStartOutgoingInteractionLink_4002Command(req)
> : getCreateCompleteIncomingInteractionLink_4002Command(req);
> }
> if (OrganisationElementTypes.AggregateUnitLink_4004 == req
> .getElementType()) {
> return req.getTarget() == null ?
> getCreateStartOutgoingAggregateUnitLink_4004Command(req)
> : getCreateCompleteIncomingAggregateUnitLink_4004Command(req);
> }
> if (OrganisationElementTypes.SuperiorLink_4005 == req.getElementType()) {
> return req.getTarget() == null ? null
> : getCreateCompleteIncomingSuperiorLink_4005Command(req);
> }
> return super.getCreateRelationshipCommand(req);
> }
>
> /**
> * @generated
> */
> protected Command getCreateStartOutgoingInteractionLink_4002Command(
> CreateRelationshipRequest req) {
> EObject sourceEObject = req.getSource();
> if (false == sourceEObject instanceof UnitOfWork) {
> return UnexecutableCommand.INSTANCE;
> }
> UnitOfWork source = (UnitOfWork) sourceEObject;
> OrganisationModel container = (OrganisationModel)
> getRelationshipContainer(
> source, OrganisationPackage.eINSTANCE.getOrganisationModel(),
> req.getElementType());
> if (container == null) {
> return UnexecutableCommand.INSTANCE;
> }
> if (!OrganisationBaseItemSemanticEditPolicy.LinkConstraints
> .canCreateInteractionLink_4002(container, source, null)) {
> return UnexecutableCommand.INSTANCE;
> }
> return new Command() {
> };
> }
>
> /**
> * @generated
> */
> protected Command getCreateCompleteIncomingInteractionLink_4002Command(
> CreateRelationshipRequest req) {
> EObject sourceEObject = req.getSource();
> EObject targetEObject = req.getTarget();
> if (false == sourceEObject instanceof UnitOfWork
> || false == targetEObject instanceof UnitOfWork) {
> return UnexecutableCommand.INSTANCE;
> }
> UnitOfWork source = (UnitOfWork) sourceEObject;
> UnitOfWork target = (UnitOfWork) targetEObject;
> OrganisationModel container = (OrganisationModel)
> getRelationshipContainer(
> source, OrganisationPackage.eINSTANCE.getOrganisationModel(),
> req.getElementType());
> if (container == null) {
> return UnexecutableCommand.INSTANCE;
> }
> if (!OrganisationBaseItemSemanticEditPolicy.LinkConstraints
> .canCreateInteractionLink_4002(container, source, target)) {
> return UnexecutableCommand.INSTANCE;
> }
> if (req.getContainmentFeature() == null) {
> req.setContainmentFeature(OrganisationPackage.eINSTANCE
> .getOrganisationModel_Links());
> }
> return getMSLWrapper(new InteractionLinkTypeLinkCreateCommand(req,
> container, source, target));
> }
>
> /**
> * @generated
> */
> protected Command getCreateStartOutgoingAggregateUnitLink_4004Command(
> CreateRelationshipRequest req) {
> EObject sourceEObject = req.getSource();
> if (false == sourceEObject instanceof AggregatedUnit) {
> return UnexecutableCommand.INSTANCE;
> }
> AggregatedUnit source = (AggregatedUnit) sourceEObject;
> OrganisationModel container = (OrganisationModel)
> getRelationshipContainer(
> source, OrganisationPackage.eINSTANCE.getOrganisationModel(),
> req.getElementType());
> if (container == null) {
> return UnexecutableCommand.INSTANCE;
> }
> if (!OrganisationBaseItemSemanticEditPolicy.LinkConstraints
> .canCreateAggregateUnitLink_4004(container, source, null)) {
> return UnexecutableCommand.INSTANCE;
> }
> return new Command() {
> };
> }
>
> /**
> * @generated
> */
> protected Command getCreateCompleteIncomingAggregateUnitLink_4004Command(
> CreateRelationshipRequest req) {
> EObject sourceEObject = req.getSource();
> EObject targetEObject = req.getTarget();
> if (false == sourceEObject instanceof AggregatedUnit
> || false == targetEObject instanceof UnitOfWork) {
> return UnexecutableCommand.INSTANCE;
> }
> AggregatedUnit source = (AggregatedUnit) sourceEObject;
> UnitOfWork target = (UnitOfWork) targetEObject;
> OrganisationModel container = (OrganisationModel)
> getRelationshipContainer(
> source, OrganisationPackage.eINSTANCE.getOrganisationModel(),
> req.getElementType());
> if (container == null) {
> return UnexecutableCommand.INSTANCE;
> }
> if (!OrganisationBaseItemSemanticEditPolicy.LinkConstraints
> .canCreateAggregateUnitLink_4004(container, source, target)) {
> return UnexecutableCommand.INSTANCE;
> }
> if (req.getContainmentFeature() == null) {
> req.setContainmentFeature(OrganisationPackage.eINSTANCE
> .getOrganisationModel_Links());
> }
> return getMSLWrapper(new AggregateUnitLinkTypeLinkCreateCommand(req,
> container, source, target));
> }
>
> /**
> * @generated
> */
> protected Command getCreateCompleteIncomingSuperiorLink_4005Command(
> CreateRelationshipRequest req) {
> EObject sourceEObject = req.getSource();
> EObject targetEObject = req.getTarget();
> if (false == sourceEObject instanceof ISuperiorLinkSource
> || false == targetEObject instanceof UnitOfWork) {
> return UnexecutableCommand.INSTANCE;
> }
> ISuperiorLinkSource source = (ISuperiorLinkSource) sourceEObject;
> UnitOfWork target = (UnitOfWork) targetEObject;
> OrganisationModel container = (OrganisationModel)
> getRelationshipContainer(
> source, OrganisationPackage.eINSTANCE.getOrganisationModel(),
> req.getElementType());
> if (container == null) {
> return UnexecutableCommand.INSTANCE;
> }
> if (!OrganisationBaseItemSemanticEditPolicy.LinkConstraints
> .canCreateSuperiorLink_4005(container, source, target)) {
> return UnexecutableCommand.INSTANCE;
> }
> if (req.getContainmentFeature() == null) {
> req.setContainmentFeature(OrganisationPackage.eINSTANCE
> .getOrganisationModel_Links());
> }
> return getMSLWrapper(new SuperiorLinkTypeLinkCreateCommand(req,
> container, source, target));
> }
>
> /**
> * Returns command to reorient EClass based link. New link target or source
> * should be the domain model element associated with this node.
> *
> * @generated
> */
> protected Command getReorientRelationshipCommand(
> ReorientRelationshipRequest req) {
> switch (getVisualID(req)) {
> case InteractionLinkEditPart.VISUAL_ID:
> return getMSLWrapper(new InteractionLinkReorientCommand(req));
> case AggregateUnitLinkEditPart.VISUAL_ID:
> return getMSLWrapper(new AggregateUnitLinkReorientCommand(req));
> case SuperiorLinkEditPart.VISUAL_ID:
> return getMSLWrapper(new SuperiorLinkReorientCommand(req));
> }
> return super.getReorientRelationshipCommand(req);
> }
>
> }
>
Re: Question (Yes/No) for Delete elements [message #160493 is a reply to message #159853] Thu, 15 November 2007 04:50 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: arvinderbirdi.sbcglobal.net

I have this problem with a nested node. When it is a top level node, Destroy
element is not called on a selection. GMF 2.0


"arvinder birdi" <arvinderbirdi@sbcglobal.net> wrote in message
news:fhb6gg$shp$1@build.eclipse.org...
> Somehow this has a nasty side effect for me.
> getDestroyElementCommand() is called when I do a simple select and it
> brings up the yes/no dialog!
> It is not able to delete.
>
> When I do a delete, the dialog shows up and then I'm able to delete.
>
> I am using europa eclipse with java 1.6.0.3. Windows 2003.
>
>
> "Jan Herriger" <jan.herriger@gmx.de> wrote in message
> news:fh4dmn$3hf$1@build.eclipse.org...
>> attached wrong file...
>>
>
>
> ------------------------------------------------------------ --------------------
>
>
>> package org.memo.orgml.organisation.diagram.edit.policies;
>>
>> import java.util.ArrayList;
>> import java.util.Collection;
>> import java.util.Collections;
>> import java.util.Iterator;
>>
>> import org.eclipse.emf.ecore.EAnnotation;
>> import org.eclipse.emf.ecore.EObject;
>> import org.eclipse.gef.EditPart;
>> import org.eclipse.gef.commands.Command;
>> import org.eclipse.gef.commands.CompoundCommand;
>> import org.eclipse.gef.commands.UnexecutableCommand;
>> import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditP art;
>> import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
>> import
>> org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceCo nstants;
>> import
>> org.eclipse.gmf.runtime.diagram.ui.requests.EditCommandReque stWrapper;
>> import
>> org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElemen tCommand;
>> import
>> org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelatio nshipRequest;
>> import
>> org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElemen tRequest;
>> import
>> org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelat ionshipRequest;
>> import org.eclipse.gmf.runtime.notation.Edge;
>> import org.eclipse.gmf.runtime.notation.View;
>> import org.eclipse.jface.dialogs.IDialogConstants;
>> import org.eclipse.jface.dialogs.MessageDialogWithToggle;
>> import org.eclipse.jface.preference.IPreferenceStore;
>> import org.eclipse.swt.widgets.Display;
>> import org.memo.orgml.organisation.AggregatedUnit;
>> import org.memo.orgml.organisation.ISuperiorLinkSource;
>> import org.memo.orgml.organisation.OrganisationModel;
>> import org.memo.orgml.organisation.OrganisationPackage;
>> import org.memo.orgml.organisation.UnitOfWork;
>> import
>> org.memo.orgml.organisation.diagram.edit.commands.AggregateU nitLinkReorientCommand;
>> import
>> org.memo.orgml.organisation.diagram.edit.commands.AggregateU nitLinkTypeLinkCreateCommand;
>> import
>> org.memo.orgml.organisation.diagram.edit.commands.Interactio nLinkReorientCommand;
>> import
>> org.memo.orgml.organisation.diagram.edit.commands.Interactio nLinkTypeLinkCreateCommand;
>> import
>> org.memo.orgml.organisation.diagram.edit.commands.SuperiorLi nkReorientCommand;
>> import
>> org.memo.orgml.organisation.diagram.edit.commands.SuperiorLi nkTypeLinkCreateCommand;
>> import
>> org.memo.orgml.organisation.diagram.edit.parts.AggregateUnit LinkEditPart;
>> import
>> org.memo.orgml.organisation.diagram.edit.parts.AggregatedUni tEditPart;
>> import
>> org.memo.orgml.organisation.diagram.edit.parts.InteractionLi nkEditPart;
>> import
>> org.memo.orgml.organisation.diagram.edit.parts.SuperiorLinkE ditPart;
>> import
>> org.memo.orgml.organisation.diagram.part.OrganisationDiagram EditorPlugin;
>> import
>> org.memo.orgml.organisation.diagram.providers.OrganisationEl ementTypes;
>>
>> /**
>> * @generated
>> */
>> public class AggregatedUnitItemSemanticEditPolicy extends
>> OrganisationBaseItemSemanticEditPolicy {
>>
>> /**
>> * @generated NOT
>> */
>> protected Command getDestroyElementCommand(DestroyElementRequest req) {
>>
>> IPreferenceStore store = (IPreferenceStore) ((IGraphicalEditPart)
>> getHost())
>> .getDiagramPreferencesHint().getPreferenceStore();
>>
>> //check preferences whether to prompt or not
>> boolean toggle =
>> store.getBoolean(IPreferenceConstants.PREF_PROMPT_ON_DEL_FRO M_MODEL);
>> if (toggle)
>> {
>> final String DELETE_FROM_MODEL_DLG_TITLE =
>> DiagramUIMessages.PromptingDeleteFromModelAction_DeleteFromM odelDialog_Title;
>>
>> final String DELETE_FROM_MODEL_DLG_MESSAGE =
>> DiagramUIMessages.PromptingDeleteFromModelAction_DeleteFromM odelDialog_Message;
>>
>> final String DELETE_FROM_MODEL_DLG_TOGGLE_LABEL =
>> DiagramUIMessages.MessageDialogWithToggle_DoNotPromptAgainTo ggle_label;
>>
>> MessageDialogWithToggle dialog = MessageDialogWithToggle
>> .openYesNoQuestion(Display.getCurrent().getActiveShell(),
>> DELETE_FROM_MODEL_DLG_TITLE , DELETE_FROM_MODEL_DLG_MESSAGE,
>> DELETE_FROM_MODEL_DLG_TOGGLE_LABEL, false,
>> store,
>> IPreferenceConstants.PREF_PROMPT_ON_DEL_FROM_MODEL);
>>
>> //save user decision for future prompts
>> store.setValue(IPreferenceConstants.PREF_PROMPT_ON_DEL_FROM_ MODEL,
>> !dialog.getToggleState());
>> OrganisationDiagramEditorPlugin.getInstance().savePluginPref erences();
>>
>> if (dialog.getReturnCode() != IDialogConstants.YES_ID)
>> return UnexecutableCommand.INSTANCE;
>> }
>>
>> CompoundCommand cc = new CompoundCommand();
>> Collection allEdges = new ArrayList();
>> View view = (View) getHost().getModel();
>> allEdges.addAll(view.getSourceEdges());
>> allEdges.addAll(view.getTargetEdges());
>> for (Iterator it = allEdges.iterator(); it.hasNext();) {
>> Edge nextEdge = (Edge) it.next();
>> EditPart nextEditPart = (EditPart) getHost().getViewer()
>> .getEditPartRegistry().get(nextEdge);
>> EditCommandRequestWrapper editCommandRequest = new
>> EditCommandRequestWrapper(
>> new DestroyElementRequest(
>> ((AggregatedUnitEditPart) getHost())
>> .getEditingDomain(), req
>> .isConfirmationRequired()),
>> Collections.EMPTY_MAP);
>> cc.add(nextEditPart.getCommand(editCommandRequest));
>> }
>> cc.add(getMSLWrapper(new DestroyElementCommand(req) {
>>
>> protected EObject getElementToDestroy() {
>> View view = (View) getHost().getModel();
>> EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
>> if (annotation != null) {
>> return view;
>> }
>> return super.getElementToDestroy();
>> }
>>
>> }));
>> return cc;
>> }
>>
>> /**
>> * @generated
>> */
>> protected Command getCreateRelationshipCommand(CreateRelationshipRequest
>> req) {
>> if (OrganisationElementTypes.InteractionLink_4002 == req
>> .getElementType()) {
>> return req.getTarget() == null ?
>> getCreateStartOutgoingInteractionLink_4002Command(req)
>> : getCreateCompleteIncomingInteractionLink_4002Command(req);
>> }
>> if (OrganisationElementTypes.AggregateUnitLink_4004 == req
>> .getElementType()) {
>> return req.getTarget() == null ?
>> getCreateStartOutgoingAggregateUnitLink_4004Command(req)
>> : getCreateCompleteIncomingAggregateUnitLink_4004Command(req);
>> }
>> if (OrganisationElementTypes.SuperiorLink_4005 == req.getElementType()) {
>> return req.getTarget() == null ? null
>> : getCreateCompleteIncomingSuperiorLink_4005Command(req);
>> }
>> return super.getCreateRelationshipCommand(req);
>> }
>>
>> /**
>> * @generated
>> */
>> protected Command getCreateStartOutgoingInteractionLink_4002Command(
>> CreateRelationshipRequest req) {
>> EObject sourceEObject = req.getSource();
>> if (false == sourceEObject instanceof UnitOfWork) {
>> return UnexecutableCommand.INSTANCE;
>> }
>> UnitOfWork source = (UnitOfWork) sourceEObject;
>> OrganisationModel container = (OrganisationModel)
>> getRelationshipContainer(
>> source, OrganisationPackage.eINSTANCE.getOrganisationModel(),
>> req.getElementType());
>> if (container == null) {
>> return UnexecutableCommand.INSTANCE;
>> }
>> if (!OrganisationBaseItemSemanticEditPolicy.LinkConstraints
>> .canCreateInteractionLink_4002(container, source, null)) {
>> return UnexecutableCommand.INSTANCE;
>> }
>> return new Command() {
>> };
>> }
>>
>> /**
>> * @generated
>> */
>> protected Command getCreateCompleteIncomingInteractionLink_4002Command(
>> CreateRelationshipRequest req) {
>> EObject sourceEObject = req.getSource();
>> EObject targetEObject = req.getTarget();
>> if (false == sourceEObject instanceof UnitOfWork
>> || false == targetEObject instanceof UnitOfWork) {
>> return UnexecutableCommand.INSTANCE;
>> }
>> UnitOfWork source = (UnitOfWork) sourceEObject;
>> UnitOfWork target = (UnitOfWork) targetEObject;
>> OrganisationModel container = (OrganisationModel)
>> getRelationshipContainer(
>> source, OrganisationPackage.eINSTANCE.getOrganisationModel(),
>> req.getElementType());
>> if (container == null) {
>> return UnexecutableCommand.INSTANCE;
>> }
>> if (!OrganisationBaseItemSemanticEditPolicy.LinkConstraints
>> .canCreateInteractionLink_4002(container, source, target)) {
>> return UnexecutableCommand.INSTANCE;
>> }
>> if (req.getContainmentFeature() == null) {
>> req.setContainmentFeature(OrganisationPackage.eINSTANCE
>> .getOrganisationModel_Links());
>> }
>> return getMSLWrapper(new InteractionLinkTypeLinkCreateCommand(req,
>> container, source, target));
>> }
>>
>> /**
>> * @generated
>> */
>> protected Command getCreateStartOutgoingAggregateUnitLink_4004Command(
>> CreateRelationshipRequest req) {
>> EObject sourceEObject = req.getSource();
>> if (false == sourceEObject instanceof AggregatedUnit) {
>> return UnexecutableCommand.INSTANCE;
>> }
>> AggregatedUnit source = (AggregatedUnit) sourceEObject;
>> OrganisationModel container = (OrganisationModel)
>> getRelationshipContainer(
>> source, OrganisationPackage.eINSTANCE.getOrganisationModel(),
>> req.getElementType());
>> if (container == null) {
>> return UnexecutableCommand.INSTANCE;
>> }
>> if (!OrganisationBaseItemSemanticEditPolicy.LinkConstraints
>> .canCreateAggregateUnitLink_4004(container, source, null)) {
>> return UnexecutableCommand.INSTANCE;
>> }
>> return new Command() {
>> };
>> }
>>
>> /**
>> * @generated
>> */
>> protected Command getCreateCompleteIncomingAggregateUnitLink_4004Command(
>> CreateRelationshipRequest req) {
>> EObject sourceEObject = req.getSource();
>> EObject targetEObject = req.getTarget();
>> if (false == sourceEObject instanceof AggregatedUnit
>> || false == targetEObject instanceof UnitOfWork) {
>> return UnexecutableCommand.INSTANCE;
>> }
>> AggregatedUnit source = (AggregatedUnit) sourceEObject;
>> UnitOfWork target = (UnitOfWork) targetEObject;
>> OrganisationModel container = (OrganisationModel)
>> getRelationshipContainer(
>> source, OrganisationPackage.eINSTANCE.getOrganisationModel(),
>> req.getElementType());
>> if (container == null) {
>> return UnexecutableCommand.INSTANCE;
>> }
>> if (!OrganisationBaseItemSemanticEditPolicy.LinkConstraints
>> .canCreateAggregateUnitLink_4004(container, source, target)) {
>> return UnexecutableCommand.INSTANCE;
>> }
>> if (req.getContainmentFeature() == null) {
>> req.setContainmentFeature(OrganisationPackage.eINSTANCE
>> .getOrganisationModel_Links());
>> }
>> return getMSLWrapper(new AggregateUnitLinkTypeLinkCreateCommand(req,
>> container, source, target));
>> }
>>
>> /**
>> * @generated
>> */
>> protected Command getCreateCompleteIncomingSuperiorLink_4005Command(
>> CreateRelationshipRequest req) {
>> EObject sourceEObject = req.getSource();
>> EObject targetEObject = req.getTarget();
>> if (false == sourceEObject instanceof ISuperiorLinkSource
>> || false == targetEObject instanceof UnitOfWork) {
>> return UnexecutableCommand.INSTANCE;
>> }
>> ISuperiorLinkSource source = (ISuperiorLinkSource) sourceEObject;
>> UnitOfWork target = (UnitOfWork) targetEObject;
>> OrganisationModel container = (OrganisationModel)
>> getRelationshipContainer(
>> source, OrganisationPackage.eINSTANCE.getOrganisationModel(),
>> req.getElementType());
>> if (container == null) {
>> return UnexecutableCommand.INSTANCE;
>> }
>> if (!OrganisationBaseItemSemanticEditPolicy.LinkConstraints
>> .canCreateSuperiorLink_4005(container, source, target)) {
>> return UnexecutableCommand.INSTANCE;
>> }
>> if (req.getContainmentFeature() == null) {
>> req.setContainmentFeature(OrganisationPackage.eINSTANCE
>> .getOrganisationModel_Links());
>> }
>> return getMSLWrapper(new SuperiorLinkTypeLinkCreateCommand(req,
>> container, source, target));
>> }
>>
>> /**
>> * Returns command to reorient EClass based link. New link target or
>> source
>> * should be the domain model element associated with this node.
>> *
>> * @generated
>> */
>> protected Command getReorientRelationshipCommand(
>> ReorientRelationshipRequest req) {
>> switch (getVisualID(req)) {
>> case InteractionLinkEditPart.VISUAL_ID:
>> return getMSLWrapper(new InteractionLinkReorientCommand(req));
>> case AggregateUnitLinkEditPart.VISUAL_ID:
>> return getMSLWrapper(new AggregateUnitLinkReorientCommand(req));
>> case SuperiorLinkEditPart.VISUAL_ID:
>> return getMSLWrapper(new SuperiorLinkReorientCommand(req));
>> }
>> return super.getReorientRelationshipCommand(req);
>> }
>>
>> }
>>
>
>
Re: Question (Yes/No) for Delete elements [message #160895 is a reply to message #160493] Fri, 16 November 2007 13:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jan.herriger.gmx.de

My fault. Not everything I said is true...

Actually, SemanticEditPolicy *does* show a confirmation dialog when an
element is about to be destroyed.

The dialog doesn't show up after selecting "delete from model" in the
popup menu, because DestroyRequest#isConfirmationRequired is always (?)
set to false. This makes sence, because the user explicitly sais "delete
this element from model" and you don't want to annoy users with
unnecessary dialogs. On the other hand, you might as well take up the
position, that users never really know what they are doing ;-)

As a workaround, I've overridden SemanticEditPolicy#shouldProceed inside
xxxBaseItemSemanticEditPolicy:

protected boolean shouldProceed(DestroyRequest destroyRequest) {
IPreferenceStore store = (IPreferenceStore)
((IGraphicalEditPart)getHost())
.getDiagramPreferencesHint().getPreferenceStore();
//check preferences whether to prompt or not
boolean toggle = store.getBoolean(
IPreferenceConstants.PREF_PROMPT_ON_DEL_FROM_MODEL);
((DestroyRequest) destroyRequest).setConfirm(toggle);
return super.shouldProceed(destroyRequest);
}

One problem remains. If a node has some connections attached, a
confirmation dialog will be opened for every single connection.

Regards
Jan

arvinder birdi schrieb:
> I have this problem with a nested node. When it is a top level node, Destroy
> element is not called on a selection. GMF 2.0
>
>
> "arvinder birdi" <arvinderbirdi@sbcglobal.net> wrote in message
> news:fhb6gg$shp$1@build.eclipse.org...
>> Somehow this has a nasty side effect for me.
>> getDestroyElementCommand() is called when I do a simple select and it
>> brings up the yes/no dialog!
>> It is not able to delete.
>>
>> When I do a delete, the dialog shows up and then I'm able to delete.
>>
>> I am using europa eclipse with java 1.6.0.3. Windows 2003.
>>
>>
>> "Jan Herriger" <jan.herriger@gmx.de> wrote in message
>> news:fh4dmn$3hf$1@build.eclipse.org...
>>> attached wrong file...
>>>
>>
>> ------------------------------------------------------------ --------------------
>>
>>
>>> package org.memo.orgml.organisation.diagram.edit.policies;
>>>
>>> import java.util.ArrayList;
>>> import java.util.Collection;
>>> import java.util.Collections;
>>> import java.util.Iterator;
>>>
>>> import org.eclipse.emf.ecore.EAnnotation;
>>> import org.eclipse.emf.ecore.EObject;
>>> import org.eclipse.gef.EditPart;
>>> import org.eclipse.gef.commands.Command;
>>> import org.eclipse.gef.commands.CompoundCommand;
>>> import org.eclipse.gef.commands.UnexecutableCommand;
>>> import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditP art;
>>> import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
>>> import
>>> org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceCo nstants;
>>> import
>>> org.eclipse.gmf.runtime.diagram.ui.requests.EditCommandReque stWrapper;
>>> import
>>> org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElemen tCommand;
>>> import
>>> org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelatio nshipRequest;
>>> import
>>> org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElemen tRequest;
>>> import
>>> org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelat ionshipRequest;
>>> import org.eclipse.gmf.runtime.notation.Edge;
>>> import org.eclipse.gmf.runtime.notation.View;
>>> import org.eclipse.jface.dialogs.IDialogConstants;
>>> import org.eclipse.jface.dialogs.MessageDialogWithToggle;
>>> import org.eclipse.jface.preference.IPreferenceStore;
>>> import org.eclipse.swt.widgets.Display;
>>> import org.memo.orgml.organisation.AggregatedUnit;
>>> import org.memo.orgml.organisation.ISuperiorLinkSource;
>>> import org.memo.orgml.organisation.OrganisationModel;
>>> import org.memo.orgml.organisation.OrganisationPackage;
>>> import org.memo.orgml.organisation.UnitOfWork;
>>> import
>>> org.memo.orgml.organisation.diagram.edit.commands.AggregateU nitLinkReorientCommand;
>>> import
>>> org.memo.orgml.organisation.diagram.edit.commands.AggregateU nitLinkTypeLinkCreateCommand;
>>> import
>>> org.memo.orgml.organisation.diagram.edit.commands.Interactio nLinkReorientCommand;
>>> import
>>> org.memo.orgml.organisation.diagram.edit.commands.Interactio nLinkTypeLinkCreateCommand;
>>> import
>>> org.memo.orgml.organisation.diagram.edit.commands.SuperiorLi nkReorientCommand;
>>> import
>>> org.memo.orgml.organisation.diagram.edit.commands.SuperiorLi nkTypeLinkCreateCommand;
>>> import
>>> org.memo.orgml.organisation.diagram.edit.parts.AggregateUnit LinkEditPart;
>>> import
>>> org.memo.orgml.organisation.diagram.edit.parts.AggregatedUni tEditPart;
>>> import
>>> org.memo.orgml.organisation.diagram.edit.parts.InteractionLi nkEditPart;
>>> import
>>> org.memo.orgml.organisation.diagram.edit.parts.SuperiorLinkE ditPart;
>>> import
>>> org.memo.orgml.organisation.diagram.part.OrganisationDiagram EditorPlugin;
>>> import
>>> org.memo.orgml.organisation.diagram.providers.OrganisationEl ementTypes;
>>>
>>> /**
>>> * @generated
>>> */
>>> public class AggregatedUnitItemSemanticEditPolicy extends
>>> OrganisationBaseItemSemanticEditPolicy {
>>>
>>> /**
>>> * @generated NOT
>>> */
>>> protected Command getDestroyElementCommand(DestroyElementRequest req) {
>>>
>>> IPreferenceStore store = (IPreferenceStore) ((IGraphicalEditPart)
>>> getHost())
>>> .getDiagramPreferencesHint().getPreferenceStore();
>>>
>>> //check preferences whether to prompt or not
>>> boolean toggle =
>>> store.getBoolean(IPreferenceConstants.PREF_PROMPT_ON_DEL_FRO M_MODEL);
>>> if (toggle)
>>> {
>>> final String DELETE_FROM_MODEL_DLG_TITLE =
>>> DiagramUIMessages.PromptingDeleteFromModelAction_DeleteFromM odelDialog_Title;
>>>
>>> final String DELETE_FROM_MODEL_DLG_MESSAGE =
>>> DiagramUIMessages.PromptingDeleteFromModelAction_DeleteFromM odelDialog_Message;
>>>
>>> final String DELETE_FROM_MODEL_DLG_TOGGLE_LABEL =
>>> DiagramUIMessages.MessageDialogWithToggle_DoNotPromptAgainTo ggle_label;
>>>
>>> MessageDialogWithToggle dialog = MessageDialogWithToggle
>>> .openYesNoQuestion(Display.getCurrent().getActiveShell(),
>>> DELETE_FROM_MODEL_DLG_TITLE , DELETE_FROM_MODEL_DLG_MESSAGE,
>>> DELETE_FROM_MODEL_DLG_TOGGLE_LABEL, false,
>>> store,
>>> IPreferenceConstants.PREF_PROMPT_ON_DEL_FROM_MODEL);
>>>
>>> //save user decision for future prompts
>>> store.setValue(IPreferenceConstants.PREF_PROMPT_ON_DEL_FROM_ MODEL,
>>> !dialog.getToggleState());
>>> OrganisationDiagramEditorPlugin.getInstance().savePluginPref erences();
>>>
>>> if (dialog.getReturnCode() != IDialogConstants.YES_ID)
>>> return UnexecutableCommand.INSTANCE;
>>> }
>>>
>>> CompoundCommand cc = new CompoundCommand();
>>> Collection allEdges = new ArrayList();
>>> View view = (View) getHost().getModel();
>>> allEdges.addAll(view.getSourceEdges());
>>> allEdges.addAll(view.getTargetEdges());
>>> for (Iterator it = allEdges.iterator(); it.hasNext();) {
>>> Edge nextEdge = (Edge) it.next();
>>> EditPart nextEditPart = (EditPart) getHost().getViewer()
>>> .getEditPartRegistry().get(nextEdge);
>>> EditCommandRequestWrapper editCommandRequest = new
>>> EditCommandRequestWrapper(
>>> new DestroyElementRequest(
>>> ((AggregatedUnitEditPart) getHost())
>>> .getEditingDomain(), req
>>> .isConfirmationRequired()),
>>> Collections.EMPTY_MAP);
>>> cc.add(nextEditPart.getCommand(editCommandRequest));
>>> }
>>> cc.add(getMSLWrapper(new DestroyElementCommand(req) {
>>>
>>> protected EObject getElementToDestroy() {
>>> View view = (View) getHost().getModel();
>>> EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
>>> if (annotation != null) {
>>> return view;
>>> }
>>> return super.getElementToDestroy();
>>> }
>>>
>>> }));
>>> return cc;
>>> }
>>>
>>> /**
>>> * @generated
>>> */
>>> protected Command getCreateRelationshipCommand(CreateRelationshipRequest
>>> req) {
>>> if (OrganisationElementTypes.InteractionLink_4002 == req
>>> .getElementType()) {
>>> return req.getTarget() == null ?
>>> getCreateStartOutgoingInteractionLink_4002Command(req)
>>> : getCreateCompleteIncomingInteractionLink_4002Command(req);
>>> }
>>> if (OrganisationElementTypes.AggregateUnitLink_4004 == req
>>> .getElementType()) {
>>> return req.getTarget() == null ?
>>> getCreateStartOutgoingAggregateUnitLink_4004Command(req)
>>> : getCreateCompleteIncomingAggregateUnitLink_4004Command(req);
>>> }
>>> if (OrganisationElementTypes.SuperiorLink_4005 == req.getElementType()) {
>>> return req.getTarget() == null ? null
>>> : getCreateCompleteIncomingSuperiorLink_4005Command(req);
>>> }
>>> return super.getCreateRelationshipCommand(req);
>>> }
>>>
>>> /**
>>> * @generated
>>> */
>>> protected Command getCreateStartOutgoingInteractionLink_4002Command(
>>> CreateRelationshipRequest req) {
>>> EObject sourceEObject = req.getSource();
>>> if (false == sourceEObject instanceof UnitOfWork) {
>>> return UnexecutableCommand.INSTANCE;
>>> }
>>> UnitOfWork source = (UnitOfWork) sourceEObject;
>>> OrganisationModel container = (OrganisationModel)
>>> getRelationshipContainer(
>>> source, OrganisationPackage.eINSTANCE.getOrganisationModel(),
>>> req.getElementType());
>>> if (container == null) {
>>> return UnexecutableCommand.INSTANCE;
>>> }
>>> if (!OrganisationBaseItemSemanticEditPolicy.LinkConstraints
>>> .canCreateInteractionLink_4002(container, source, null)) {
>>> return UnexecutableCommand.INSTANCE;
>>> }
>>> return new Command() {
>>> };
>>> }
>>>
>>> /**
>>> * @generated
>>> */
>>> protected Command getCreateCompleteIncomingInteractionLink_4002Command(
>>> CreateRelationshipRequest req) {
>>> EObject sourceEObject = req.getSource();
>>> EObject targetEObject = req.getTarget();
>>> if (false == sourceEObject instanceof UnitOfWork
>>> || false == targetEObject instanceof UnitOfWork) {
>>> return UnexecutableCommand.INSTANCE;
>>> }
>>> UnitOfWork source = (UnitOfWork) sourceEObject;
>>> UnitOfWork target = (UnitOfWork) targetEObject;
>>> OrganisationModel container = (OrganisationModel)
>>> getRelationshipContainer(
>>> source, OrganisationPackage.eINSTANCE.getOrganisationModel(),
>>> req.getElementType());
>>> if (container == null) {
>>> return UnexecutableCommand.INSTANCE;
>>> }
>>> if (!OrganisationBaseItemSemanticEditPolicy.LinkConstraints
>>> .canCreateInteractionLink_4002(container, source, target)) {
>>> return UnexecutableCommand.INSTANCE;
>>> }
>>> if (req.getContainmentFeature() == null) {
>>> req.setContainmentFeature(OrganisationPackage.eINSTANCE
>>> .getOrganisationModel_Links());
>>> }
>>> return getMSLWrapper(new InteractionLinkTypeLinkCreateCommand(req,
>>> container, source, target));
>>> }
>>>
>>> /**
>>> * @generated
>>> */
>>> protected Command getCreateStartOutgoingAggregateUnitLink_4004Command(
>>> CreateRelationshipRequest req) {
>>> EObject sourceEObject = req.getSource();
>>> if (false == sourceEObject instanceof AggregatedUnit) {
>>> return UnexecutableCommand.INSTANCE;
>>> }
>>> AggregatedUnit source = (AggregatedUnit) sourceEObject;
>>> OrganisationModel container = (OrganisationModel)
>>> getRelationshipContainer(
>>> source, OrganisationPackage.eINSTANCE.getOrganisationModel(),
>>> req.getElementType());
>>> if (container == null) {
>>> return UnexecutableCommand.INSTANCE;
>>> }
>>> if (!OrganisationBaseItemSemanticEditPolicy.LinkConstraints
>>> .canCreateAggregateUnitLink_4004(container, source, null)) {
>>> return UnexecutableCommand.INSTANCE;
>>> }
>>> return new Command() {
>>> };
>>> }
>>>
>>> /**
>>> * @generated
>>> */
>>> protected Command getCreateCompleteIncomingAggregateUnitLink_4004Command(
>>> CreateRelationshipRequest req) {
>>> EObject sourceEObject = req.getSource();
>>> EObject targetEObject = req.getTarget();
>>> if (false == sourceEObject instanceof AggregatedUnit
>>> || false == targetEObject instanceof UnitOfWork) {
>>> return UnexecutableCommand.INSTANCE;
>>> }
>>> AggregatedUnit source = (AggregatedUnit) sourceEObject;
>>> UnitOfWork target = (UnitOfWork) targetEObject;
>>> OrganisationModel container = (OrganisationModel)
>>> getRelationshipContainer(
>>> source, OrganisationPackage.eINSTANCE.getOrganisationModel(),
>>> req.getElementType());
>>> if (container == null) {
>>> return UnexecutableCommand.INSTANCE;
>>> }
>>> if (!OrganisationBaseItemSemanticEditPolicy.LinkConstraints
>>> .canCreateAggregateUnitLink_4004(container, source, target)) {
>>> return UnexecutableCommand.INSTANCE;
>>> }
>>> if (req.getContainmentFeature() == null) {
>>> req.setContainmentFeature(OrganisationPackage.eINSTANCE
>>> .getOrganisationModel_Links());
>>> }
>>> return getMSLWrapper(new AggregateUnitLinkTypeLinkCreateCommand(req,
>>> container, source, target));
>>> }
>>>
>>> /**
>>> * @generated
>>> */
>>> protected Command getCreateCompleteIncomingSuperiorLink_4005Command(
>>> CreateRelationshipRequest req) {
>>> EObject sourceEObject = req.getSource();
>>> EObject targetEObject = req.getTarget();
>>> if (false == sourceEObject instanceof ISuperiorLinkSource
>>> || false == targetEObject instanceof UnitOfWork) {
>>> return UnexecutableCommand.INSTANCE;
>>> }
>>> ISuperiorLinkSource source = (ISuperiorLinkSource) sourceEObject;
>>> UnitOfWork target = (UnitOfWork) targetEObject;
>>> OrganisationModel container = (OrganisationModel)
>>> getRelationshipContainer(
>>> source, OrganisationPackage.eINSTANCE.getOrganisationModel(),
>>> req.getElementType());
>>> if (container == null) {
>>> return UnexecutableCommand.INSTANCE;
>>> }
>>> if (!OrganisationBaseItemSemanticEditPolicy.LinkConstraints
>>> .canCreateSuperiorLink_4005(container, source, target)) {
>>> return UnexecutableCommand.INSTANCE;
>>> }
>>> if (req.getContainmentFeature() == null) {
>>> req.setContainmentFeature(OrganisationPackage.eINSTANCE
>>> .getOrganisationModel_Links());
>>> }
>>> return getMSLWrapper(new SuperiorLinkTypeLinkCreateCommand(req,
>>> container, source, target));
>>> }
>>>
>>> /**
>>> * Returns command to reorient EClass based link. New link target or
>>> source
>>> * should be the domain model element associated with this node.
>>> *
>>> * @generated
>>> */
>>> protected Command getReorientRelationshipCommand(
>>> ReorientRelationshipRequest req) {
>>> switch (getVisualID(req)) {
>>> case InteractionLinkEditPart.VISUAL_ID:
>>> return getMSLWrapper(new InteractionLinkReorientCommand(req));
>>> case AggregateUnitLinkEditPart.VISUAL_ID:
>>> return getMSLWrapper(new AggregateUnitLinkReorientCommand(req));
>>> case SuperiorLinkEditPart.VISUAL_ID:
>>> return getMSLWrapper(new SuperiorLinkReorientCommand(req));
>>> }
>>> return super.getReorientRelationshipCommand(req);
>>> }
>>>
>>> }
>>>
>>
>
>
Re: Question (Yes/No) for Delete elements [message #160958 is a reply to message #160895] Fri, 16 November 2007 14:21 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jan.herriger.gmx.de

Well, I think it would be better to return
PromptingDeleteFromModelAction inside generated
xxxContributionItemProvider (wich unfortunately is internal) and
register 'deleteFromModelAction' against this provider.

plugin.xml:

<extension point="...contributionItemProviders">
<?gmfgen generated="false"?>
<contributionItemProvider
class="x.x.x.diagram.providers.xxxContributionItemProvider" >
<Priority name="Low">
</Priority>
....
<popupContribution
class="org.eclipse.gmf.runtime.diagram.ui.
providers.DiagramContextMenuProvider">
<popupStructuredContributionCriteria
objectClass="x.x.x.diagram.edit.parts.xxxEditPart">
</popupStructuredContributionCriteria>
<popupAction
id="deleteFromModelAction"
path="/editGroup">
</popupAction>
<popupPredefinedItem
id="deleteFromModelAction"
remove="true">
</popupPredefinedItem>
</popupContribution>
....
</extension>

xxxContributionItemProvider.java:

protected IAction createAction(String actionId,
IWorkbenchPartDescriptor partDescriptor) {

if (actionId.equals(PrintPreviewAction.ID)) {
return new RenderedPrintPreviewAction(
new EnhancedPrintActionHelper());
} else if (actionId.equals(ActionIds.ACTION_DELETE_FROM_MODEL)) {
IWorkbenchPage workbenchPage = partDescriptor.getPartPage();
return new PromptingDeleteFromModelAction(workbenchPage);
}
....
}



Enough confusion for today... I'm out :-)
Re: Question (Yes/No) for Delete elements [message #161023 is a reply to message #160958] Fri, 16 November 2007 22:23 Go to previous message
Eclipse UserFriend
Originally posted by: arvinder.birdi.ca.com

I eventually came to the same conclusion.
Only PromptingDeleteAction.createCommand knows about all the selected edit
parts.

In my current implementation a Y/N box is displayed for every selected
EParts. If you select N for any of the EParts the whole group is undone.
You dont have individual Y/N control yet you are asked for every
individual EPart!

-Arvinder
Previous Topic:Setting of Edge bendpoints does not reflect visually
Next Topic:Stable Version 2.0.1?
Goto Forum:
  


Current Time: Thu Apr 25 04:52:27 GMT 2024

Powered by FUDForum. Page generated in 0.04467 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top