Search in sources :

Example 1 with Connection

use of org.jboss.tools.hibernate.ui.diagram.editors.model.Connection in project jbosstools-hibernate by jbosstools.

the class OpenSourceAction method run.

public void run() {
    DiagramEditorInput objectEditorInput = (DiagramEditorInput) ((DiagramViewer) getWorkbenchPart()).getEditorInput();
    ConsoleConfiguration consoleConfig = objectEditorInput.getConsoleConfig();
    DiagramViewer part = (DiagramViewer) getWorkbenchPart();
    Set<Shape> selectedElements = part.getSelectedElements();
    IEditorPart editorPart = null;
    Iterator<Shape> iterator = selectedElements.iterator();
    // open only first editor - no sense to open all of them
    while (iterator.hasNext() && editorPart == null) {
        Shape shape = iterator.next();
        Object selection = shape.getOrmElement();
        if (selection instanceof IColumn || selection instanceof ITable) {
            Iterator<Connection> targetConnections = shape.getTargetConnections().iterator();
            while (targetConnections.hasNext()) {
                Connection connection = targetConnections.next();
                Shape sh1 = connection.getSource();
                Shape sh2 = connection.getTarget();
                if (shape == sh1 && sh2 != null) {
                    shape = sh2;
                    break;
                } else if (shape == sh2 && sh1 != null) {
                    shape = sh1;
                    break;
                }
            }
            selection = shape.getOrmElement();
        }
        IPersistentClass rootClass = null;
        if (selection instanceof IPersistentClass) {
            rootClass = (IPersistentClass) selection;
        } else if (selection instanceof IProperty) {
            rootClass = ((IProperty) selection).getPersistentClass();
        } else {
            continue;
        }
        // HibernateUtils.getPersistentClassName(rootClass);
        String fullyQualifiedName = rootClass.getClassName();
        /*if (fullyQualifiedName.indexOf("$") > 0) {
				fullyQualifiedName = fullyQualifiedName.substring(0, fullyQualifiedName.indexOf("$"));
			}*/
        try {
            editorPart = org.hibernate.eclipse.console.actions.OpenSourceAction.run(consoleConfig, selection, fullyQualifiedName);
        } catch (CoreException e) {
            HibernateConsolePlugin.getDefault().logErrorMessage(DiagramViewerMessages.OpenSourceAction_canot_open_source_file, e);
        } catch (FileNotFoundException e) {
            HibernateConsolePlugin.getDefault().logErrorMessage(DiagramViewerMessages.OpenSourceAction_canot_find_source_file, e);
        }
    }
}
Also used : DiagramEditorInput(org.jboss.tools.hibernate.ui.view.DiagramEditorInput) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) Shape(org.jboss.tools.hibernate.ui.diagram.editors.model.Shape) Connection(org.jboss.tools.hibernate.ui.diagram.editors.model.Connection) FileNotFoundException(java.io.FileNotFoundException) IEditorPart(org.eclipse.ui.IEditorPart) DiagramViewer(org.jboss.tools.hibernate.ui.diagram.editors.DiagramViewer) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) CoreException(org.eclipse.core.runtime.CoreException) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) ITable(org.jboss.tools.hibernate.runtime.spi.ITable)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)1 CoreException (org.eclipse.core.runtime.CoreException)1 IEditorPart (org.eclipse.ui.IEditorPart)1 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)1 IColumn (org.jboss.tools.hibernate.runtime.spi.IColumn)1 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)1 IProperty (org.jboss.tools.hibernate.runtime.spi.IProperty)1 ITable (org.jboss.tools.hibernate.runtime.spi.ITable)1 DiagramViewer (org.jboss.tools.hibernate.ui.diagram.editors.DiagramViewer)1 Connection (org.jboss.tools.hibernate.ui.diagram.editors.model.Connection)1 Shape (org.jboss.tools.hibernate.ui.diagram.editors.model.Shape)1 DiagramEditorInput (org.jboss.tools.hibernate.ui.view.DiagramEditorInput)1