Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » DestroyElementRequest
DestroyElementRequest [message #202277] Mon, 18 August 2008 17:24 Go to next message
Toyin is currently offline ToyinFriend
Messages: 35
Registered: July 2009
Member
I'm trying to use the code below to delete an element in my model.
Whenever I delete this element, the element is not completely deleted, a
faded image of that element remains on the screen and the remaining
elements remain static. Is something missing in my code? Please help

DestroyElementRequest request = new DestroyElementRequest
(selectedElement.resolveSemanticElement(), false);
Command destroy = selectedElement.getCommand(new
EditCommandRequestWrapper(request) );
selectedElement.getDiagramEditDomain().getDiagramCommandStac k().execute(cc);
destroy.execute();

Thanks

Toyin
Re: DestroyElementRequest [message #202520 is a reply to message #202277] Tue, 19 August 2008 17:44 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Stefan.Kuhn.[REMOVE]gentleware.com

hi, here my 2 cents:

1) what is cc and why are 2 commands executed?
> selectedElement.getDiagramEditDomain().getDiagramCommandStac k().execute(cc);

> destroy.execute();
2) you shouldn't call destroy.execute() but execute it on the command stack

-stefan

Toyin Fakorede schrieb:
> I'm trying to use the code below to delete an element in my model.
> Whenever I delete this element, the element is not completely deleted, a
> faded image of that element remains on the screen and the remaining
> elements remain static. Is something missing in my code? Please help
>
> DestroyElementRequest request = new DestroyElementRequest
> (selectedElement.resolveSemanticElement(), false);
> Command destroy = selectedElement.getCommand(new
> EditCommandRequestWrapper(request) );
> selectedElement.getDiagramEditDomain().getDiagramCommandStac k().execute(cc);
>
> destroy.execute();
>
> Thanks
>
> Toyin
>


--
Stefan Kuhn, Gentleware AG
http://www.gentleware.com
Re: DestroyElementRequest [message #202845 is a reply to message #202520] Thu, 21 August 2008 11:01 Go to previous messageGo to next message
Toyin is currently offline ToyinFriend
Messages: 35
Registered: July 2009
Member
Hi Stefan,
This is my code. I should make more sense. This code deletes the element
but makes the remaining elements on the workspace static. Pls help.

package org.eclipse.scrapbuuk.diagram.popup.actions;
import java.util.List;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartViewer;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CompoundCommand;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
import
org.eclipse.gmf.runtime.diagram.ui.commands.DeferredCreateCo nnectionViewAndElementCommand;
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
import
org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnection ViewAndElementRequest;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewReques t;
import
org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewReques tFactory;
import
org.eclipse.gmf.runtime.diagram.ui.requests.EditCommandReque stWrapper;
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants ;
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
import
org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElemen tRequest;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import Scrapbook.diagram.edit.parts.ScrapItemEditPart;
import Scrapbook.diagram.edit.parts.ScrapBookDiagramEditPart;
import Scrapbook.diagram.edit.parts.FolderEditPart;
import Scrapbook.diagram.edit.parts.SolidConnectionEditPart;
import Scrapbook.diagram.providers.ScrapBuukElementTypes;

public class CreateShape implements IObjectActionDelegate {

public final static String ID = "org.eclipse.scrapbook.custom.newAction";

private ScrapItemEditPart selectedElement;


public void run(IAction action) {
//CompoundCommand cc = new CompoundCommand("Create another shape");
// combine all of these commands together
CompoundCommand cc = new CompoundCommand("A compound command");


// Create the new shape.
CreateViewRequest shapeRequest =
CreateViewRequestFactory.getCreateShapeRequest(ScrapBuukElem entTypes.Folder_1001,
selectedElement.getDiagramPreferencesHint());
Point p =
selectedElement.getFigure().getBounds().getTopRight().getCop y();
selectedElement.getFigure().translateToAbsolute(p);
int edgeCount =
selectedElement.getNotationView().getSourceEdges().size();

int offset = (edgeCount * 0);
shapeRequest.setLocation(p.translate(-45, offset));

ScrapBookDiagramEditPart scrapbookmodelEditPart =
(ScrapBookDiagramEditPart) selectedElement.getParent();
Command createShapeCmd = scrapbookmodelEditPart.getCommand(shapeRequest);

cc.add(createShapeCmd);

// try this code to delete element
DestroyElementRequest request2 = new DestroyElementRequest
(selectedElement.resolveSemanticElement(), true);
Command destroy = selectedElement.getCommand(new
EditCommandRequestWrapper(request2) );

cc.add(destroy);
// you can then execute all the commands
selectedElement.getDiagramEditDomain().getDiagramCommandStac k().execute(cc);

}
public void selectionChanged(IAction action, ISelection selection) {
selectedElement = null;
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection)
selection;
if (structuredSelection.getFirstElement() instanceof ScrapItemEditPart)
{
selectedElement = (ScrapItemEditPart)
structuredSelection.getFirstElement();
}
}
}

