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);
}
}
}
Aggregations