Search in sources :

Example 21 with ChangeBoundsRequest

use of org.eclipse.gef.requests.ChangeBoundsRequest in project statecharts by Yakindu.

the class TreeLayoutEditPolicy method showLayoutTargetFeedback.

@Override
protected void showLayoutTargetFeedback(Request request) {
    if (request instanceof ChangeBoundsRequest) {
        final ChangeBoundsRequest changeBoundsRequest = (ChangeBoundsRequest) request;
        if (!changeBoundsRequest.getEditParts().isEmpty() && !(changeBoundsRequest.getEditParts().get(0) instanceof LabelEditPart)) {
            final IGraphicalEditPart editPart = (IGraphicalEditPart) changeBoundsRequest.getEditParts().get(0);
            final List<IGraphicalEditPart> siblingList = TreeLayoutUtil.getSiblings(editPart);
            if (!siblingList.isEmpty()) {
                final int newTreePosition = TreeLayoutUtil.getNewTreeNodePosition(changeBoundsRequest.getLocation(), TreeLayoutUtil.getSiblings(editPart));
                Point point;
                if (newTreePosition == 0) {
                    // top end
                    point = getFeedBackFigurePoint(editPart.getFigure(), siblingList, 0, 0);
                } else if (newTreePosition == siblingList.size()) {
                    // Bottom end
                    point = getFeedBackFigurePoint(editPart.getFigure(), siblingList, siblingList.size(), siblingList.size());
                } else {
                    // Between siblings
                    point = getFeedBackFigurePoint(editPart.getFigure(), siblingList, newTreePosition - 1, newTreePosition);
                }
                final Rectangle bounds = getFeedbackFigureBounds();
                siblingList.get(0).getFigure().translateToAbsolute(bounds);
                bounds.setLocation(point);
                getFeedbackFigure().setBounds(bounds);
                getFeedbackFigure().translateToRelative(getFeedbackFigure().getBounds());
                getFeedbackLayer().add(getFeedbackFigure());
                getFeedbackLayer().repaint();
            }
        }
    }
}
Also used : ChangeBoundsRequest(org.eclipse.gef.requests.ChangeBoundsRequest) IGraphicalEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) LabelEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart) Rectangle(org.eclipse.draw2d.geometry.Rectangle) RoundedRectangle(org.eclipse.draw2d.RoundedRectangle) Point(org.eclipse.draw2d.geometry.Point) TreeLayoutConstraint(org.yakindu.base.gmf.runtime.treelayout.TreeLayoutConstraint) Point(org.eclipse.draw2d.geometry.Point)

Example 22 with ChangeBoundsRequest

use of org.eclipse.gef.requests.ChangeBoundsRequest in project whole by wholeplatform.

the class TextTransferDropTargetListener method getCommand.

@Override
protected Command getCommand() {
    String text = (String) getCurrentEvent().data;
    Shell shell = getViewer().getControl().getShell();
    IImportAsModelDialog dialog = factory.createImplicitElementImportAsModelDialog(shell, "Drop As", false);
    if (!dialog.show())
        return null;
    IPersistenceKit persistenceKit = dialog.getPersistenceKit();
    EntityDescriptor<?> stage = dialog.getStage();
    try {
        IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
        bm.wDefValue("parseFragments", true);
        IEntity entity = persistenceKit.readModel(new StringPersistenceProvider(text, bm));
        // FIXME workaround for selections with multiple entities
        if (EntityUtils.isTuple(entity))
            bm.wDef("syntheticRoot", entity);
        boolean hasSyntheticRoot = bm.wIsSet("syntheticRoot");
        IEntityIterator<IEntity> iterator;
        boolean needsCompositeTarget = false;
        if (hasSyntheticRoot) {
            IEntity syntheticRoot = bm.wGet("syntheticRoot");
            iterator = IteratorFactory.childIterator();
            iterator.reset(syntheticRoot);
            needsCompositeTarget = syntheticRoot.wSize() > 1;
        } else {
            iterator = IteratorFactory.selfIterator();
            iterator.reset(entity);
        }
        List<IEntityPart> editParts = new ArrayList<IEntityPart>();
        while (iterator.hasNext()) {
            IEntity stageEntity = EntityUtils.clone(iterator.next());
            stageEntity = ClipboardUtils.conditionalStageAdd(getTargetEditPart(), stage, stageEntity, needsCompositeTarget);
            editParts.add(ClipboardUtils.createEditPart(getViewer().getEditPartFactory(), stageEntity));
        }
        ChangeBoundsRequest request = (ChangeBoundsRequest) getTargetRequest();
        request.setEditParts(editParts);
        return super.getCommand();
    } catch (Exception e) {
        return null;
    }
}
Also used : StringPersistenceProvider(org.whole.lang.codebase.StringPersistenceProvider) IEntity(org.whole.lang.model.IEntity) ArrayList(java.util.ArrayList) ChangeBoundsRequest(org.eclipse.gef.requests.ChangeBoundsRequest) Shell(org.eclipse.swt.widgets.Shell) IImportAsModelDialog(org.whole.lang.ui.dialogs.IImportAsModelDialog) IBindingManager(org.whole.lang.bindings.IBindingManager) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit) IEntityPart(org.whole.lang.ui.editparts.IEntityPart)

Example 23 with ChangeBoundsRequest

use of org.eclipse.gef.requests.ChangeBoundsRequest in project whole by wholeplatform.

the class FileTransferDropTargetListener method getCommand.

