Search in sources :

Example 66 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration 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 67 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration 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 68 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.

the class ElementsFactory method getConsoleConfig.

public ConsoleConfiguration getConsoleConfig() {
    final KnownConfigurations knownConfigurations = KnownConfigurations.getInstance();
    ConsoleConfiguration consoleConfig = knownConfigurations.find(consoleConfigName);
    return consoleConfig;
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) KnownConfigurations(org.hibernate.console.KnownConfigurations)

Example 69 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.

the class OrmDiagram method getConfig.

protected IConfiguration getConfig(StringBuilder error) {
    if (error != null) {
        error.delete(0, error.length());
    }
    final ConsoleConfiguration consoleConfig = getConsoleConfig();
    if (consoleConfig != null) {
        if (!consoleConfig.hasConfiguration()) {
            try {
                consoleConfig.build();
                consoleConfig.buildMappings();
            } catch (Exception he) {
                // here just ignore this
                if (error != null) {
                    error.append(consoleConfigName);
                    // $NON-NLS-1$
                    error.append(": ");
                    error.append(he.getMessage());
                    if (error.length() == 0) {
                        error.append(he.getCause());
                    }
                }
            }
        }
        return consoleConfig.getConfiguration();
    }
    if (error != null && consoleConfigName != null && consoleConfigName.length() > 0) {
        error.append(consoleConfigName);
        // $NON-NLS-1$
        error.append(": ");
        error.append(DiagramViewerMessages.Diagram_incorrect_state);
    }
    return null;
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) WorkbenchException(org.eclipse.ui.WorkbenchException) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 70 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.

the class OrmDiagram method loadFromProperties.

@Override
protected void loadFromProperties(Properties properties) {
    super.loadFromProperties(properties);
    // $NON-NLS-1$ //$NON-NLS-2$
    consoleConfigName = getPrValue(properties, "consoleConfig_name", "");
    @SuppressWarnings("unused") ConsoleConfiguration consoleConfig = getConsoleConfig();
    labelProvider.setConsoleConfigName(consoleConfigName);
    // $NON-NLS-1$
    int size = getPrValue(properties, "entityNames_size", 0);
    roots.clear();
    entityNames.clear();
    for (int i = 0; i < size; i++) {
        roots.add(null);
        // $NON-NLS-1$ //$NON-NLS-2$
        entityNames.add(getPrValue(properties, "entityNames_" + Integer.toString(i), ""));
    }
    // $NON-NLS-1$
    rulersVisibility = getPrValue(properties, "rulersVisibility", false);
    // $NON-NLS-1$
    snapToGeometry = getPrValue(properties, "snapToGeometry", false);
    // $NON-NLS-1$
    gridEnabled = getPrValue(properties, "gridEnabled", false);
    // $NON-NLS-1$
    zoom = getPrValue(properties, "zoom", 1.0);
    // $NON-NLS-1$
    deepIntoSort = getPrValue(properties, "deepIntoSort", false);
    // $NON-NLS-1$
    flagManhattanConnectionRouter = getPrValue(properties, "flagManhattanConnectionRouter", true);
    // $NON-NLS-1$
    connectionsVisibilityAssociation = getPrValue(properties, "connectionsVisibilityAssociation", true);
    // $NON-NLS-1$
    connectionsVisibilityClassMapping = getPrValue(properties, "connectionsVisibilityClassMapping", true);
    // $NON-NLS-1$
    connectionsVisibilityForeignKeyConstraint = getPrValue(properties, "connectionsVisibilityForeignKeyConstraint", true);
    // $NON-NLS-1$
    connectionsVisibilityPropertyMapping = getPrValue(properties, "connectionsVisibilityPropertyMapping", true);
    refreshRootsFromNames();
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) Point(org.eclipse.draw2d.geometry.Point)

Aggregations

ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)107 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)19 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)17 CoreException (org.eclipse.core.runtime.CoreException)16 PartInitException (org.eclipse.ui.PartInitException)13 IProperty (org.jboss.tools.hibernate.runtime.spi.IProperty)12 KnownConfigurations (org.hibernate.console.KnownConfigurations)11 JavaModelException (org.eclipse.jdt.core.JavaModelException)10 TreePath (org.eclipse.jface.viewers.TreePath)10 Test (org.junit.Test)10 File (java.io.File)9 ArrayList (java.util.ArrayList)9 FileNotFoundException (java.io.FileNotFoundException)8 IPath (org.eclipse.core.runtime.IPath)8 TreeSelection (org.eclipse.jface.viewers.TreeSelection)8 IService (org.jboss.tools.hibernate.runtime.spi.IService)8 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)7 IEditorPart (org.eclipse.ui.IEditorPart)7 ConsoleConfigurationPreferences (org.hibernate.console.preferences.ConsoleConfigurationPreferences)7 GridLayout (org.eclipse.swt.layout.GridLayout)6