public void setActivePart(IAction action, IWorkbenchPart targetPart) {
}


}
Re: DestroyElementRequest [message #202854 is a reply to message #202845] Thu, 21 August 2008 11:34 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Stefan.Kuhn.[REMOVE]gentleware.com

hi toyin,

what do you mean by "makes the remaining elements on the workspace
static." ?

-stefan

Toyin Fakorede schrieb:
> Hi Stefan,
> This is my code. I should make more sense. This code deletes the element
> but makes the remaining elements on the workspace static. Pls help.
>
> package org.eclipse.scrapbuuk.diagram.popup.actions;
> import java.util.List;
>
> import org.eclipse.core.runtime.IAdaptable;
> import org.eclipse.draw2d.geometry.Point;
> import org.eclipse.emf.ecore.EObject;
> import org.eclipse.emf.transaction.TransactionalEditingDomain;
> import org.eclipse.gef.EditPart;
> import org.eclipse.gef.EditPartViewer;
> import org.eclipse.gef.Request;
> import org.eclipse.gef.commands.Command;
> import org.eclipse.gef.commands.CompoundCommand;
> import org.eclipse.gmf.runtime.common.core.command.ICommand;
> import
> org.eclipse.gmf.runtime.diagram.ui.commands.DeferredCreateCo nnectionViewAndElementCommand;
>
> import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
> import
> org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnection ViewAndElementRequest;
>
> import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewReques t;
> import
> org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewReques tFactory;
> import
> org.eclipse.gmf.runtime.diagram.ui.requests.EditCommandReque stWrapper;
> import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants ;
> import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
> import org.eclipse.gmf.runtime.emf.type.core.IElementType;
> import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
> import
> org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElemen tRequest;
> import org.eclipse.gmf.runtime.notation.View;
> import org.eclipse.jface.action.IAction;
> import org.eclipse.jface.viewers.ISelection;
> import org.eclipse.jface.viewers.IStructuredSelection;
> import org.eclipse.jface.viewers.StructuredSelection;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.ui.IObjectActionDelegate;
> import org.eclipse.ui.IWorkbenchPart;
> import Scrapbook.diagram.edit.parts.ScrapItemEditPart;
> import Scrapbook.diagram.edit.parts.ScrapBookDiagramEditPart;
> import Scrapbook.diagram.edit.parts.FolderEditPart;
> import Scrapbook.diagram.edit.parts.SolidConnectionEditPart;
> import Scrapbook.diagram.providers.ScrapBuukElementTypes;
>
> public class CreateShape implements IObjectActionDelegate {
>
> public final static String ID =
> "org.eclipse.scrapbook.custom.newAction";
>
> private ScrapItemEditPart selectedElement;
>
>
> public void run(IAction action) {
> //CompoundCommand cc = new CompoundCommand("Create another shape");
> // combine all of these commands together
> CompoundCommand cc = new CompoundCommand("A compound command");
>
>
> // Create the new shape.
> CreateViewRequest shapeRequest =
> CreateViewRequestFactory.getCreateShapeRequest(ScrapBuukElem entTypes.Folder_1001,
> selectedElement.getDiagramPreferencesHint());
> Point p =
> selectedElement.getFigure().getBounds().getTopRight().getCop y();
> selectedElement.getFigure().translateToAbsolute(p);
> int edgeCount =
> selectedElement.getNotationView().getSourceEdges().size();
>
> int offset = (edgeCount * 0);
> shapeRequest.setLocation(p.translate(-45, offset));
>
> ScrapBookDiagramEditPart scrapbookmodelEditPart =
> (ScrapBookDiagramEditPart) selectedElement.getParent();
> Command createShapeCmd =
> scrapbookmodelEditPart.getCommand(shapeRequest);
>
> cc.add(createShapeCmd);
>
> // try this code to delete element
> DestroyElementRequest request2 = new DestroyElementRequest
> (selectedElement.resolveSemanticElement(), true);
> Command destroy = selectedElement.getCommand(new
> EditCommandRequestWrapper(request2) );
>
> cc.add(destroy);
> // you can then execute all the commands
> selectedElement.getDiagramEditDomain().getDiagramCommandStac k().execute(cc);
>
>
> }
> public void selectionChanged(IAction action, ISelection selection) {
> selectedElement = null;
> if (selection instanceof IStructuredSelection) {
> IStructuredSelection structuredSelection =
> (IStructuredSelection) selection;
> if (structuredSelection.getFirstElement() instanceof
> ScrapItemEditPart) {
> selectedElement = (ScrapItemEditPart)
> structuredSelection.getFirstElement();
> }
> }
> }
>
> public void setActivePart(IAction action, IWorkbenchPart targetPart) {
> }
>
>
> }
>
>
>


--
Stefan Kuhn, Gentleware AG
http://www.gentleware.com
Re: DestroyElementRequest [message #202862 is a reply to message #202854] Thu, 21 August 2008 12:06 Go to previous messageGo to next message
Toyin is currently offline ToyinFriend
Messages: 35
Registered: July 2009
Member
Hi Stefan,
This is the whole idea. I've got elements A, B, C, D in my model on the
workspace, I want to be able to replace element A with element C.
This is my problem: When I select element A and hit the replace button,
element C appears but element A becomes faded (not properly deleted) and
the remaining elements B, C and D becomes unmovable (static) on the
workspace. I cant even create any new elements.

I think the problem with my code is the right use of the
DestroyElementRequest. Any suggestions

Thanks
Toyin
Re: DestroyElementRequest [message #203111 is a reply to message #202862] Fri, 22 August 2008 12:25 Go to previous message
Eclipse UserFriend
Originally posted by: Stefan.Kuhn.[REMOVE]gentleware.com

this sounds like the editor gets into an unexpected state. Check the
error view of the runtime-eclipse for exceptions ... or catch all
exceptions with the debugger before an replace

-stefan

Toyin Fakorede schrieb:
> Hi Stefan,
> This is the whole idea. I've got elements A, B, C, D in my model on the
> workspace, I want to be able to replace element A with element C. This
> is my problem: When I select element A and hit the replace button,
> element C appears but element A becomes faded (not properly deleted) and
> the remaining elements B, C and D becomes unmovable (static) on the
> workspace. I cant even create any new elements.
>
> I think the problem with my code is the right use of the
> DestroyElementRequest. Any suggestions
>
> Thanks
> Toyin
>


--
Stefan Kuhn, Gentleware AG
http://www.gentleware.com
Previous Topic:Styles of note attachment not shown after refresh/reopen
Next Topic:GMF Editor should use additional notation model
Goto Forum:
  


Current Time: Fri Apr 26 19:36:05 GMT 2024

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

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

Back to the top