@Override
protected Command getCommand() {
    String[] filePaths = (String[]) getCurrentEvent().data;
    List<EditPart> editParts = new ArrayList<EditPart>();
    Shell shell = getViewer().getControl().getShell();
    IImportAsModelDialog dialog = factory.createElementListImportAsModelDialog(shell, "DnD Import", false);
    String[] fileNames = new String[filePaths.length];
    for (int i = 0; i < fileNames.length; i++) fileNames[i] = filePaths[i].substring(filePaths[i].lastIndexOf(File.separatorChar) + 1);
    dialog.setSelection(fileNames);
    if (!dialog.show())
        return null;
    IPersistenceKit persistenceKit = dialog.getPersistenceKit();
    EntityDescriptor<?> stage = dialog.getStage();
    boolean needsCompositeTarget = filePaths.length > 1;
    for (String filePath : filePaths) {
        try {
            IWorkspace workspace = ResourcesPlugin.getWorkspace();
            File file = new File(filePath);
            IFile[] files = workspace.getRoot().findFilesForLocationURI(file.toURI());
            IPersistenceProvider persistenceProvider = (files.length == 1) ? new IFilePersistenceProvider(files[0]) : new FilePersistenceProvider(file);
            IEntity entity = persistenceKit.readModel(persistenceProvider);
            entity = ClipboardUtils.conditionalStageAdd(getTargetEditPart(), stage, entity, needsCompositeTarget);
            editParts.add(ClipboardUtils.createEditPart(getViewer().getEditPartFactory(), entity));
        } catch (Exception e) {
        // fail silently
        }
    }
    if (!editParts.isEmpty()) {
        ChangeBoundsRequest request = (ChangeBoundsRequest) getTargetRequest();
        request.setEditParts(editParts);
    } else
        return null;
    return super.getCommand();
}
Also used : IFile(org.eclipse.core.resources.IFile) IEntity(org.whole.lang.model.IEntity) EditPart(org.eclipse.gef.EditPart) ArrayList(java.util.ArrayList) ChangeBoundsRequest(org.eclipse.gef.requests.ChangeBoundsRequest) Shell(org.eclipse.swt.widgets.Shell) IImportAsModelDialog(org.whole.lang.ui.dialogs.IImportAsModelDialog) FilePersistenceProvider(org.whole.lang.codebase.FilePersistenceProvider) IFilePersistenceProvider(org.whole.lang.codebase.IFilePersistenceProvider) IWorkspace(org.eclipse.core.resources.IWorkspace) IFilePersistenceProvider(org.whole.lang.codebase.IFilePersistenceProvider) IPersistenceProvider(org.whole.lang.codebase.IPersistenceProvider) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 24 with ChangeBoundsRequest

use of org.eclipse.gef.requests.ChangeBoundsRequest in project statecharts by Yakindu.

the class EnlargeContainerEditPolicy method getCommand.

@SuppressWarnings("unchecked")
@Override
public Command getCommand(Request request) {
    if (!RequestConstants.REQ_RESIZE.equals(request.getType()) && !RequestConstants.REQ_MOVE.equals(request.getType())) {
        return null;
    }
    if (request instanceof SetPreferredSizeRequest) {
        showSourceFeedback(request);
    }
    ChangeBoundsRequest cbr = (ChangeBoundsRequest) request;
    CompoundCommand result = new CompoundCommand();
    // Update Bounds of the container hierachy
    for (IGraphicalEditPart currentContainer : containerHierachy) {
        IFigure figure = currentContainer.getFigure();
        SetBoundsCommand boundsCommand = new SetBoundsCommand(getHost().getEditingDomain(), DiagramUIMessages.SetLocationCommand_Label_Resize, new EObjectAdapter(currentContainer.getNotationView()), figure.getBounds());
        result.add(new ICommandProxy(boundsCommand));
        // Update child bounds of elements that stand in the way...
        List<IGraphicalEditPart> children = currentContainer.getParent().getChildren();
        for (IGraphicalEditPart childPart : children) {
            if (cbr.getEditParts().contains(childPart))
                continue;
            IFigure childFigure = childPart.getFigure();
            if (childPart == currentContainer)
                continue;
            SetBoundsCommand childBoundsCommand = new SetBoundsCommand(getHost().getEditingDomain(), DiagramUIMessages.SetLocationCommand_Label_Resize, new EObjectAdapter(childPart.getNotationView()), childFigure.getBounds());
            result.add(new ICommandProxy(childBoundsCommand));
        }
    }
    return result;
}
Also used : ChangeBoundsRequest(org.eclipse.gef.requests.ChangeBoundsRequest) IGraphicalEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) ICommandProxy(org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy) SetBoundsCommand(org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand) EObjectAdapter(org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

ChangeBoundsRequest (org.eclipse.gef.requests.ChangeBoundsRequest)24 Point (org.eclipse.draw2d.geometry.Point)8 EditPart (org.eclipse.gef.EditPart)7 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)7 List (java.util.List)6 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)6 ArrayList (java.util.ArrayList)5 Command (org.eclipse.gef.commands.Command)4 PointList (org.eclipse.draw2d.geometry.PointList)3 PrecisionRectangle (org.eclipse.draw2d.geometry.PrecisionRectangle)3 IFigure (org.eclipse.draw2d.IFigure)2 Rectangle (org.eclipse.draw2d.geometry.Rectangle)2 ICommandProxy (org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy)2 IGraphicalEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart)2 DropTargetEvent (org.eclipse.swt.dnd.DropTargetEvent)2 Shell (org.eclipse.swt.widgets.Shell)2 IPersistenceKit (org.whole.lang.codebase.IPersistenceKit)2 IEntity (org.whole.lang.model.IEntity)2 IImportAsModelDialog (org.whole.lang.ui.dialogs.IImportAsModelDialog)2 CreateNestedArchimateConnectionsWithDialogCommand (com.archimatetool.editor.diagram.commands.CreateNestedArchimateConnectionsWithDialogCommand)1