List of usage examples for org.eclipse.jface.dialogs ProgressMonitorDialog run
@Override public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException
IRunnableWithProgress
using the progress monitor for this progress dialog and blocks until the runnable has been run, regardless of the value of fork
. From source file:com.motorola.studio.android.emulator.ui.view.AbstractAndroidView.java
License:Apache License
/** * Stops all emulator instances with the Progress Monitor opened. *//*from ww w.jav a2 s . co m*/ private void stopEmulatorInstances() { // defines the runnable object for stopping emulator instances. final IRunnableWithProgress stopRunnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) { Collection<IAndroidEmulatorInstance> startedInstances = DeviceFrameworkManager.getInstance() .getAllStartedInstances(); boolean errorsHappened = false; for (IAndroidEmulatorInstance instance : startedInstances) { try { instance.stop(true); } catch (InstanceStopException e) { errorsHappened = true; } } // if closing on shutdown, use a progress bar and stall UI if (closingOnShutdown) { // start a progress monitor monitor.beginTask("", IProgressMonitor.UNKNOWN); // make sure the stop instance job finished Job[] jobs = Job.getJobManager().find(null); // get all jobs for (Job job : jobs) { if (job.getName().equals(EmulatorNLS.UI_AbstractAndroidView_StopInstanceJob)) { // when job result is not null, it has finished while (job.getResult() == null) { try { // sleep a little so the waiting is not too busy Thread.sleep(1000); } catch (InterruptedException e) { // do nothing } } } } } if (errorsHappened) { EclipseUtils.showErrorDialog(EmulatorNLS.GEN_Error, EmulatorNLS.EXC_AncroidView_CannotRunMultipleStopServices); } } }; // executes the runnable defined above. PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { public void run() { Shell currentShell = getViewSite().getShell(); ProgressMonitorDialog dialog = new ProgressMonitorDialog(currentShell); try { dialog.run(true, false, stopRunnable); } catch (Exception e) { // Should not have exceptions. // The runnable is not interrupted and it handles exceptions internally // Log runtime exceptions error("Runtime exception was thrown: " + e.getClass().getSimpleName()); } } }); }
From source file:com.motorola.studio.android.generatemenucode.ui.GenerateMenuCodeHandler.java
License:Apache License
/** * Open {@link GenerateMenuCodeDialog} and use {@link JavaModifierBasedOnMenu} to insert code into Android source code (Activity/Fragment). *//*from w w w . ja v a 2 s. co m*/ public Object execute(ExecutionEvent event) throws ExecutionException { SelectionBean selectionBean = resolveSelection(event); if (selectionBean.isProject() || selectionBean.isAllowedClassInstance()) { final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); GenerateMenuCodeDialog menuDialog = new GenerateMenuCodeDialog(window.getShell(), CodeUtilsNLS.GenerateMenuCodeDialog_DefaultMessage, CodeUtilsNLS.GenerateMenuCodeDialog_Title, CodeUtilsNLS.GenerateMenuCodeDialog_ShellTitle, CodeUtilsActivator.getImageDescriptor(WIZARD_IMAGE_PATH).createImage()); final JavaModifierBasedOnMenu modifier = new JavaModifierBasedOnMenu(); menuDialog.init(modifier, selectionBean.getJavaProject(), selectionBean.getJavaFile()); int status = menuDialog.open(); if (status == Window.OK) { ICompilationUnit compilationUnit = menuDialog.getJavaFile(); IEditorPart editor = null; try { editor = JavaUI.openInEditor(compilationUnit); } catch (Exception e) { StudioLogger.warn(GenerateMenuCodeHandler.class, "Unable to open editor or bring it to front for Java file while trying to generate menu code based on xml file", //$NON-NLS-1$ e); } final ProgressMonitorDialog dialog = new ProgressMonitorDialog(menuDialog.getShell()); final IEditorPart editorPart = editor; PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { public void run() { try { dialog.run(true, false, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { // collect usage data - UDC StudioLogger.collectUsageData(UsageDataConstants.WHAT_VIEW_BY_MENU_EXEC, UsageDataConstants.KIND_VIEW_BY_MENU_EXEC, "View by menu feature executed.", //$NON-NLS-1$ CodeUtilsActivator.PLUGIN_ID, CodeUtilsActivator.getDefault() .getBundle().getVersion().toString()); modifier.insertCode(monitor, editorPart); } catch (final JavaModelException e) { final MultiStatus errorStatus = new MultiStatus( CodeUtilsActivator.PLUGIN_ID, IStatus.ERROR, "Error inserting code on activity/fragment based on menu", //$NON-NLS-1$ null); errorStatus.merge(e.getStatus()); PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { public void run() { IStatus mostSevere = EclipseUtils.findMostSevereError(errorStatus); ErrorDialog.openError( PlatformUI.getWorkbench().getDisplay().getActiveShell(), "Error inserting code on activity/fragment based on menu", //$NON-NLS-1$ e.getMessage(), mostSevere); } }); StudioLogger.error(this.getClass(), "Error inserting code on activity/fragment based on menu" //$NON-NLS-1$ + ": " + e.getMessage()); //$NON-NLS-1$ } } }); } catch (Exception e) { StudioLogger.error(this.getClass(), "Error inserting code on activity/fragment based on menu" //$NON-NLS-1$ + ": " + e.getMessage()); //$NON-NLS-1$ } } }); } } else { EclipseUtils.showErrorDialog(CodeUtilsNLS.GenerateMenuCodeDialog_Title, CodeUtilsNLS.GenerateMenuCodeHandler_SelectedClassNeitherActivityFragment);//GenerateMenuCodeHandler_SelectedClassNeitherActivityFragment } return null; }
From source file:com.motorola.studio.android.generateviewbylayout.ui.AbstractCodeGeneratorHandler.java
License:Apache License
protected static void executeCodeGenerationWizard(ExecutionEvent event, IFile javaFile, final IProject javaProject, final AbstractLayoutItemsDialog layoutDialog) { final JavaModifierBasedOnLayout modifier = new JavaModifierBasedOnLayout(); layoutDialog.init(modifier, javaProject, javaFile); int status = layoutDialog.open(); if (status == Window.OK) { ICompilationUnit compilationUnit = layoutDialog.getJavaFile(); IEditorPart editor = null;//from www . jav a2s.co m try { editor = JavaUI.openInEditor(compilationUnit); } catch (Exception e) { StudioLogger.warn(AbstractCodeGeneratorHandler.class, "Unable to open editor or bring it to front for Java file while trying to generate code from layout xml file", //$NON-NLS-1$ e); } final ProgressMonitorDialog dialog = new ProgressMonitorDialog(layoutDialog.getShell()); final IEditorPart editorPart = editor; PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { public void run() { try { dialog.run(true, false, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { // collect usage data - UDC StudioLogger.collectUsageData(UsageDataConstants.WHAT_VIEW_BY_LAYOUT_EXEC, UsageDataConstants.KIND_VIEW_BY_LAYOUT_EXEC, "View by layout feature executed.", //$NON-NLS-1$ CodeUtilsActivator.PLUGIN_ID, CodeUtilsActivator.getDefault().getBundle().getVersion().toString()); modifier.insertCode(monitor, editorPart); } catch (final JavaModelException e) { final MultiStatus errorStatus = new MultiStatus(CodeUtilsActivator.PLUGIN_ID, IStatus.ERROR, "Error inserting code on activity/fragment based on layout", null); errorStatus.merge(e.getStatus()); PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { public void run() { IStatus mostSevere = EclipseUtils.findMostSevereError(errorStatus); ErrorDialog.openError( PlatformUI.getWorkbench().getDisplay().getActiveShell(), "Error inserting code on activity/fragment based on layout", e.getMessage(), mostSevere); } }); StudioLogger.error(this.getClass(), "Error inserting code on activity/fragment based on layout" + ": " //$NON-NLS-2$ + e.getMessage()); } } }); } catch (Exception e) { StudioLogger.error(this.getClass(), "Error inserting code on activity/fragment based on layout" + ": " //$NON-NLS-2$ + e.getMessage()); } } }); } }
From source file:com.motorola.studio.android.packaging.ui.export.PackageExportWizardArea.java
License:Apache License
/** * do the finish: Create the package for each selected descriptor */// w w w .j a va 2 s . c o m public boolean performFinish() { final boolean[] finished = { false }; boolean destOK = false; final MultiStatus status = new MultiStatus(PackagingUIPlugin.PLUGIN_ID, IStatus.OK, "", null); //$NON-NLS-1$ ProgressMonitorDialog monitorDialog = null; String DESCRIPTION_TO_LOG = StudioLogger.DESCRIPTION_DEFAULT; try { destOK = checkDestination(); } catch (CoreException e) { status.add(e.getStatus()); } if (destOK) { monitorDialog = new ProgressMonitorDialog(parentComposite.getShell()); try { monitorDialog.run(false, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor aMonitor) throws InvocationTargetException, InterruptedException { int finishSize = getSelectedItems().size() * PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER; SubMonitor monitor = SubMonitor.convert(aMonitor); monitor.beginTask(Messages.PACKAGE_EXPORT_WIZARD_AREA_FINISH_ACTION_LABEL, finishSize); IPath exportDestinationFolder = new Path(destinationText.getText()); IPath exportDestinationFile = null; for (TreeItem item : getSelectedItems()) { // get the eclipse project as a java project to get // the project // destination IProject eclipseProject = (IProject) item.getData(); try { monitor.worked(PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER / 4); JavaProject javaProject = new JavaProject(); javaProject.setProject(eclipseProject); // find all packages built by Android builder Map<String, String> apkConfigurations = SdkUtils .getAPKConfigurationsForProject(eclipseProject); Set<String> apkConfNames = new HashSet<String>(); if (apkConfigurations != null) { apkConfNames.addAll(apkConfigurations.keySet()); } apkConfNames.add(""); // the default package //$NON-NLS-1$ SubMonitor submonitor = monitor .newChild(PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER / 4); submonitor.beginTask(Messages.PACKAGE_EXPORT_WIZARD_AREA_EXPORTING_ACTION_LABEL, 3 * PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER * apkConfNames.size()); for (String apkConfName : apkConfNames) { String apkName = eclipseProject.getName() + (apkConfName.isEmpty() ? apkConfName : "-" //$NON-NLS-1$ //$NON-NLS-2$ + apkConfName); if (defaultDestination.getSelection()) { exportDestinationFolder = eclipseProject.getLocation() .append(CertificateManagerActivator.PACKAGE_PROJECT_DESTINATION); } exportDestinationFile = exportDestinationFolder.append(apkName) .addFileExtension(CertificateManagerActivator.PACKAGE_EXTENSION); File file = exportDestinationFile.toFile(); submonitor.worked(PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER); //always export unsigned package AdtUtils.exportUnsignedReleaseApk(javaProject.getProject(), file, submonitor); submonitor.worked(PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER); if (signCheckBox.getSelection()) { //sign the package if required IStatus signStatus = signPackage(eclipseProject, file); status.add(signStatus); } //zipalign the file and we are done exporting the package PackageFile.zipAlign(file); submonitor.worked(PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER); } submonitor.done(); } catch (CoreException e) { StudioLogger.error(PackageExportWizardArea.class, "Error while building project or getting project output folder" //$NON-NLS-1$ + eclipseProject.getName(), e); status.add(new Status(IStatus.ERROR, PackagingUIPlugin.PLUGIN_ID, Messages.PACKAGE_EXPORT_WIZARD_AREA_ERROR_PROJECT_BUILD + " " //$NON-NLS-1$ + eclipseProject.getName())); } finally { try { eclipseProject.refreshLocal(IResource.DEPTH_INFINITE, monitor.newChild(PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER / 4)); } catch (CoreException e) { // do nothing } } monitor.worked(PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER / 4); } finished[0] = true; } }); } catch (Exception e) { StudioLogger.warn("Error finishing package export."); } } if (!status.isOK()) { status.getMessage(); DESCRIPTION_TO_LOG = Messages.PACKAGE_EXPORT_WIZARD_AREA_READONLY_TITLE; ErrorDialog.openError(parentComposite.getShell(), Messages.PACKAGE_EXPORT_WIZARD_AREA_READONLY_TITLE, Messages.PACKAGE_EXPORT_WIZARD_AREA_READONLY_MESSAGE, status); } // Saving usage data try { StudioLogger.collectUsageData(StudioLogger.WHAT_APP_MANAGEMENT_PACKAGE, StudioLogger.KIND_APP_MANAGEMENT, DESCRIPTION_TO_LOG, PackagingUIPlugin.PLUGIN_ID, PackagingUIPlugin.getDefault().getBundle().getVersion().toString()); } catch (Throwable e) { // Do nothing, but error on the log should never prevent app from // working } return finished[0]; }
From source file:com.muratools.eclipse.wizard.newInstall.NewInstallWizard.java
License:Apache License
private void downloadMura() { ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell()); try {// w w w . j a v a 2 s .c om dialog.run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { //monitor.beginTask("Downloading Mura...", 100); try { URL url = new URL("http://www.getmura.com/currentversion/?source=muratools"); int contentLength = url.openConnection().getContentLength(); monitor.beginTask("Downloading Mura...", contentLength); InputStream reader = url.openStream(); FileOutputStream writer = new FileOutputStream(zipLocation); byte[] buffer = new byte[44640]; int bytesRead = 0; int tp = 0; while ((bytesRead = reader.read(buffer)) > 0) { writer.write(buffer, 0, bytesRead); buffer = new byte[44640]; tp++; System.err.println(tp + " / " + Integer.toString((int) Math.ceil((double) contentLength / (double) 44640)) + "[" + bytesRead + "]"); monitor.worked(bytesRead); } writer.close(); reader.close(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } monitor.done(); } }); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:com.muratools.eclipse.wizard.newInstall.NewInstallWizard.java
License:Apache License
private void deployMuraZip() { ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell()); try {/*from w w w. j a va 2 s.co m*/ dialog.run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { //monitor.beginTask("Unzipping Mura...", IProgressMonitor.UNKNOWN); try { String tempDir = System.getProperty("java.io.tmpdir") + "/latest-mura-" + Long.toString(new Date().getTime()); // make the tempDir new File(tempDir).mkdir(); Enumeration entries; ZipFile zipFile; zipFile = new ZipFile(zipLocation); entries = zipFile.entries(); monitor.beginTask("Unzipping Mura...", zipFile.size() * 2); // unzip the zip file to the temp directory while (entries.hasMoreElements()) { ZipEntry entry = (ZipEntry) entries.nextElement(); String fullEntryPath = tempDir + "/" + entry.getName(); if (entry.isDirectory()) { (new File(fullEntryPath)).mkdir(); continue; } copyInputStream(zipFile.getInputStream(entry), new BufferedOutputStream(new FileOutputStream(fullEntryPath))); monitor.worked(1); } zipFile.close(); // copy the files to the target directory String sourceDir = tempDir; File testDir = new File(tempDir + "/www"); if (testDir.exists() && testDir.isDirectory()) { sourceDir += "/www"; } copyDirectory(new File(sourceDir), new File(getTargetDirectory()), monitor); } catch (IOException e) { e.printStackTrace(); } monitor.done(); } }); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:com.nextep.datadesigner.gui.impl.CommandProgress.java
License:Open Source License
public static List<?> runWithProgress(boolean fork, String name, Shell shell, boolean cancellable, ICommand... commands) {//from ww w . ja v a 2 s. c o m waitVolatileJobs(); ProgressMonitorDialog pd = new ProgressMonitorDialog(shell); try { CommandProgress cmdProgress = new CommandProgress(fork, name, shell, commands); pd.run(fork, cancellable, cmdProgress); return cmdProgress.getResults(); } catch (InvocationTargetException e) { if (e.getCause() instanceof DesignerException) { throw (DesignerException) e.getCause(); } else if (e.getCause() instanceof SWTException && e.getCause().getCause() instanceof DesignerException) { // In case of Display.syncExec or asyncExec call, we will fall here // with our exception wrapped into a SWTException throw (DesignerException) e.getCause().getCause(); } else { throw new ErrorException(e.getCause()); } } catch (InterruptedException e) { throw new ErrorException(e); } }
From source file:com.nextep.datadesigner.vcs.gui.dialog.MergeResultGUI.java
License:Open Source License
private void createMergeNavigators() { // Sorting results by source name / target name final List<IComparisonItem> sortedResult = Arrays.asList(result); // Sorting items unless told not to do so if (!noSort) { Collections.sort(sortedResult, new Comparator<IComparisonItem>() { @Override/* w ww . ja v a 2 s . com*/ public int compare(IComparisonItem o1, IComparisonItem o2) { IReferenceable src = o1.getSource() == null ? o1.getTarget() : o1.getSource(); IReferenceable tgt = o2.getSource() == null ? o2.getTarget() : o2.getSource(); return ((INamedObject) src).getName().compareTo(((INamedObject) tgt).getName()); } }); } // Creating merge lines items ProgressMonitorDialog pd = new ProgressMonitorDialog(this.getShell()); try { pd.run(false, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.setTaskName("Initializing..."); monitor.beginTask("Preparing preview for user validation...", result.length); for (IComparisonItem content : sortedResult) { // if(!hideUnchanged || content.getDifferenceType()!=DifferenceType.EQUALS) { int type = UPDATES; switch (content.getDifferenceType()) { case EQUALS: if (hideUnchanged) { continue; } type = UNCHANGED; break; case DIFFER: type = UPDATES; break; case MISSING_SOURCE: type = DELETIONS; break; case MISSING_TARGET: type = ADDITIONS; break; } sourceConn = new MergeNavigator(sourceRoot[type], targetRoot[type], mergedRoot[type], content); sourceConn.setShowAllChecks(repositoryMergeWindow); if (content.getDifferenceType() != DifferenceType.EQUALS) { sourceConn.showUnchangedItems(!hideUnchanged); } else { sourceConn.showUnchangedItems(true); } sourceConn.create(sourceRoot[type], -1); sourceConn.initialize(); sourceConn.refreshConnector(false); monitor.worked(1); } // } for (int i = 0; i < 4; i++) { final int count = sourceRoot[i].getItemCount(); if (count > 0) { sourceRoot[i].setText(VCSUIMessages.getString(msgKeys[i]) + " (" + count + ")"); sourceRoot[i].setFont(FontFactory.FONT_BOLD); // Unchecking everything to ensure reprocessing sourceRoot[i].setChecked(false); targetRoot[i].setChecked(false); mergedRoot[i].setChecked(false); // Processing gray checks gray(sourceRoot[i]); gray(targetRoot[i]); gray(mergedRoot[i]); } else { sourceRoot[i].setText(VCSUIMessages.getString(msgKeys[i])); sourceRoot[i].setFont(null); } } monitor.done(); } }); } catch (Exception e) { throw new ErrorException(e); } }
From source file:com.nextep.datadesigner.vcs.gui.dialog.VersionDiffViewer.java
License:Open Source License
private void refreshGUI() { if (result.length == 1) { IComparisonItem soloResult = result[0]; // Setting source & target release in a null safe way if (soloResult.getSource() instanceof IVersionable) { IVersionable<?> srcVersion = (IVersionable<?>) soloResult.getSource(); sourceText.setText(srcVersion.getVersion().getLabel() + " - " + srcVersion.getVersion().getStatus().getLabel()); }/*from w ww. j a v a2s. c o m*/ if (soloResult.getTarget() instanceof IVersionable) { IVersionable<?> tgtVersion = (IVersionable<?>) soloResult.getTarget(); targetText.setText(tgtVersion.getVersion().getLabel() + " - " + tgtVersion.getVersion().getStatus().getLabel()); } } else { sourceText.setText("Comparing a set of source items"); targetText.setText("Comparing a set of target items"); } // Setting proper button action if (diffOnlyFlag) { diffOnlyButton.setText("Show all hierarchy"); } else { diffOnlyButton.setText("Show differences only"); } sourceTree.removeAll(); TreeItem srcRoot = new TreeItem(sourceTree, SWT.NONE); srcRoot.setText("Comparison results..."); //result.getSource().toString()); srcRoot.setImage(VCSImages.ICON_DIFF); //generateViewer(result,srcRoot); ProgressMonitorDialog pd = new ProgressMonitorDialog(this.getShell()); try { pd.run(true, false, new GenerationProgress(srcRoot, result)); } catch (Exception e) { throw new ErrorException(e); } srcRoot.setExpanded(true); }
From source file:com.nextep.designer.vcs.ui.controllers.MergeController.java
License:Open Source License
/** * @see com.nextep.datadesigner.gui.model.InvokableController#invoke(java.lang.Object) *//* w w w . j ava2 s .c om*/ @Override public Object invoke(Object... model) { if (model.length == 0) { throw new ErrorException("The merge controller need at least 1 non-null argument to proceed."); } else { final IVersionable<?> versionable = (IVersionable<?>) model[0]; final MergeWizard wiz = new MergeWizard(new MergeInitGUI(versionable), new MergePreviewWizard(versionable)); wiz.setToVersionable(versionable); WizardDialog w = new WizardDialog( VCSUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(), wiz); w.setBlockOnOpen(true); w.open(); if (w.getReturnCode() != Window.CANCEL) { // FIXME QUICKFIX calling this static method => TO remove !!! MergeStrategy.setIsGenerating(false); // try { final IMerger m = MergerFactory.getMerger(wiz.getToRelease()); // Building compare command ICommand compareCommand = new ICommand() { @Override public Object execute(Object... parameters) { return m.compare(wiz.getReference(), wiz.getFromRelease(), wiz.getToRelease(), true); } @Override public String getName() { return "Computing differences between " + wiz.getToRelease().getLabel() + " and " + wiz.getFromRelease().getLabel(); } }; final IComparisonItem comp = (IComparisonItem) CommandProgress.runWithProgress(compareCommand) .iterator().next(); ProgressMonitorDialog pd = new ProgressMonitorDialog( VCSUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell()); try { pd.run(true, false, new MergeProgress(comp, m)); } catch (Exception e) { throw new ErrorException(e); } // } finally { MergeStrategy.setIsGenerating(true); // } MergeResultGUI mergeGUI = new MergeResultGUI(true, comp); mergeGUI.setIsRepositoryMerge(true); mergeGUI.setRootText( "Source release " + wiz.getFromRelease().getLabel() + " [" + wiz.getFromRelease().getBranch().getName() + "]", "Current target release " + wiz.getToRelease().getLabel() + " [" + wiz.getToRelease().getBranch().getName() + "]", "Merge result"); boolean doItAgain = true; while (doItAgain) { invokeGUI(new GUIWrapper(mergeGUI, "Merge results", 800, 600)); // Checking that everything is resolved if (comp.getMergeInfo().getStatus() != MergeStatus.MERGE_RESOLVED) { // IF not we ask if the user would like to edit again doItAgain = MessageDialog.openQuestion( VCSUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(), VCSUIMessages.getString("mergeUnresolvedTitle"), VCSUIMessages.getString("mergeUnresolved")); if (!doItAgain) { throw new CancelException("Merge operation aborted due to unresolved conflicts."); } } else { doItAgain = false; } } // We fall here if no cancel exception // HibernateUtil.getInstance().getSession().clear(); // IdentifiableDAO.getInstance().loadAll(VersionReference.class); HibernateUtil.getInstance().clearAllSessions(); pd = new ProgressMonitorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); try { pd.run(false, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Merge in progress...", 5); // Global listeners switch off Observable.deactivateListeners(); // Refreshing progress monitor.worked(1); IVersionable<?> mergedObject = null; try { // Building the merge result final String activityText = "Merged " + wiz.getFromRelease().getLabel() + " -> " + wiz.getFromRelease().getBranch().getName(); final IVersioningService versioningService = VCSPlugin .getService(IVersioningService.class); final IActivity mergeActivity = versioningService.createActivity(activityText); mergedObject = (IVersionable<?>) m.buildMergedObject(comp, mergeActivity); // Checking if the merge did anything if (mergedObject instanceof IVersionable<?>) { if (((IVersionable<?>) mergedObject).getVersion() .getStatus() == IVersionStatus.CHECKED_IN) { final boolean forceMerge = MessageDialog.openQuestion( Display.getCurrent().getActiveShell(), VCSUIMessages.getString("mergeDidNothingTitle"), VCSUIMessages.getString("mergeDidNothing")); if (forceMerge) { comp.getMergeInfo().setMergeProposal(null); mergedObject = (IVersionable<?>) m.buildMergedObject(comp, mergeActivity); } else { return; } } } } finally { Observable.activateListeners(); } log.info("Merged successfully!"); // Refreshing progress monitor.worked(1); monitor.setTaskName("Updating view contents..."); // Temporary bugfix for DES-710 // TODO refactor EVERYTHING as a service final Session session = HibernateUtil.getInstance().getSandBoxSession(); // FIXME draft of view removal / addition of the merged object // Switching versionables (for database only) IVersionContainer parent = versionable.getContainer(); // First removing current versionable in current session parent.getContents().remove(versionable); versionable.setContainer(null); // Forcing save of module without parent final IIdentifiableDAO identifiableDao = CorePlugin.getIdentifiableDao(); identifiableDao.save(parent); // Refreshing progress monitor.worked(1); // Reloading parent container in sandbox (because merged object is in // sandbox) if (parent instanceof IWorkspace) { parent = (IVersionContainer) identifiableDao.load(Workspace.class, parent.getUID(), session, false); } else { parent = (IVersionContainer) identifiableDao.load(IVersionable.class, parent.getUID(), session, false); } // Refreshing progress monitor.worked(1); monitor.setTaskName("Committing to repository..."); // Adding sandbox merged object mergedObject.setContainer(parent); parent.getContents().add(mergedObject); // Saving to sandbox before reloading view identifiableDao.save(mergedObject); session.flush(); // ************** // DES-710 urgent workaround // Hibernate does not properly send the INSERT statements to the db // But logs it properly in the logs ! final IRepositoryService repositoryService = CorePlugin.getRepositoryService(); final IDatabaseConnector connector = repositoryService.getRepositoryConnector(); final IConnection repositoryConnection = repositoryService.getRepositoryConnection(); Connection conn = null; PreparedStatement stmt = null; try { conn = connector.connect(repositoryConnection); String insertSql = null; if (parent instanceof IWorkspace) { insertSql = "INSERT INTO REP_VIEW_CONTENTS (VIEW_ID,VERSION_ID) VALUES (?,?)"; //$NON-NLS-1$ } else { insertSql = "INSERT INTO REP_MODULE_CONTENTS (MODULE_ID,VERSION_ID) VALUES (?,?)"; //$NON-NLS-1$ } stmt = conn.prepareStatement(insertSql); stmt.setLong(1, parent.getUID().rawId()); stmt.setLong(2, mergedObject.getUID().rawId()); stmt.execute(); if (!conn.getAutoCommit()) { conn.commit(); } } catch (SQLException e) { log.error(e); } finally { if (stmt != null) { try { stmt.close(); } catch (SQLException e) { log.error(e); } } if (conn != null) { try { conn.close(); } catch (SQLException e) { log.error(e); } } } // End of DES-710 workaround // ************** // HibernateUtil.getInstance().reconnectAll(); // Merger.save(mergedObject); // Merger.save(parent); monitor.worked(1); log.info("Please wait while view is reloading..."); monitor.setTaskName("Finished: Reloading view..."); monitor.done(); // END OF the fixme part } }); } catch (Exception e) { throw new ErrorException(e); } // Restoring a new view log.info("Refreshing current view"); VersionUIHelper.changeView(VersionHelper.getCurrentView().getUID()); // Designer.getInstance().invokeSelection("com.neXtep.designer.vcs.SelectionInvoker", // "version.compare", comp); } } return null; }