Search in sources :

Example 1 with Shape

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

the class ExpandableShapeTreeEditPart method refreshVisuals.

/**
 * Refreshes the visual properties of the TreeItem for this part.
 */
protected void refreshVisuals() {
    if (getWidget() instanceof Tree) {
        return;
    }
    Shape model = (Shape) getModel();
    Object element = model.getOrmElement();
    setWidgetImage(getExpandeableShape().getOrmDiagram().getLabelProvider().getImage(element));
    setWidgetText(getExpandeableShape().getOrmDiagram().getLabelProvider().getText(element));
}
Also used : Shape(org.jboss.tools.hibernate.ui.diagram.editors.model.Shape) ExpandableShape(org.jboss.tools.hibernate.ui.diagram.editors.model.ExpandableShape) Tree(org.eclipse.swt.widgets.Tree)

Example 2 with Shape

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

the class OpenMappingAction 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 IProperty && ((IProperty) selection).getPersistentClass().isInstanceOfSpecialRootClass()) {
            IProperty compositSel = ((IProperty) selection);
            IProperty parentProperty = ((IPersistentClass) compositSel.getPersistentClass()).getProperty();
            try {
                editorPart = org.hibernate.eclipse.console.actions.OpenMappingAction.run(consoleConfig, compositSel, parentProperty);
            } catch (CoreException e) {
                HibernateConsolePlugin.getDefault().logErrorMessage(DiagramViewerMessages.OpenMappingAction_canot_find_or_open_mapping_file, e);
            } catch (FileNotFoundException e) {
                HibernateConsolePlugin.getDefault().logErrorMessage(DiagramViewerMessages.OpenMappingAction_canot_find_or_open_mapping_file, e);
            }
            continue;
        }
        if (selection instanceof IPersistentClass && ((IPersistentClass) selection).isInstanceOfSpecialRootClass()) {
            selection = ((IPersistentClass) selection).getProperty();
        }
        Shape shapeParent = null;
        Object selectionParent = null;
        if (selection instanceof IColumn) {
            shapeParent = (Shape) shape.getParent();
            selectionParent = shapeParent.getOrmElement();
        }
        try {
            editorPart = org.hibernate.eclipse.console.actions.OpenMappingAction.run(consoleConfig, selection, selectionParent);
        } catch (CoreException e) {
            HibernateConsolePlugin.getDefault().logErrorMessage(DiagramViewerMessages.OpenMappingAction_open_mapping_file, e);
        } catch (FileNotFoundException e) {
            HibernateConsolePlugin.getDefault().logErrorMessage(DiagramViewerMessages.OpenMappingAction_open_mapping_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) 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) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn)

Example 3 with Shape

use of org.jboss.tools.hibernate.ui.diagram.editors.model.Shape 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)

Example 4 with Shape

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

the class DiagramViewer method getSelectedElements.

public Set<Shape> getSelectedElements() {
    Set<Shape> ret = new HashSet<Shape>();
    List<?> selectedEditParts = getGraphicalViewer().getSelectedEditParts();
    Iterator<?> iterator = selectedEditParts.iterator();
    while (iterator.hasNext()) {
        Object elem = iterator.next();
        if (elem instanceof OrmEditPart) {
            Shape shape = (Shape) ((OrmEditPart) elem).getModel();
            ret.add(shape);
        }
    }
    return ret;
}
Also used : Shape(org.jboss.tools.hibernate.ui.diagram.editors.model.Shape) OrmEditPart(org.jboss.tools.hibernate.ui.diagram.editors.parts.OrmEditPart) HashSet(java.util.HashSet)

Example 5 with Shape

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

the class ShapeTreeEditPart method refreshVisuals.

/**
 * Refreshes the visual properties of the TreeItem for this part.
 */
protected void refreshVisuals() {
    if (getWidget() instanceof Tree) {
        return;
    }
    Shape model = (Shape) getModel();
    Object element = model.getOrmElement();
    setWidgetImage(getShape().getOrmDiagram().getLabelProvider().getImage(element));
    setWidgetText(getShape().getOrmDiagram().getLabelProvider().getText(element));
}
Also used : Shape(org.jboss.tools.hibernate.ui.diagram.editors.model.Shape) Tree(org.eclipse.swt.widgets.Tree)

Aggregations

Shape (org.jboss.tools.hibernate.ui.diagram.editors.model.Shape)6 IColumn (org.jboss.tools.hibernate.runtime.spi.IColumn)3 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)3 IProperty (org.jboss.tools.hibernate.runtime.spi.IProperty)3 FileNotFoundException (java.io.FileNotFoundException)2 CoreException (org.eclipse.core.runtime.CoreException)2 Tree (org.eclipse.swt.widgets.Tree)2 IEditorPart (org.eclipse.ui.IEditorPart)2 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)2 ITable (org.jboss.tools.hibernate.runtime.spi.ITable)2 DiagramViewer (org.jboss.tools.hibernate.ui.diagram.editors.DiagramViewer)2 ExpandableShape (org.jboss.tools.hibernate.ui.diagram.editors.model.ExpandableShape)2 OrmEditPart (org.jboss.tools.hibernate.ui.diagram.editors.parts.OrmEditPart)2 DiagramEditorInput (org.jboss.tools.hibernate.ui.view.DiagramEditorInput)2 HashSet (java.util.HashSet)1 AbstractTreeEditPart (org.eclipse.gef.editparts.AbstractTreeEditPart)1 IAction (org.eclipse.jface.action.IAction)1 Separator (org.eclipse.jface.action.Separator)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1