use of org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart in project statecharts by Yakindu.
the class AdjustIdentityAnchorCommand method computeNewAnchor.
private PrecisionPoint computeNewAnchor(PrecisionPoint currentAnchorPoint, EditPart editPart) {
double scale = getScale(editPart);
IFigure figure = ((IGraphicalEditPart) editPart).getFigure();
Rectangle bounds = figure.getBounds();
if (figure instanceof HandleBounds) {
bounds = ((HandleBounds) figure).getHandleBounds();
}
Point currentRelativePoint = getAnchorRelativePoint(currentAnchorPoint, bounds);
if (futureSize != null && delta != null) {
// and delta are used instead of the request data.
return new PrecisionPoint(((double) (currentRelativePoint.x - delta.x)) / futureSize.width, ((double) (currentRelativePoint.y - delta.y)) / futureSize.height);
} else {
double logicalWidthDelta = request.getSizeDelta().width / scale;
double logicalHeightDelta = request.getSizeDelta().height / scale;
int direction = request.getResizeDirection();
double newRelativeX = computeNewXRelativeLocation(direction, currentRelativePoint, logicalWidthDelta);
double newRelativeY = computeNewYRelativeLocation(direction, currentRelativePoint, logicalHeightDelta);
return new PrecisionPoint(newRelativeX / (bounds.width() + logicalWidthDelta), newRelativeY / (bounds.height() + logicalHeightDelta));
}
}
use of org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart in project statecharts by Yakindu.
the class CreationWizard method openDiagram.
protected boolean openDiagram(Resource diagram) throws PartInitException {
String path = diagram.getURI().toPlatformString(true);
IResource workspaceResource = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(path));
if (workspaceResource instanceof IFile) {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
StatechartDiagramEditor editor = (StatechartDiagramEditor) page.openEditor(new FileEditorInput((IFile) workspaceResource), getEditorID());
if (editor != null) {
List<EObject> allNotationElements = EcoreUtil2.eAllContentsAsList(diagram);
for (EObject eObject : allNotationElements) {
if (eObject instanceof View && ((View) eObject).getType().equals(SemanticHints.STATE_NAME)) {
IGraphicalEditPart editPart = EditPartUtils.findEditPartForSemanticElement(editor.getDiagramGraphicalViewer().getRootEditPart(), ((View) eObject).getElement());
editPart = editPart.getChildBySemanticHint(SemanticHints.STATE_NAME);
if (editPart != null) {
final DirectEditRequest request = new DirectEditRequest();
request.setDirectEditFeature(BasePackage.Literals.NAMED_ELEMENT__NAME);
editPart.performRequest(request);
break;
}
}
}
return false;
}
}
return false;
}
use of org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart in project statecharts by Yakindu.
the class SheetLabelProvider method getImage.
public Image getImage(Object element) {
element = unwrap(element);
if (element instanceof IGraphicalEditPart) {
EObject semanticElement = ((IGraphicalEditPart) element).resolveSemanticElement();
if (semanticElement == null) {
// Default images
View view = ((IGraphicalEditPart) element).getNotationView();
String viewType = view.getType();
if (ViewType.NOTE.equals(viewType)) {
return SharedImages.get(SharedImages.IMG_NOTE);
} else if (ViewType.TEXT.equals(viewType)) {
return SharedImages.get(SharedImages.IMG_TEXT);
}
} else {
// custom images
IElementType elementType = ElementTypeRegistry.getInstance().getElementType(semanticElement);
Image image = DiagramActivator.getDefault().getImageRegistry().get(elementType.getIconURL().toString());
if (image == null) {
ImageDescriptor desc = ImageDescriptor.createFromURL(elementType.getIconURL());
DiagramActivator.getDefault().getImageRegistry().put(elementType.getIconURL().toString(), desc.createImage());
return DiagramActivator.getDefault().getImageRegistry().get(elementType.getIconURL().toString());
}
return image;
}
}
return null;
}
use of org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart in project statecharts by Yakindu.
the class SheetLabelProvider method getText.
public String getText(Object element) {
element = unwrap(element);
if (element instanceof IGraphicalEditPart) {
EObject semanticElement = ((IGraphicalEditPart) element).resolveSemanticElement();
if (semanticElement == null) {
View view = ((IGraphicalEditPart) element).getNotationView();
return view.getType();
} else {
IElementType elementType = ElementTypeRegistry.getInstance().getElementType(semanticElement);
StringBuilder builder = new StringBuilder();
builder.append(elementType.getDisplayName());
if (semanticElement instanceof NamedElement && ((NamedElement) semanticElement).getName() != null) {
builder.append(' ');
builder.append(((NamedElement) semanticElement).getName());
}
return builder.toString();
}
}
return null;
}
use of org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart in project statecharts by Yakindu.
the class StatechartMarkerNavigationProvider method doGotoMarker.
@Override
@SuppressWarnings("rawtypes")
protected void doGotoMarker(IMarker marker) {
String elementId = marker.getAttribute(SCTMarkerType.SEMANTIC_ELEMENT_ID, null);
if (elementId == null || !(getEditor() instanceof DiagramEditor)) {
return;
}
DiagramEditor editor = (DiagramEditor) getEditor();
EObject targetElement = (EObject) editor.getDiagram().eResource().getEObject(elementId);
if (targetElement == null) {
return;
}
View view = DiagramPartitioningUtil.findNotationView(targetElement);
if (view == null) {
return;
}
Diagram element = DiagramPartitioningUtil.getDiagramContaining(view.getElement());
editor = (DiagramEditor) DiagramPartitioningUtil.openEditor(element);
Map editPartRegistry = editor.getDiagramGraphicalViewer().getEditPartRegistry();
EditPart targetEditPart = (EditPart) editPartRegistry.get(view);
if (targetEditPart != null) {
if (!targetEditPart.isSelectable())
return;
DiagramPartitioningUtil.selectElementsInDiagram(editor, Arrays.asList(new EditPart[] { targetEditPart }));
}
try {
if (marker.isSubtypeOf(SCTMarkerType.SUPERTYPE)) {
final DirectEditRequest request = new DirectEditRequest();
request.setDirectEditFeature(getEditFeature(targetElement, marker));
List<IGraphicalEditPart> allEditParts = getEditParts(editPartRegistry, EcoreUtil2.eAllContentsAsList(view));
for (IGraphicalEditPart editPart : allEditParts) {
if (editPart instanceof IXtextAwareEditPart || (editPart instanceof TextAwareLabelEditPart) && ((TextAwareLabelEditPart) editPart).getFeature().equals(request.getDirectEditFeature())) {
editPart.performRequest(request);
break;
}
}
}
} catch (CoreException e) {
e.printStackTrace();
}
}
Aggregations