Java Code Examples for org.eclipse.gmf.runtime.notation.Diagram#getElement()

The following examples show how to use org.eclipse.gmf.runtime.notation.Diagram#getElement() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DiagramPartitioningUtil.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Opens a subdiagram for a given {@link Diagram}
 */
public static IEditorPart openEditor(Diagram diagramToOpen) {
	IFile file = WorkspaceSynchronizer.getFile(diagramToOpen.eResource());
	try {
		IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName());
		final IWorkbenchPage wbPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
		if (diagramToOpen.getElement() instanceof Statechart) {
			return wbPage.openEditor(new FileEditorInput(file), desc.getId());
		} else if (diagramToOpen.getElement() instanceof State) {
			return wbPage.openEditor(new DiagramEditorInput(diagramToOpen), desc.getId());
		}
	} catch (PartInitException e) {
		e.printStackTrace();
	}
	return null;
}
 
Example 2
Source File: BatchValidationOperation.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
public IStatus getResult() {
    final MultiStatus result = new MultiStatus(ValidationCommonPlugin.PLUGIN_ID, IStatus.OK, "", null);
    fileProcessed.clear();
    for (final Diagram d : diagramsToDiagramEditPart.keySet()) {
        final EObject element = d.getElement();
        if (element != null) {
            final IFile target = d.eResource() != null ? WorkspaceSynchronizer.getFile(d.eResource()) : null;
            if (target != null && !fileProcessed.contains(target)) {
                try {
                    buildMultiStatus(target, result);
                } catch (final CoreException e) {
                    BonitaStudioLog.error(e);
                }
            }
        }
    }
    return result;
}
 
Example 3
Source File: DiagramForElementRunnable.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void run() {
    final TreeIterator<EObject> allContents = resource.getAllContents();
    EObject elementToFind = null;
    final Set<Diagram> diagrams = new HashSet<Diagram>();
    while (allContents.hasNext()) {
        final EObject eObject = allContents.next();
        if (EcoreUtil.equals(eObject, element)) {
            elementToFind = eObject;
        }
        if (eObject instanceof Diagram) {
            diagrams.add((Diagram) eObject);
        }
    }
    if (elementToFind == null) {
        return;
    }
    for (final Diagram diagram : diagrams) {
        final EObject diagramElement = diagram.getElement();
        if (diagramElement != null && diagramElement.equals(elementToFind)) {
            result = diagram;
            break;
        }
    }
}
 
Example 4
Source File: DiagramPartitioningUtil.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public static List<Diagram> getDiagramContainerHierachy(Diagram diagram) {
	Assert.isNotNull(diagram);
	List<Diagram> result = new ArrayList<Diagram>();
	result.add(diagram);
	while (diagram.getElement() instanceof State) {
		diagram = DiagramPartitioningUtil.getDiagramContaining((State) diagram.getElement());
		result.add(diagram);
	}
	Collections.reverse(result);
	return result;
}
 
Example 5
Source File: DiagramPartitioningUtil.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public static List<Diagram> getSubDiagramHierachy(Diagram diagram) {
	Assert.isNotNull(diagram);
	List<Diagram> result = new ArrayList<Diagram>();
	result.add(diagram);
	while (diagram.getElement() instanceof State) {
		diagram = DiagramPartitioningUtil.getSubDiagram((CompositeElement) diagram.getElement());
		result.add(diagram);
	}
	Collections.reverse(result);
	return result;
}
 
Example 6
Source File: DiagramPartitioningBreadcrumbViewer.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected TreeViewer createDiagramViewer(final Composite composite, Diagram diagram) {
	TreeViewer viewer = new TreeViewer(composite);
	viewer.setLabelProvider(new AdapterFactoryLabelProvider(new SGraphItemProviderAdapterFactory()));
	viewer.setContentProvider(new AdapterFactoryContentProvider(new BreadcrumbItemProviderAdapterFactory()));
	EObject element = diagram.getElement();
	viewer.setInput(element);
	viewer.addSelectionChangedListener(this);
	return viewer;
}
 
Example 7
Source File: DiagramPartitioningEditor.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected void initializeTitle(SubmachineEditorInput input) {
	Diagram diagram = input.getDiagram();
	EObject element = diagram.getElement();
	AdapterFactoryLabelProvider labelProvider = new AdapterFactoryLabelProvider(
			new SGraphItemProviderAdapterFactory());
	setTitleImage(labelProvider.getImage(element));
	initializeTitle(diagram);
	setPartName(((SubmachineEditorInput) input).getContext() + " : " + labelProvider.getText(element));

}
 
Example 8
Source File: DiagramPartitioningEditor.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected void initializeTitle(IDiagramEditorInput input) {
	Diagram diagram = input.getDiagram();
	EObject element = diagram.getElement();
	AdapterFactoryLabelProvider labelProvider = new AdapterFactoryLabelProvider(
			new SGraphItemProviderAdapterFactory());
	setTitleImage(labelProvider.getImage(element));
	setPartName(labelProvider.getText(element));
}
 
Example 9
Source File: DiagramPartitioningEditor.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected void initializeTitle(Diagram diagram) {
	EObject element = diagram.getElement();
	AdapterFactoryLabelProvider labelProvider = new AdapterFactoryLabelProvider(
			new SGraphItemProviderAdapterFactory());
	setTitleImage(labelProvider.getImage(element));
	setPartName(labelProvider.getText(element));
}
 
Example 10
Source File: DiagramPartitioningEditor.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public void updateLabel(ViewerLabel label, TreePath elementPath) {
	Diagram lastSegment = (Diagram) elementPath.getLastSegment();
	NamedElement element = (NamedElement) lastSegment.getElement();
	AdapterFactoryLabelProvider provider = new AdapterFactoryLabelProvider(
			new SGraphItemProviderAdapterFactory());
	label.setText(provider.getText(element));
	if (element instanceof Statechart)
		label.setImage(StatechartImages.LOGO.image());
	else
		label.setImage(provider.getImage(element));

}
 
Example 11
Source File: OffscreenEditPartFactory.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public DiagramEditPart createOffscreenDiagramEditPart(final Diagram d) {
    final EObject element = d.getElement();
    if (element != null) {
        final OffscreenDiagramEditPartRunnable runnable = new OffscreenDiagramEditPartRunnable(d, factory);
        if (inUIThread()) {
            runnable.run();
        } else {
            runInUI(runnable);
        }

        toDispose.add(runnable.getDisposable());
        return runnable.getDiagramEditPart();
    }
    return null;
}
 
Example 12
Source File: DiagramManager.java    From txtUML with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Gets the {@link Element} that is the container of the diagram
 * @param diagram - The Diagram
 * @return Container of the diagram
 */
public Element getDiagramContainer(Diagram diagram){
	return (Element) diagram.getElement();
}