Search in sources :

Example 1 with ObjectPluginAction

use of org.eclipse.ui.internal.ObjectPluginAction in project jbosstools-hibernate by jbosstools.

the class OpenDiagramActionDelegate method run.

public void run(IAction action) {
    ObjectPluginAction objectPluginAction = (ObjectPluginAction) action;
    Map<ConsoleConfiguration, Set<IPersistentClass>> mapCC_PCs = new HashMap<ConsoleConfiguration, Set<IPersistentClass>>();
    TreePath[] paths = ((TreeSelection) objectPluginAction.getSelection()).getPaths();
    for (int i = 0; i < paths.length; i++) {
        final Object firstSegment = paths[i].getFirstSegment();
        if (!(firstSegment instanceof ConsoleConfiguration)) {
            continue;
        }
        final ConsoleConfiguration consoleConfig = (ConsoleConfiguration) (firstSegment);
        Set<IPersistentClass> setPC = mapCC_PCs.get(consoleConfig);
        if (null == setPC) {
            setPC = new HashSet<IPersistentClass>();
            mapCC_PCs.put(consoleConfig, setPC);
        }
        Object last_el = paths[i].getLastSegment();
        if (last_el instanceof IPersistentClass) {
            IPersistentClass persClass = (IPersistentClass) last_el;
            setPC.add(persClass);
        } else if (last_el instanceof IConfiguration) {
            IConfiguration config = (IConfiguration) last_el;
            Iterator<IPersistentClass> it = config.getClassMappings();
            while (it.hasNext()) {
                setPC.add(it.next());
            }
        } else if (last_el instanceof ConsoleConfiguration) {
            IConfiguration config = consoleConfig.getConfiguration();
            if (config == null) {
                try {
                    consoleConfig.build();
                } catch (Exception he) {
                    HibernateConsolePlugin.getDefault().showError(HibernateConsolePlugin.getShell(), DiagramViewerMessages.OpenDiagramActionDelegate_could_not_load_configuration + ' ' + consoleConfig.getName(), he);
                }
                if (consoleConfig.hasConfiguration()) {
                    consoleConfig.buildMappings();
                }
                config = consoleConfig.getConfiguration();
            }
            if (config != null) {
                Iterator<IPersistentClass> it = config.getClassMappings();
                while (it.hasNext()) {
                    setPC.add(it.next());
                }
            }
        }
    }
    for (Iterator<ConsoleConfiguration> it = mapCC_PCs.keySet().iterator(); it.hasNext(); ) {
        ConsoleConfiguration consoleConfiguration = it.next();
        Set<IPersistentClass> setPC = mapCC_PCs.get(consoleConfiguration);
        try {
            openEditor(setPC, consoleConfiguration);
        } catch (PartInitException e) {
            // $NON-NLS-1$
            HibernateConsolePlugin.getDefault().logErrorMessage("Can't open mapping view.", e);
        }
    }
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) PartInitException(org.eclipse.ui.PartInitException) ObjectPluginAction(org.eclipse.ui.internal.ObjectPluginAction) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) Iterator(java.util.Iterator) PartInitException(org.eclipse.ui.PartInitException) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration)

Aggregations

HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Set (java.util.Set)1 TreePath (org.eclipse.jface.viewers.TreePath)1 TreeSelection (org.eclipse.jface.viewers.TreeSelection)1 PartInitException (org.eclipse.ui.PartInitException)1 ObjectPluginAction (org.eclipse.ui.internal.ObjectPluginAction)1 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)1 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)1 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)1