List of usage examples for org.eclipse.jface.dialogs ProgressMonitorDialog close
@Override public boolean close()
ProgressMonitorDialog
implementation of this method only closes the dialog if there are no currently running runnables. From source file:net.sf.eclipsensis.installoptions.actions.PreviewAction.java
License:Open Source License
private void doPreview(final INIFile iniFile, final File file) { final Shell shell = mEditor.getSite().getShell(); BusyIndicator.showWhile(shell.getDisplay(), new Runnable() { public void run() { final ProgressMonitorDialog pmd = new ProgressMonitorDialog(shell) { @Override// w w w .j a va2 s . c om protected void configureShell(Shell shell) { super.configureShell(shell); Rectangle rect = shell.getDisplay().getBounds(); shell.setLocation(rect.x + rect.width + 1, rect.y + rect.height + 1); } @Override protected Rectangle getConstrainedShellBounds(Rectangle preferredSize) { Rectangle rect = shell.getDisplay().getBounds(); return new Rectangle(rect.x + rect.width + 1, rect.y + rect.height + 1, preferredSize.width, preferredSize.height); } }; pmd.open(); try { ModalContext.run(new IRunnableWithProgress() { private File createPreviewFile(File previewFile, INIFile inifile, final NSISLanguage lang) throws IOException { File previewFile2 = previewFile; INIFile inifile2 = inifile; if (previewFile2 == null) { previewFile2 = File.createTempFile("preview", ".ini"); //$NON-NLS-1$ //$NON-NLS-2$ previewFile2.deleteOnExit(); } inifile2 = inifile2.copy(); InstallOptionsDialog dialog = InstallOptionsDialog.loadINIFile(inifile2); DialogSize dialogSize; if (getId().equals(PREVIEW_MUI_ID)) { dialogSize = DialogSizeManager.getDialogSize(cMUIDialogSizeName); } else { dialogSize = DialogSizeManager.getDialogSize(cClassicDialogSizeName); } if (dialogSize == null) { dialogSize = DialogSizeManager.getDefaultDialogSize(); } dialog.setDialogSize(dialogSize); Font font = FontUtility.getFont(lang); for (Iterator<InstallOptionsWidget> iter = dialog.getChildren().iterator(); iter .hasNext();) { InstallOptionsWidget widget = iter.next(); if (widget instanceof InstallOptionsPicture) { final InstallOptionsPicture picture = (InstallOptionsPicture) widget; final Dimension dim = widget.toGraphical(widget.getPosition(), font).getSize(); final Map<Dimension, File> cache; switch (picture.getSWTImageType()) { case SWT.IMAGE_BMP: cache = cBitmapCache; break; case SWT.IMAGE_ICO: cache = cIconCache; break; default: continue; } final File[] imageFile = new File[] { cache.get(dim) }; if (!IOUtility.isValidFile(imageFile[0])) { shell.getDisplay().syncExec(new Runnable() { public void run() { Image widgetImage = picture.getImage(); ImageData data = widgetImage.getImageData(); data.width = dim.width; data.height = dim.height; data.type = picture.getSWTImageType(); Image bitmap = new Image(shell.getDisplay(), data); GC gc = new GC(bitmap); gc.setBackground(shell.getDisplay() .getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); gc.setForeground( shell.getDisplay().getSystemColor(SWT.COLOR_BLACK)); gc.fillRectangle(0, 0, dim.width, dim.height); Rectangle rect = widgetImage.getBounds(); int x, y, width, height; if (rect.width > dim.width) { x = 0; width = dim.width; } else { x = (dim.width - rect.width) / 2; width = rect.width; } if (rect.height > dim.height) { y = 0; height = dim.height; } else { y = (dim.height - rect.height) / 2; height = rect.height; } gc.drawImage(widgetImage, 0, 0, rect.width, rect.height, x, y, width, height); gc.setLineStyle(SWT.LINE_CUSTOM); gc.setLineDash(DashedLineBorder.DASHES); gc.drawRectangle(0, 0, dim.width - 1, dim.height - 1); gc.dispose(); ImageLoader loader = new ImageLoader(); loader.data = new ImageData[] { bitmap.getImageData() }; try { imageFile[0] = File.createTempFile("preview", //$NON-NLS-1$ picture.getFileExtension()); imageFile[0].deleteOnExit(); loader.save(imageFile[0].getAbsolutePath(), picture.getSWTImageType()); cache.put(dim, imageFile[0]); } catch (IOException e) { imageFile[0] = null; InstallOptionsPlugin.getDefault().log(e); cache.remove(dim); } } }); } if (imageFile[0] != null) { picture.setPropertyValue(InstallOptionsModel.PROPERTY_TEXT, imageFile[0].getAbsolutePath()); } } } inifile2 = dialog.updateINIFile(); IOUtility.writeContentToFile(previewFile2, inifile2.toString().getBytes()); return previewFile2; } public void run(IProgressMonitor monitor) { try { monitor.beginTask( InstallOptionsPlugin.getResourceString("previewing.script.task.name"), //$NON-NLS-1$ IProgressMonitor.UNKNOWN); String pref = InstallOptionsPlugin.getDefault().getPreferenceStore() .getString(IInstallOptionsConstants.PREFERENCE_PREVIEW_LANG); NSISLanguage lang; if (pref.equals("")) { //$NON-NLS-1$ lang = NSISLanguageManager.getInstance().getDefaultLanguage(); } else { lang = NSISLanguageManager.getInstance().getLanguage(pref); if (lang == null) { lang = NSISLanguageManager.getInstance().getDefaultLanguage(); InstallOptionsPlugin.getDefault().getPreferenceStore() .setValue(IInstallOptionsConstants.PREFERENCE_PREVIEW_LANG, ""); //$NON-NLS-1$ } } PreviewCacheKey key = new PreviewCacheKey(file, lang); File previewFile = cPreviewCache.get(key); if (previewFile == null || file.lastModified() > previewFile.lastModified()) { previewFile = createPreviewFile(previewFile, iniFile, lang); cPreviewCache.put(key, previewFile); } Map<String, String> symbols = mSettings.getSymbols(); symbols.put("PREVIEW_INI", previewFile.getAbsolutePath()); //$NON-NLS-1$ symbols.put("PREVIEW_LANG", lang.getName()); //$NON-NLS-1$ Locale locale = NSISLanguageManager.getInstance() .getLocaleForLangId(lang.getLangId()); if (getId().equals(PREVIEW_MUI_ID)) { symbols.put("PREVIEW_TITLE", //$NON-NLS-1$ InstallOptionsPlugin.getResourceString(locale, "preview.setup.title")); //$NON-NLS-1$ symbols.put("PREVIEW_SUBTITLE", InstallOptionsPlugin.getResourceString(locale, //$NON-NLS-1$ "preview.setup.subtitle")); //$NON-NLS-1$ } else { symbols.put("PREVIEW_BRANDING", InstallOptionsPlugin.getResourceString(locale, //$NON-NLS-1$ "preview.setup.branding")); //$NON-NLS-1$ } symbols.put("PREVIEW_NAME", //$NON-NLS-1$ InstallOptionsPlugin.getResourceString(locale, "preview.setup.name")); //$NON-NLS-1$ if (EclipseNSISPlugin.getDefault().isWinVista() && NSISPreferences.getInstance() .getNSISVersion().compareTo(INSISVersions.VERSION_2_21) >= 0) { symbols.put("WINDOWS_VISTA", ""); //$NON-NLS-1$ //$NON-NLS-2$ } mSettings.setSymbols(symbols); final File previewScript = getPreviewScript(); long timestamp = System.currentTimeMillis(); MakeNSISResults results = null; results = MakeNSISRunner.compile(previewScript, mSettings, cDummyConsole, new INSISConsoleLineProcessor() { public NSISConsoleLine processText(String text) { return NSISConsoleLine.info(text); } public void reset() { } }); if (results != null) { if (results.getReturnCode() != 0) { List<NSISScriptProblem> errors = results.getProblems(); final String error; if (!Common.isEmptyCollection(errors)) { Iterator<NSISScriptProblem> iter = errors.iterator(); StringBuffer buf = new StringBuffer(iter.next().getText()); while (iter.hasNext()) { buf.append(INSISConstants.LINE_SEPARATOR) .append(iter.next().getText()); } error = buf.toString(); } else { error = InstallOptionsPlugin.getResourceString("preview.compile.error"); //$NON-NLS-1$ } shell.getDisplay().asyncExec(new Runnable() { public void run() { Common.openError(shell, error, InstallOptionsPlugin.getShellImage()); } }); } else { final File outfile = new File(results.getOutputFileName()); if (IOUtility.isValidFile(outfile) && outfile.lastModified() > timestamp) { MakeNSISRunner.testInstaller(outfile.getAbsolutePath(), null, true); } } } } catch (final Exception e) { InstallOptionsPlugin.getDefault().log(e); shell.getDisplay().asyncExec(new Runnable() { public void run() { Common.openError(shell, e.getMessage(), InstallOptionsPlugin.getShellImage()); } }); } finally { monitor.done(); } } }, true, pmd.getProgressMonitor(), shell.getDisplay()); } catch (Exception e) { InstallOptionsPlugin.getDefault().log(e); Common.openError(shell, e.getMessage(), InstallOptionsPlugin.getShellImage()); } finally { pmd.close(); } } }); }
From source file:net.sf.fjep.fatjar.popup.actions.BuildFatJar.java
License:Open Source License
public void runBuildConfiguredFatJar(IJavaProject jproject, Properties props, Set excludes, ArrayList includes) {//w w w .j a v a2 s . c o m // Create a progress bar Shell shell = new Shell(); ProgressMonitorDialog progressmonitordialog = new ProgressMonitorDialog(shell); progressmonitordialog.open(); IProgressMonitor iprogressmonitor = progressmonitordialog.getProgressMonitor(); iprogressmonitor.beginTask("Build Fat jar", PROGRESS_CLEAN + PROGRESS_COLLECT + PROGRESS_PACK + PROGRESS_CLEAN); // Make One-JAR? boolean onejar = new Boolean(props.getProperty(AguiPlugin.ONEJAR_CHECKBOX)).booleanValue(); String expand = props.getProperty(AguiPlugin.ONEJAR_EXPAND); String jarfile = null; try { saveConfig(jproject, props); doCleanFatJar(jproject, iprogressmonitor); doCollectFatJar(jproject, iprogressmonitor, excludes, includes, onejar, expand); jarfile = doPackFatJar(jproject, iprogressmonitor); doCleanFatJar(jproject, iprogressmonitor); try { jproject.getProject().refreshLocal(IResource.DEPTH_ONE, null); } catch (CoreException e) { e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); MessageDialog.openInformation(shell, "Fat Jar Plug-In ERROR", e.getMessage()); } progressmonitordialog.close(); MessageDialog.openInformation(shell, "Fat Jar Plug-In", "built " + jarfile); }
From source file:net.sf.fjep.fatjar.popup.actions.BuildFatJar.java
License:Open Source License
public void doQuickBuildFatJar(IJavaProject jproject) { Properties props = getFatJarProperties(jproject); Set excludes = getExcludes(jproject, props.getProperty("excludes")); ArrayList includes = getIncludes(jproject, props.getProperty("includes")); // Create a progress bar Shell shell = new Shell(); ProgressMonitorDialog progressmonitordialog = new ProgressMonitorDialog(shell); progressmonitordialog.open();/*from w ww.j av a 2 s .c o m*/ IProgressMonitor iprogressmonitor = progressmonitordialog.getProgressMonitor(); iprogressmonitor.beginTask("Quick Build Fat jar", PROGRESS_CLEAN + PROGRESS_COLLECT + PROGRESS_PACK + PROGRESS_CLEAN); // Make One-JAR? boolean onejar = new Boolean(props.getProperty(AguiPlugin.ONEJAR_CHECKBOX)).booleanValue(); String expand = props.getProperty(AguiPlugin.ONEJAR_EXPAND); String jarfile = null; try { // saveConfig(jproject, props); doCleanFatJar(jproject, iprogressmonitor); doCollectFatJar(jproject, iprogressmonitor, excludes, includes, onejar, expand); jarfile = doPackFatJar(jproject, iprogressmonitor); doCleanFatJar(jproject, iprogressmonitor); try { jproject.getProject().refreshLocal(IResource.DEPTH_ONE, null); } catch (CoreException e) { e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); MessageDialog.openInformation(shell, "Fat Jar Plug-In ERROR", e.getMessage()); } progressmonitordialog.close(); MessageDialog.openInformation(shell, "Fat Jar Plug-In", "built " + jarfile); // testExtensionPoints(jarfile); }
From source file:net.sf.fjep.fatjar.wizards.export.BuildFJ.java
License:Open Source License
public static void buildConfiguredFatJar(JProjectConfiguration jproject, BuildProperties props, SourceInfo[] sourceInfo) {//from w w w.j a va 2s . c om // Create a progress bar Shell shell = new Shell(); ProgressMonitorDialog progressmonitordialog = new ProgressMonitorDialog(shell); progressmonitordialog.open(); IProgressMonitor iprogressmonitor = progressmonitordialog.getProgressMonitor(); iprogressmonitor.beginTask("Build Fat jar", PROGRESS_CLEAN + PROGRESS_COLLECT + PROGRESS_PACK + PROGRESS_CLEAN); // Make One-JAR? boolean onejar = props.isUseOneJar(); String expand = props.getOnejarExpand(); String jarfile = null; try { props.save(); jarfile = buildFatJar(jproject, props, sourceInfo); try { jproject.getProject().refreshLocal(IResource.DEPTH_ONE, null); } catch (CoreException e) { e.printStackTrace(); } JProjectConfiguration.removeTempFatjarConfigs(); } catch (Exception e) { e.printStackTrace(); MessageDialog.openInformation(shell, "Fat Jar Plug-In ERROR", e.getMessage()); } progressmonitordialog.close(); MessageDialog.openInformation(shell, "Fat Jar Plug-In", "built " + jarfile); }
From source file:nexcore.tool.uml.ui.core.registry.ResourceManager.java
License:Open Source License
/** * //from ww w .j av a2 s .co m * * void */ public void closeResource() { Display.getDefault().asyncExec(new Runnable() { @Override public void run() { ProjectUtil.closeAllEditor(); } }); UMLCacheManager.getInstance().shutdown(); ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell()); try { dialog.run(true, false, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject[] projects = root.getProjects(); cleanResource(monitor, projects, false); } }); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } finally { dialog.close(); allElementList.clear(); ResourceSet resourceSet = DomainRegistry.getUMLDomain().getResourceSet(); EList<Adapter> cacheAdapters = resourceSet.eAdapters(); cacheAdapters.remove(cacheAdapter); Map<URI, Resource> uriResourceMap = ((ResourceSetImpl) resourceSet).getURIResourceMap(); List<Resource> resourceList = new ArrayList<Resource>(); for (Iterator iterator = uriResourceMap.values().iterator(); iterator.hasNext();) { Resource resource = (Resource) iterator.next(); if (resource.getURI().toString().endsWith("uml")) { resourceList.add(resource); } } resourceSet.getResources().clear(); uriResourceMap.clear(); resourceSet.getResources().addAll(resourceList); cacheAdapter = null; System.gc(); } final CommonViewer viewer = ViewerRegistry.getViewer(); if (viewer != null && !viewer.getControl().isDisposed()) { Display.getDefault().asyncExec(new Runnable() { @Override public void run() { viewer.refresh(); } }); } }
From source file:nexcore.tool.uml.ui.core.registry.ResourceManager.java
License:Open Source License
/** * initializeRunnable/* w ww.j a va 2 s. c om*/ * * @param projects * @return RunnableWithResult<Object> */ private RunnableWithResult<Object> initializeRunnable(final IProject[] projects) { return /** * <ul> * <li> : nexcore.tool.uml.ui.core</li> * <li> : nexcore.tool.uml.ui.core.registry</li> * <li> : 1</li> * <li>? : 2012. 7. 10.</li> * <li>? : nspark</li> * </ul> */ new RunnableWithResult<Object>() { IStatus status = null; public Object getResult() { return status; } public IStatus getStatus() { return status; } public void setStatus(IStatus status) { } IProject[] projectArray; public IProject[] getProjects() { return projectArray; } public void setProjects(IProject[] projects) { this.projectArray = projects; } int count = 0; ModelUpdater modelUpdate = null; public void run() { referencedProject.clear(); setProjects(projects); executeProgressDialog(); // ? ? ? ? clear RESOURCE_MEMENTO.clear(); status = Status.OK_STATUS; } private void executeProgressDialog() { // prompt ? ? ? ? . boolean persistableResource = false; // RESOURCE_MEMENTO ? ?? ? ?? . if (!RESOURCE_MEMENTO.isEmpty()) { persistableResource = promptToPersistableResource(); } // ? RESOURCE_MEMENTO? clear ? ? . if (!persistableResource) { RESOURCE_MEMENTO.clear(); } ProgressMonitorDialog dialog = null; try { Shell shell = getShell(); count = 0; modelCount(getProjects()); dialog = new ProgressMonitorDialog(shell); dialog.setOpenOnRun(true); dialog.run(true, false, new IRunnableWithProgress() { private List<String> uriList = new ArrayList<String>(); private void worked(IProgressMonitor monitor, String uri) { try { if (!uriList.contains(uri)) { monitor.worked(1); uriList.add(uri); } } catch (Exception e) { e.printStackTrace(); } } public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask(UMLMessage.LABEL_LOAD_RESOURCE, count); Display.getDefault().syncExec(new Runnable() { @Override public void run() { for (IProject project : getProjects()) { if (!ProjectUtil.isActiveUMLProject(project)) { continue; } try { IMarker[] findMarkers = project.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_ONE); if (findMarkers != null) { for (IMarker marker : findMarkers) { marker.delete(); } } // project.deleteMarkers(IMarker.PROBLEM, true, IResource.DEPTH_ONE); } catch (CoreException e) { e.printStackTrace(); } } } }); resourceManager.addResourceLoadedAdapter(); // ? PrecedingInitializerRegistry.getInstance().executeInitializer(); // /////////////////////////////////////////////////////// // ??? // /////////////////////////////////////////////////////// String UML_MODEL_UPDATE = "UML_MODEL_UPDATE_%s_%s"; for (IProject project : getProjects()) { if (!ProjectUtil.isActiveUMLProject(project)) { continue; } monitor.setTaskName(String.format("%s : %s", project.getName(), UMLMessage.LABEL_MODEL_VERSION_CHECK)); String key = String.format(UML_MODEL_UPDATE, project.getName(), DateUtil.getCurrentDate()); // ?? ??? ?. String model_update = System.getProperty("model.update"); if (model_update != null && Boolean.parseBoolean(model_update)) { if (modelUpdate == null) { modelUpdate = new ModelUpdater(); } try { UiCorePlugin.getDefault().getPreferenceStore().setValue(key, true); modelUpdate.modelUpdate(project, monitor); monitor.subTask(""); } catch (Exception e) { e.printStackTrace(); } finally { if (modelUpdate != null) { modelUpdate.dispose(); } modelUpdate = null; UiCorePlugin.getDefault().getPreferenceStore().needsSaving(); } } } initUMLPrimitiveTypes(); initJavaPrimitiveTypes(); initXMLPrimitiveTypes(); UMLCacheAdapter crossReferenceAdapter = new UMLCacheAdapter(); crossReferenceAdapter.setMonitor(monitor); crossReferenceAdapter.setUriList(uriList); EList<Adapter> cacheAdapter = DomainRegistry.getUMLDomain().getResourceSet() .eAdapters(); if (!cacheAdapter.contains(crossReferenceAdapter)) { cacheAdapter.add(crossReferenceAdapter); } long s = System.currentTimeMillis(); // /////////////////////////////////////////////////////// for (IProject project : getProjects()) { try { if (!ProjectUtil.isActiveUMLProject(project)) { continue; } monitor.setTaskName(String.format("%s : %s", project.getName(), UMLMessage.LABEL_LOAD_RESOURCE)); for (IResource resource : project.members()) { loadUMXResource(resource, monitor, count); } monitor.subTask(""); } catch (Exception e) { e.printStackTrace(); } } if (UMLDebug.DEBUG) { System.err.println("---------------" + (System.currentTimeMillis() - s)); } monitor.subTask(""); monitor.done(); cacheAdapter.remove(crossReferenceAdapter); } // private void loadUMFResource(IResource resource, IProgressMonitor monitor, int total) { // try { // if (resource instanceof IFolder) { // for (IResource member : ((IFolder) resource).members()) { // loadUMFResource(member, monitor, total); // } // } else if (resource instanceof IFile) { // try { // if (ProjectUtil.isFragmentFile((IFile) resource)) { // monitor.worked(1); // String subTask = String.format(" %s", ((IFile) resource).getFullPath() // .toString()); // monitor.subTask(subTask); // // URI uri = URI.createURI(((IFile) resource).getFullPath().toString()); // Resource res = DomainRegistry.getUMLDomain() // .getResourceSet() // .getResource(uri, true); // res.setTrackingModification(true); // // ((ResourceImpl)res).setIntrinsicIDToEObjectMap(new HashMap<String, EObject>()); // // ? ? ? ? UML ? // // ? ? // // ? ?? . // EObject eObject; // if (!res.getContents().isEmpty()) { //// EcoreUtil.UnresolvedProxyCrossReferencer.find(res); // } // } // } catch (Exception e) { // // ignore // } // } // } catch (CoreException e) { // e.printStackTrace(); // } // } /** * * @param resource * @param monitor * @param total * void */ private synchronized void loadUMXResource(IResource resource, IProgressMonitor monitor, int total) { try { if (resource instanceof IFolder) { for (IResource member : ((IFolder) resource).members()) { loadUMXResource(member, monitor, total); } } else if (resource instanceof IFile) { try { if (DomainUtil.isUMXFile((IFile) resource)) { if (monitor != null) { String path = ((IFile) resource).getFullPath().toString(); worked(monitor, path); String subTask = String.format("Loading : %s", path); monitor.subTask(subTask); } URI uri = URI.createURI(((IFile) resource).getFullPath().toString()); boolean active = isActive(uri); if (!active) { return; } Resource res = DomainRegistry.getUMLDomain().getResource(uri, true); // ? ? does not exist. ? . // ? ?? ? ?? ? ? ? unload load . // ? ? ? ??. if (res != null && (!res.getErrors().isEmpty() || !res.getWarnings().isEmpty())) { res.unload(); res = DomainRegistry.getUMLDomain().getResourceSet() .getResource(uri, true); } if (!res.getContents().isEmpty()) { if (!res.isTrackingModification()) { res.setTrackingModification(true); } final Resource umlResource = res; DomainUtil.run(new TransactionalAction() { /** * @see nexcore.tool.uml.manager.transaction.TransactionalAction#doExecute() */ @Override public void doExecute() { EcoreUtil.resolveAll(umlResource); } }); } } } catch (Exception e) { // ignore e.printStackTrace(); } } } catch (CoreException e) { e.printStackTrace(); } } /** * * void */ private void initJavaPrimitiveTypes() { URI uri = URI.createURI(UMLResource.JAVA_PRIMITIVE_TYPES_LIBRARY_URI); Resource resource = DomainRegistry.getUMLDomain().getResource(uri, true); if (resource != null) { addElement(resource); } } /** * * void */ private void initUMLPrimitiveTypes() { URI uri = URI.createURI(UMLResource.UML_PRIMITIVE_TYPES_LIBRARY_URI); Resource resource = DomainRegistry.getUMLDomain().getResource(uri, true); if (resource != null) { addElement(resource); } } /** * * void */ private void initXMLPrimitiveTypes() { URI uri = URI.createURI(UMLResource.XML_PRIMITIVE_TYPES_LIBRARY_URI); Resource resource = DomainRegistry.getUMLDomain().getResource(uri, true); if (resource != null) { addElement(resource); } } }); } catch (InvocationTargetException e1) { e1.printStackTrace(); } catch (InterruptedException e1) { e1.printStackTrace(); } finally { dialog.close(); System.gc(); if (referencedProject.size() > 0) { boolean openQuestion = promptToOpenWithReferences(); if (!openQuestion) { referencedProject.clear(); return; } setProjects(referencedProject.keySet().toArray(new IProject[] {})); openProject(referencedProject.keySet().toArray(new IProject[] {})); resourceManager.removeResourceLoadedAdapter(); } } } private int modelCount(IProject[] projects) { for (IProject project : projects) { if (!ProjectUtil.isActiveUMLProject(project)) { continue; } try { for (IResource r : project.members()) { count(r); } } catch (CoreException e) { e.printStackTrace(); } } return count; } /** * promptToOpenWithReferences * * @return boolean */ private boolean promptToOpenWithReferences() { IPreferenceStore store = UiCorePlugin.getDefault().getPreferenceStore(); String key = "OPEN_REQUIRED_PROJECTS"; String value = store.getString(key); if (MessageDialogWithToggle.ALWAYS.equals(value)) { return true; } if (MessageDialogWithToggle.NEVER.equals(value)) { return false; } String message = UMLMessage.MESSAGE_REFERENCED_PROJECTS;//"? ? ."; MessageDialogWithToggle dialog = MessageDialogWithToggle.openInformation(getShell(), "Information", message, null, false, store, key);//MessageDialogWithToggle.openYesNoCancelQuestion(getShell(), "Question", message, null, false, store, key); int result = dialog.getReturnCode(); // the result is equal to SWT.DEFAULT if the user uses the 'esc' key to close the dialog return dialog.getReturnCode() == IDialogConstants.OK_ID || result == SWT.DEFAULT; } /** * promptToPersistableResource * * @return boolean */ private boolean promptToPersistableResource() { return true; } private void count(IResource resource) { if (resource instanceof IFolder) { try { for (IResource member : ((IFolder) resource).members()) { count(member); } } catch (CoreException e) { } } else if (resource instanceof IFile) { if (ProjectUtil.isModelFile((IFile) resource)) { count++; URI uri = URI.createURI(resource.getFullPath().toString()); IProject project = resource.getProject(); List<String> list = RESOURCE_MEMENTO.get(project.getName()); if (list != null && list.contains(uri.toString())) { ResourceManager.getInstance().setActivation(uri, true); } else { ResourceManager.getInstance().setActivation(uri, false); } } } } }; }
From source file:nexcore.tool.uml.ui.project.explorer.action.ClearUnusedElementAction.java
License:Open Source License
/** * @see nexcore.tool.uml.ui.project.explorer.action.CommonActionDelegate#run(org.eclipse.jface.action.IAction) *//*from ww w. ja va 2s .c o m*/ @Override public void run(IAction action) { if (!(selectedEObject instanceof Namespace)) { return; } Namespace selectedElement = (Namespace) selectedEObject; if (!MessageDialog.openConfirm(UiCorePlugin.getShell(), UMLMessage.getMessage(UMLMessage.LABEL_DELETE_UNUSED_ELEMENT), UMLMessage.getMessage( UMLMessage.MESSAGE_DELETE_UNUSED_ELEMENT, selectedElement.getQualifiedName()))) { return; } ProgressMonitorDialog dialog = new ProgressMonitorDialog(targetPart.getSite().getShell()); dialog.create(); dialog.getProgressMonitor().beginTask(UMLMessage.LABEL_DELETE_UNUSED_ELEMENT, IProgressMonitor.UNKNOWN); dialog.open(); /********* . *********/ EList<Lifeline> lifelineList = null; // ????? . EList<Message> messageList = null; // ? . EList<AbstractConnection> connectionList = null; // ?? . EList<AbstractNode> nodeList = null; // ?? . // ?? ? ???? . List<Lifeline> lifelineNodeList = new ArrayList<Lifeline>(); // ?? ? . List<Message> messageConnectionList = new ArrayList<Message>(); // EObject ? .. List<Element> deleteList = new ArrayList<Element>(); // ? ?. // List<Diagram> sequencediagramList = ModelManager.getAllDiagramList(selectedElement, // DiagramType.SEQUENCE_DIAGRAM); // for (Diagram diagram : sequencediagramList) { // if (diagram.getParent() instanceof Interaction) { // Interaction interaction = (Interaction) diagram.getParent(); // // /********* MessageOccurenceSpecification, BehaviorExecutionSpecification ?. *********/ // // ???? ? ? MessageOccurenceSpecification BehaviorExecutionSpecification, Event. // EList<InteractionFragment> fragments = interaction.getFragments(); // for (InteractionFragment interactionFragment : fragments) { // if (interactionFragment instanceof MessageOccurrenceSpecification) { // MessageOccurrenceSpecification mos = (MessageOccurrenceSpecification) interactionFragment; // if (null == mos.getMessage()) { // deleteList.add(interactionFragment); // if (null != mos.getEvent()) { // deleteList.add(mos.getEvent()); // } // } // } else if (interactionFragment instanceof BehaviorExecutionSpecification) { // BehaviorExecutionSpecification bes = (BehaviorExecutionSpecification) interactionFragment; // if (null == bes.getStart() || null == bes.getFinish()) { // deleteList.add(interactionFragment); // } // } // } // // /********* ???? ?. *********/ // // ?? ???? ?. // nodeList = diagram.getNodeList(); // lifelineNodeList = new ArrayList<Lifeline>(); // for (AbstractNode abstractNode : nodeList) { // Element element = abstractNode.getUmlModel(); // if (element instanceof Lifeline) { // lifelineNodeList.add((Lifeline) element); // } // } // // // ????? ?? ?. // lifelineList = interaction.getLifelines(); // for (Lifeline lifeline : lifelineList) { // if (!lifelineNodeList.contains(lifeline)) { // deleteList.add(lifeline); // } // } // // /********* ?. *********/ // // ?? ? // connectionList = diagram.getConnectionList(); // messageConnectionList = new ArrayList<Message>(); // for (AbstractConnection abstractConnection : connectionList) { // Element element = abstractConnection.getUmlModel(); // if (element instanceof Message) { // messageConnectionList.add((Message) element); // } // } // // // ?? ?. // messageList = interaction.getMessages(); // for (Message message : messageList) { // if (!messageConnectionList.contains(message)) { // deleteList.add(message); // } // } // } // } /********* . *********/ // TODO deleteList . Command deleteCommand; CompoundCommand deleteCommandList = new CompoundCommand(); List<IMarker> deleteMarkerList = new ArrayList<IMarker>(); // deleteCommandList.add(diagramDelete); for (EObject eobject : deleteList) { // UMLManager.clearStereotype((Element) eobject); // EcoreUtil.remove(eobject); NamedElement obj = (NamedElement) eobject; deleteCommand = DeleteUMLElementCommandFactory.getCommand(obj); if (null == deleteCommand) { continue; } else { deleteCommandList.add(deleteCommand); ProjectRegistry.UMLTreeNodeRegistry.removeTreeNode(obj); // IPath path = new Path(obj.eResource().getURI().toFileString()); IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); try { IMarker[] markers = file.findMarkers(UICoreConstant.VALIDATION_MARKER_TYPE, true, IResource.DEPTH_INFINITE); for (IMarker marker : markers) { String location = (String) marker.getAttribute(IMarker.LOCATION); if (obj.getQualifiedName().equals(location) && !deleteMarkerList.contains(marker)) { deleteMarkerList.add(marker); } } } catch (CoreException e) { } } } if (0 != deleteCommandList.getCommands().size()) { for (int i = 0; i < deleteMarkerList.size(); i++) { try { if (deleteMarkerList.get(i).exists()) { deleteMarkerList.get(i).delete(); } } catch (CoreException e) { Log.error(e); } } ((UMLDiagramCommandStack) DomainRegistry.getUMLDomain().getCommandStackListener()) .execute(deleteCommandList); // deleteResource(); } dialog.getProgressMonitor().done(); dialog.close(); MessageDialog.openInformation(ProjectExplorerPlugin.getShell(), UMLMessage.LABEL_DELETE_UNUSED_ELEMENT_COMPLETED, UMLMessage.getMessage(UMLMessage.MESSAGE_DELETE_UNUSED_ELEMENT_COMPLETED, String.valueOf(deleteCommandList.size()))); }
From source file:nexcore.tool.uml.ui.project.explorer.action.MergeFragmentAction.java
License:Open Source License
/** * @see nexcore.tool.uml.ui.project.explorer.action.CommonActionDelegate#run(org.eclipse.jface.action.IAction) *///from www .ja va2 s. co m @Override public void run(IAction action) { if (selectedEObject == null) { return; } if (!(AdapterFactoryEditingDomain.isControlled(selectedEObject))) { MessageDialog.openInformation(ProjectExplorerPlugin.getShell(), UMLMessage.LABEL_FILE_DEFRAGMENTATION, UMLMessage.MESSAGE_FRAGMENT_NOT_FRAGMENTED); return; } if (!MessageDialog.openConfirm(UiCorePlugin.getShell(), UMLMessage.getMessage(UMLMessage.LABEL_FILE_DEFRAGMENTATION), UMLMessage.getMessage(UMLMessage.MESSAGE_CONFIRM_MERGE))) { return; } final ChangeRecorder recorder = new ChangeRecorder(DomainRegistry.getUMLDomain().getResourceSet()); // TODO : close the opened windows of the fragment file. // CommandUtil.closeEditor(eobject, false); DomainRegistry.getEditingDomain().getCommandStack() .execute(new RecordingCommand(DomainRegistry.getEditingDomain()) { /** * @see org.eclipse.emf.transaction.RecordingCommand#doExecute() */ @Override public void doExecute() { ProgressMonitorDialog dialog = new ProgressMonitorDialog(ProjectExplorerPlugin.getShell()); dialog.create(); EList<Resource> resources = DomainRegistry.getUMLDomain().getResourceSet().getResources(); dialog.getProgressMonitor().beginTask(UMLMessage.LABEL_FILE_DEFRAGMENTATION, resources.size()); dialog.open(); IResourceSetListener rsListener = ContentProviderRegistry.getContentProvider(); try { if (rsListener != null) { rsListener.stopResourceListening(); } Resource sourceResource = selectedEObject.eResource(); org.eclipse.uml2.uml.Package source = (org.eclipse.uml2.uml.Package) selectedEObject; // ? ?? ? Reference . EAnnotation sourceFragmentContainerAnnotation = ProjectUtil .getFragmentContainerAnnotation(source); if (sourceFragmentContainerAnnotation.getReferences() != null) { sourceFragmentContainerAnnotation.getReferences() .remove(selectedEObject.eContainer()); } // ? ?? FragmentContainer if (sourceFragmentContainerAnnotation != null) { source.getEAnnotations().remove(sourceFragmentContainerAnnotation); } // ? ?? ProjectInfo EAnnotation sourceProjectInfoAnnotation = ProjectUtil.getProjectInfoAnnotation(source); if (sourceProjectInfoAnnotation != null) { source.getEAnnotations().remove(sourceProjectInfoAnnotation); } // ?? Fragment Reference org.eclipse.uml2.uml.Package target = (org.eclipse.uml2.uml.Package) selectedEObject .eContainer(); EAnnotation targetAnn = ProjectUtil.getFragmentAnnotation(target); if (targetAnn.getReferences() != null) { targetAnn.getReferences().remove(selectedEObject); } // ?? ? ? ? URI srcUri = sourceResource.getURI(); URI parentUri = selectedEObject.eContainer().eResource().getURI(); List<Resource> saveResourceList = new ArrayList<Resource>(); for (Resource rs : resources) { if (rs != null && ProjectUtil.isModelFile(rs)) { final IFile file = WorkspaceSynchronizer.getFile(rs); if (file != null && file.exists()) { if (!rs.isLoaded()) { rs.load(DomainModelHandlerUtil.getLoadOptions()); } dialog.getProgressMonitor().worked(1); if (ResourceManager.getInstance().isRelated(rs, srcUri)) { dialog.getProgressMonitor().subTask(rs.getURI().toString()); saveResourceList.add(rs); continue; } if (ResourceManager.getInstance().isRelated(rs, parentUri)) { dialog.getProgressMonitor().subTask(rs.getURI().toString()); saveResourceList.add(rs); continue; } if (rs == selectedEObject.eResource()) { dialog.getProgressMonitor().subTask(rs.getURI().toString()); saveResourceList.add(rs); continue; } if (rs == selectedEObject.eContainer().eResource()) { dialog.getProgressMonitor().subTask(rs.getURI().toString()); saveResourceList.add(rs); } dialog.getProgressMonitor().subTask(""); } } } // ?? Fragment if (targetAnn != null) { if (targetAnn.getReferences() != null && targetAnn.getReferences().size() == 0) { target.getEAnnotations().remove(targetAnn); } } ResourceManager.getInstance().removeContentsOfResource(sourceResource, selectedEObject); selectedEObject.eResource().getContents().addAll( ProjectUtil.getStereotypesForFragment(sourceResource, selectedEObject, true)); for (Resource saveResource : saveResourceList) { DomainModelHandlerUtil.save(saveResource, true); } // have to remove source file. final EObject parentObject = selectedEObject.eContainer(); final IFile file = WorkspaceSynchronizer.getFile(sourceResource); TreeIterator<EObject> allContents = source.eAllContents(); while (allContents.hasNext()) { EObject content = allContents.next(); UMLTreeNodeRegistry.removeTreeNode(content); } UMLTreeNodeRegistry.removeTreeNode(source); // ResourceManager.getInstance().removeResource(sourceResource); ResourceUnloader.getInstance().put(sourceResource); ProjectExplorerPlugin.getDisplay().asyncExec(new Runnable() { public void run() { try { // 2011-08-11 ? // ?? ?? .fragment? ?? boolean isPackageStructuredFragment = true; IFolder folder = ((IFolder) ResourcesPlugin.getWorkspace().getRoot() .getFolder(file.getFullPath()).getParent()); while (!folder.getName() .equals(UICoreConstant.PROJECT_CONSTANTS__FRAGMENT_FOLDER_NAME)) { Object parent = folder.getParent(); if (!(parent instanceof IFolder)) { isPackageStructuredFragment = false; break; } folder = ((IFolder) parent); } if (isPackageStructuredFragment) { folder = ((IFolder) ResourcesPlugin.getWorkspace().getRoot() .getFolder(file.getFullPath()).getParent()); List<IFolder> removeList = new ArrayList<IFolder>(); while ((folder.members().length == 1) && (!folder.getName().equals( UICoreConstant.PROJECT_CONSTANTS__FRAGMENT_FOLDER_NAME))) { removeList.add(folder); folder = ((IFolder) folder.getParent()); } file.delete(false, new NullProgressMonitor()); for (Iterator<IFolder> it = removeList.iterator(); it.hasNext();) { folder = (IFolder) it.next(); folder.delete(false, new NullProgressMonitor()); } } else { file.delete(false, new NullProgressMonitor()); } } catch (Exception ex) { ex.printStackTrace(); Log.error(ex); } finally { try { if (parentObject != null) { ProjectUtil.refreshNodeInExplorer(parentObject); } } catch (Exception e) { e.printStackTrace(); // ignore } } } }); } catch (Exception e) { e.printStackTrace(); // ResourceSet rollback ProjectUtil.rollbackResourceSet(recorder); dialog.getProgressMonitor().done(); dialog.close(); MessageDialog.openError(ProjectExplorerPlugin.getShell(), UMLMessage.LABEL_FILE_DEFRAGMENTATION, UMLMessage.MESSAGE_SAVE_FAIL); } finally { if (rsListener != null) { rsListener.startResourceListening(); } try { dialog.getProgressMonitor().done(); dialog.close(); } catch (Exception e) { //ignore } } } }); System.gc(); }
From source file:org.eclipse.birt.chart.integration.wtp.ui.internal.actions.ImportChartRuntimeAction.java
License:Open Source License
/** * action to import birt runtime component * // w w w.j av a2s.co m * @param window * @param isClear * @throws Exception */ protected void doImport(IWorkbenchWindow window, boolean isClear) throws Exception { ProgressMonitorDialog monitor = null; try { // web content folder IPath webContentPath = BirtWizardUtil.getWebContentPath(project); // do import birt runtime monitor = new ProgressMonitorDialog(window.getShell()); monitor.open(); // check whether clears the old birt runtime files if (isClear) doClearAction(webContentPath, monitor.getProgressMonitor()); // import birt runtime component BirtWizardUtil.doImports(project, null, webContentPath, monitor.getProgressMonitor(), new ImportOverwriteQuery(monitor.getShell())); // process defined folders BirtWizardUtil.processCheckFolder(properties, project, webContentPath.toFile().getName(), monitor.getProgressMonitor()); // configurate web.xml processConfiguration(monitor.getProgressMonitor(), monitor.getShell()); } finally { // closs dialog if (monitor != null) { monitor.close(); } } }
From source file:org.eclipse.emf.ecp.common.commands.DeleteModelElementCommand.java
License:Open Source License
/** * {@inheritDoc}// w w w . ja v a 2 s . c o m */ public void run() { // remove already contained model elements to prevent double deletes -> exception removeAnchestorDuplicates(toBeDeleted); // collect all association classes to be deleted Set<EObject> additionalMEs = new HashSet<EObject>(); for (EObject eObject : toBeDeleted) { additionalMEs.addAll(AssociationClassHelper.getRelatedAssociationClassToDelete(eObject, context.getMetaModelElementContext())); } toBeDeleted.addAll(additionalMEs); // now delete if (askConfirmation()) { ProgressMonitorDialog progressDialog = new ProgressMonitorDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); progressDialog.open(); try { long start = System.currentTimeMillis(); removeElementsWithoutRoot(toBeDeleted); if (toBeDeleted.size() > 0) { new ECPCommandWithParameter<Set<EObject>>(toBeDeleted.iterator().next()) { @Override protected void doRun(Set<EObject> parameter) { for (EObject eObject : toBeDeleted) { EcoreUtil.delete(eObject, true); } } }.run(toBeDeleted); } setStatusMessage( "Element deletion lasted " + (System.currentTimeMillis() - start) / 1000.0 + "sec"); // Command deleteCommand = DeleteCommand.create(context.getEditingDomain(), toBeDeleted); // context.getEditingDomain().getCommandStack().execute(deleteCommand); } finally { progressDialog.getProgressMonitor().done(); progressDialog.close(); } } }