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();
}
}
}
}
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;
}
}
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();
}
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;
}
Aggregations