public void run() { // TODO support uml files to be opened Shell shell = Display.getCurrent().getActiveShell(); Collection<IFile> files = new HashSet<IFile>(); for (IWorkbenchWindow w : PlatformUI.getWorkbench().getWorkbenchWindows()) { for (IWorkbenchPage p : w.getPages()) { for (IEditorReference e : p.getEditorReferences()) { try { if (e.getEditorInput() instanceof IFileEditorInput) { IFileEditorInput editorInput = (IFileEditorInput) e.getEditorInput(); if (editorInput.getFile().getParent().findMember("opaeum.properties") != null) { OpaeumEclipseContext ctx = OpaeumEclipseContext.findOrCreateContextFor(editorInput.getFile().getParent()); for (IResource r : editorInput.getFile().getParent().members()) { if (r.getName().endsWith(".uml")) { OpenUmlFile ouf = ctx.getOpenUmlFileFor((IFile) r); if (ouf != null && canReverseInto(ouf)) { files.add((IFile) r); } } } } } } catch (PartInitException e1) { e1.printStackTrace(); } catch (CoreException e2) { e2.printStackTrace(); } } } } ElementListSelectionDialog dialog = new ElementListSelectionDialog( shell, new LabelProvider() { @Override public String getText(Object element) { IFile file = (IFile) element; return file.getProject().getName() + "/" + file.getProjectRelativePath(); } }); dialog.setElements(files.toArray()); dialog.setTitle("Models in Workspace"); dialog.setMessage("Select the targetmodel:"); dialog.open(); if (dialog.getFirstResult() != null) { IFile file = (IFile) dialog.getFirstResult(); OpaeumEclipseContext ctx = OpaeumEclipseContext.getContextFor(file.getParent()); if (ctx != null) { final OpenUmlFile ouf = ctx.getOpenUmlFileFor(file); if (ouf != null) { ouf.suspend(); setSelectedEditor(file.getName()); ouf.getEditingDomain().getCommandStack().execute(buildCommand(ouf.getModel())); ouf.resumeAndCatchUp(); } } try { file.getProject().refreshLocal(IResource.DEPTH_INFINITE, null); } catch (CoreException e) { e.printStackTrace(); } } }
protected boolean canReverseInto(OpenUmlFile ouf) { return ouf.getModel() instanceof Model; }