/** * Shows JFace ErrorDialog but improved by constructing full stack trace in detail area. * * @return true if OK was pressed */ public static boolean showErrorDialogWithStackTrace(String msg, Throwable throwable) { // Temporary holder of child statuses List<Status> childStatuses = new ArrayList<>(); for (StackTraceElement stackTraceElement : throwable.getStackTrace()) { childStatuses.add(new Status(IStatus.ERROR, "N4js-plugin-id", stackTraceElement.toString())); } MultiStatus ms = new MultiStatus("N4js-plugin-id", IStatus.ERROR, childStatuses.toArray(new Status[] {}), // convert to array of statuses throwable.getLocalizedMessage(), throwable); final AtomicBoolean result = new AtomicBoolean(true); Display.getDefault() .syncExec( () -> result.set( ErrorDialog.openError(null, "Error occurred while organizing ", msg, ms) == Window.OK)); return result.get(); }
/** * Notify error using message box (thread safe). * @param message The message to display * @param error The error that occurred */ public void notifyError ( final String message, final Throwable error ) { final Display display = getWorkbench ().getDisplay (); if ( !display.isDisposed () ) { display.asyncExec ( new Runnable () { @Override public void run () { final Shell shell = getWorkbench ().getActiveWorkbenchWindow ().getShell (); logger.debug ( "Shell disposed: {}", shell.isDisposed () ); if ( !shell.isDisposed () ) { final IStatus status = new OperationStatus ( IStatus.ERROR, PLUGIN_ID, 0, message + ":" + error.getMessage (), error ); ErrorDialog.openError ( shell, null, message, status ); } } } ); } }
@Override public void setVisible ( final boolean visible ) { super.setVisible ( visible ); if ( visible ) { try { getContainer ().run ( false, false, new IRunnableWithProgress () { @Override public void run ( final IProgressMonitor monitor ) throws InvocationTargetException, InterruptedException { setMergeResult ( PreviewPage.this.mergeController.merge ( wrap ( monitor ) ) ); } } ); } catch ( final Exception e ) { final Status status = new Status ( IStatus.ERROR, Activator.PLUGIN_ID, Messages.PreviewPage_StatusErrorFailedToMerge, e ); StatusManager.getManager ().handle ( status ); ErrorDialog.openError ( getShell (), Messages.PreviewPage_TitleErrorFailedToMerge, Messages.PreviewPage_MessageErrorFailedToMerge, status ); } } }
private void showError ( final IStatus status ) { if ( !status.matches ( IStatus.ERROR ) ) { return; } final Display display = PlatformUI.getWorkbench ().getDisplay (); if ( !display.isDisposed () ) { display.asyncExec ( new Runnable () { @Override public void run () { if ( !display.isDisposed () ) { ErrorDialog.openError ( PlatformUI.getWorkbench ().getActiveWorkbenchWindow ().getShell (), "Connection error", "Connection failed", status, IStatus.ERROR ); } } } ); } }
protected void handleRemove () { final MultiStatus ms = new MultiStatus ( Activator.PLUGIN_ID, 0, "Removing key providers", null ); for ( final KeyProvider provider : this.selectedProviders ) { try { this.factory.remove ( provider ); } catch ( final Exception e ) { ms.add ( StatusHelper.convertStatus ( Activator.PLUGIN_ID, e ) ); } } if ( !ms.isOK () ) { ErrorDialog.openError ( getShell (), "Error", null, ms ); } }
protected void handleAdd () { final FileDialog dlg = new FileDialog ( getShell (), SWT.OPEN ); final String result = dlg.open (); if ( result != null ) { try { this.factory.addFile ( result ); } catch ( final Exception e ) { ErrorDialog.openError ( getShell (), "Error", "Failed to add file", StatusHelper.convertStatus ( Activator.PLUGIN_ID, e ) ); } } }
private void createPlot(AxisConfiguration conf) { if (conf==null) return; IDataset image = null; if (conf.getMicroscopeImage()!=null && !"".equals(conf.getMicroscopeImage())) { try { image = ServiceHolder.getLoaderService().getDataset(conf.getMicroscopeImage(), null); } catch (Exception ne) { final File file = new File(conf.getMicroscopeImage()); ErrorDialog.openError(site.getShell(), "Problem Reading '"+file.getName()+"'", "There was a problem reading '"+file.getName()+"'\n\n" + "Please contact our support representative.", new Status(IStatus.ERROR, Activator.PLUGIN_ID, ne.getMessage(), ne)); logger.error("Cannot read file!", ne); } } if (image==null && conf.isRandomNoise()) { image = Random.rand(4096, 3012); } if (image==null) { system.getSelectedXAxis().setRange(conf.getFastAxisStart(), conf.getFastAxisEnd()); system.getSelectedYAxis().setRange(conf.getSlowAxisStart(), conf.getSlowAxisEnd()); return; } createTrace(conf, image); }
/** * Stash using appropriate messages to the user. * @param models * @param shell */ @Override public void save(Object object) { try { if (file.exists()) { boolean ok = MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), "Confirm Overwrite", "Are you sure that you would like to overwrite '"+file.getName()+"'?"); if (!ok) return; } stash(object); } catch (Exception e) { ErrorDialog.openError(Display.getCurrent().getActiveShell(), "Error Saving Information", "An exception occurred while writing the "+getStashName()+" to file.", new Status(IStatus.ERROR, "org.eclipse.scanning.device.ui", e.getMessage())); logger.error("Error Saving Information", e); } }
public static void openQueueMonitor(Class<? extends StatusBean> beanClass, final String queueName, final String topicName, final String submissionQueueName, String partName) throws PartInitException, UnsupportedEncodingException { String bundle = FrameworkUtil.getBundle(beanClass).getSymbolicName(); String bean = beanClass.getName(); String sqn = queueName; String stn = topicName; String submit = submissionQueueName; String queueViewId = QueueViews.createSecondaryId(CommandConstants.getScanningBrokerUri(), bundle,bean, sqn, stn, submit); if (partName!=null) queueViewId = queueViewId+"partName="+partName; try { PageUtil.getPage().showView(QueueViews.getQueueViewID(), queueViewId, IWorkbenchPage.VIEW_ACTIVATE); } catch (PartInitException e) { ErrorDialog.openError(Display.getDefault().getActiveShell(), "Cannot open view", "Cannot open view "+queueViewId, new Status(Status.ERROR, "org.eclipse.scanning.event.ui", e.getMessage())); throw e; } }
private void openQueueMonitor() throws UnsupportedEncodingException { final IPreferenceStore store = Activator.getDefault().getPreferenceStore(); String bundle = store.getString(BUNDLE); String bean = store.getString(BEAN); String sqn = store.getString(STATUS_QUEUE); String stn = store.getString(STATUS_TOPIC); String submit = store.getString(SUBMIT_QUEUE); String part = store.getString(PART_NAME); String queueViewId = QueueViews.createSecondaryId(bundle,bean, sqn, stn, submit); queueViewId = queueViewId+"partName="+part; try { Util.getPage().showView(StatusQueueView.ID, queueViewId, IWorkbenchPage.VIEW_VISIBLE); } catch (PartInitException e) { ErrorDialog.openError(Display.getDefault().getActiveShell(), "Cannot open view", "Cannot open view "+queueViewId, new Status(Status.ERROR, "org.eclipse.scanning.event.ui", e.getMessage())); logger.error("Cannot open view", e); } }
protected void togglePausedConsumer(IAction pauseConsumer) { // The button can get out of sync if two clients are used. final boolean currentState = queueConnection.isQueuePaused(getSubmissionQueueName()); try { pauseConsumer.setChecked(!currentState); // We are toggling it. IPublisher<PauseBean> pauser = service.createPublisher(getUri(), IEventService.CMD_TOPIC); pauser.setStatusSetName(IEventService.CMD_SET); // The set that other clients may check pauser.setStatusSetAddRequired(true); PauseBean pbean = new PauseBean(); pbean.setQueueName(getSubmissionQueueName()); // The queue we are pausing pbean.setPause(pauseConsumer.isChecked()); pauser.broadcast(pbean); } catch (Exception e) { ErrorDialog.openError(getViewSite().getShell(), "Cannot pause queue "+getSubmissionQueueName(), "Cannot pause queue "+getSubmissionQueueName()+"\n\nPlease contact your support representative.", new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage())); } pauseConsumer.setChecked(queueConnection.isQueuePaused(getSubmissionQueueName())); }
private List<IResultHandler> getResultsHandlers() { if (resultsHandlers == null) { final IConfigurationElement[] configElements = Platform.getExtensionRegistry() .getConfigurationElementsFor(RESULTS_HANDLER_EXTENSION_POINT_ID); final List<IResultHandler> handlers = new ArrayList<>(configElements.length + 1); for (IConfigurationElement configElement : configElements) { try { final IResultHandler handler = (IResultHandler) configElement.createExecutableExtension("class"); handler.init(service, createConsumerConfiguration()); handlers.add(handler); } catch (Exception e) { ErrorDialog.openError(getSite().getShell(), "Internal Error", "Could not create results handler for class " + configElement.getAttribute("class") + ".\n\nPlease contact your support representative.", new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage())); } } handlers.add(new DefaultResultsHandler()); resultsHandlers = handlers; } return resultsHandlers; }
/** * You can override this method to provide custom opening of * results if required. * * @param bean */ protected void openResults(StatusBean bean) { if (bean == null) return; for (IResultHandler handler : getResultsHandlers()) { if (handler.isHandled(bean)) { try { boolean ok = handler.open(bean); if (ok) return; } catch (Exception e) { ErrorDialog.openError(getSite().getShell(), "Internal Error", handler.getErrorMessage(null), new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage())); } } } }
private void rerun(StatusBean bean) { try { final DateFormat format = DateFormat.getDateTimeInstance(); boolean ok = MessageDialog.openQuestion(getViewSite().getShell(), "Confirm resubmission "+bean.getName(), "Are you sure you want to rerun "+bean.getName()+" submitted on "+format.format(new Date(bean.getSubmissionTime()))+"?"); if (!ok) return; final StatusBean copy = bean.getClass().newInstance(); copy.merge(bean); copy.setUniqueId(UUID.randomUUID().toString()); copy.setMessage("Rerun of "+bean.getName()); copy.setStatus(org.eclipse.scanning.api.event.status.Status.SUBMITTED); copy.setPercentComplete(0.0); copy.setSubmissionTime(System.currentTimeMillis()); queueConnection.submit(copy, true); reconnect(); } catch (Exception e) { ErrorDialog.openError(getViewSite().getShell(), "Cannot rerun "+bean.getName(), "Cannot rerun "+bean.getName()+"\n\nPlease contact your support representative.", new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage())); } }
@Override public void mouseUp(MouseEvent e) { if (e.getSource() instanceof Button) { Button sel = (Button) e.getSource(); if (sel.getText().equalsIgnoreCase("Save")) { try { String tempText = util.processAdd(isEdit, editName, comp, type, editor.getDocumentProvider().getDocument(getEditorInput()).get()); editor.getDocumentProvider().getDocument(getEditorInput()).set(tempText); createPage1(); setActivePage(1); } catch (JAXBException ex) { ErrorDialog.openError(getSite().getShell(), "Error removing item", null, new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, 0, "Error removing item", null)); } } } }
@Override public void mouseUp(MouseEvent e) { if (e.getSource() instanceof Button) { Button sel = (Button) e.getSource(); if (sel.getText().equalsIgnoreCase("Save")) { try { String tempText = sUtil.processAdd(isEdit, editName, comp, type, editor.getDocumentProvider().getDocument(getEditorInput()).get()); editor.getDocumentProvider().getDocument(getEditorInput()).set(tempText); createPage1(); setActivePage(1); } catch (JAXBException ex) { ErrorDialog.openError(getSite().getShell(), "Error removing item", null, new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, 0, "Error removing item", null)); } } } }
public static void errorDialogWithStackTrace(String msg, Throwable t) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); t.printStackTrace(pw); final String trace = sw.toString(); // stack trace as a string // Temp holder of child statuses List<Status> childStatuses = new ArrayList<>(); // Split output by OS-independend new-line for (String line : trace.split(System.getProperty("line.separator"))) { // build & add status childStatuses.add(new Status(IStatus.ERROR, "Journal", line)); } MultiStatus ms = new MultiStatus("Journal", IStatus.ERROR, childStatuses.toArray(new Status[] {}), // convert // to // array // of // statuses t.getLocalizedMessage(), t); ErrorDialog.openError(null, "Error", msg, ms); }
@Override public void run(final IAction action) { try { ClientTelemetryHelper.sendRunActionEvent(this); doRun(action); } catch (final Throwable t) { final String className = this.getClass().getName(); final String messageFormat = Messages.getString("TeamExplorerBaseAction.ErrorRunningActionFormat"); //$NON-NLS-1$ final String message = MessageFormat.format(messageFormat, className); log.error(message, t); ErrorDialog.openError( getShell(), Messages.getString("TeamExplorerBaseAction.ErrorDialogTitle"), //$NON-NLS-1$ message, new Status(IStatus.ERROR, TFSCommonUIClientPlugin.PLUGIN_ID, 0, null, t)); } }
private void asyncLoadTargetCandidates(final String sourcePath) { final Shell shell = getShell(); shell.getDisplay().asyncExec(new Runnable() { @Override public void run() { if (shell != null && !shell.isDisposed()) { final QueryTargetCandidatesCommand loadTargetsCommand = new QueryTargetCandidatesCommand(shell); final ICommandExecutor commandExecutor = UICommandExecutorFactory.newWizardCommandExecutor(getContainer()); commandExecutor.setCommandFinishedCallback(loadTargetsCommand); final IStatus status = commandExecutor.execute(loadTargetsCommand); if (status.getSeverity() == IStatus.ERROR) { ErrorDialog.openError( shell, Messages.getString("SelectMergeSourceTargetWizardPage.ErrorDialogTitle"), //$NON-NLS-1$ null, status); } } }; }); }
@Override protected void okPressed() { final ICommand saveCommand = new ResourceChangingCommand(new SaveCompareInputCommand(input)); final IStatus status = new CommandExecutor().execute(saveCommand); if (status.isOK()) { /* * If the input is our CustomCompareEditorInput, then call the * setOkPressed method. Otherwise, this is a 3.2-style * CompareEditorInput from Eclipse (which did not have the * okPressed() method), so just do a noop. */ if (input instanceof CustomCompareEditorInput) { ((CustomCompareEditorInput) input).setOKPressed(); } super.okPressed(); } else { ErrorDialog.openError(getShell(), Messages.getString("CompatibleCompareDialog.DialogTitle"), null, status); //$NON-NLS-1$ } }
@Override public final void run(final IAction action) { try { ClientTelemetryHelper.sendRunActionEvent(this); doRun(action); } catch (final Throwable t) { final String messageFormat = Messages.getString("ExtendedAction.ErrorDialogTitleFormat"); //$NON-NLS-1$ final String message = MessageFormat.format(messageFormat, getName()); LogFactory.getLog(this.getClass()).error(message, t); /* TODO: use StatusHelper here */ ErrorDialog.openError( getShell(), message, null, new Status(IStatus.ERROR, TFSCommonUIClientPlugin.PLUGIN_ID, 0, getErrorMessage(), t)); } }
@Override public void reportNonOKVisitorStatus(final IStatus status) { if (status.isOK()) { return; } Display.getDefault().asyncExec(new Runnable() { @Override public void run() { final Shell shell = ShellUtils.getBestParent(ShellUtils.getWorkbenchShell()); ErrorDialog.openError( shell, Messages.getString("TFSResourceChangeUiProvider.VisitorErrorTitle"), //$NON-NLS-1$ null, status); } }); }
private void handleAction(String problemType) { Optional<BookmarkProblem> bookmarkProblem = bookmarkProblems.getBookmarkProblem(bookmarkId, problemType); if (!bookmarkProblem.isPresent()) { return; } Optional<IBookmarkProblemHandler> handler = bookmarkProblems .getBookmarkProblemDescriptor(bookmarkProblem.get().getProblemType()).getBookmarkProblemHandler(); if (!handler.isPresent()) { return; } try { handler.get().handleAction(bookmarkProblem.get()); } catch (BookmarksException e) { ErrorDialog.openError(null, "Error", "Could not solve bookmark problem", e.getStatus()); } }
protected void handleOpen(OpenEvent event) { if (showLineMatches()) { Object firstElement= ((IStructuredSelection)event.getSelection()).getFirstElement(); if (firstElement instanceof IFile) { if (getDisplayedMatchCount(firstElement) == 0) { try { open(getSite().getPage(), (IFile)firstElement, false); } catch (PartInitException e) { ErrorDialog.openError(getSite().getShell(), SearchMessages.FileSearchPage_open_file_dialog_title, SearchMessages.FileSearchPage_open_file_failed, e.getStatus()); } return; } } } super.handleOpen(event); }
/** * Opens an error dialog presenting the user with the specified message and * throwable * * @param message * @param throwable */ protected static void reportError(String message, Throwable throwable) { IStatus status = null; if (throwable instanceof CoreException) { status = ((CoreException) throwable).getStatus(); } else { status = new Status(IStatus.ERROR, JSBuildFileUIPlugin.PLUGIN_ID, 0, message, throwable); } ErrorDialog .openError( JSBuildFileUIPlugin.getActiveWorkbenchWindow() .getShell(), JSBuildFileLaunchConfigurationMessages.AntLaunchShortcut_Error_7, JSBuildFileLaunchConfigurationMessages.AntLaunchShortcut_Build_Failed_2, status); }
private void OpenEditor(IFile file) { if(file == null) return; try { IWorkbenchPage page = getWorkbenchPage(); if(page != null) IDE.openEditor(page, file, true); } catch(CoreException e) { String title = Policy.bind("OpenEditorAction.errorTitle"); String message = Policy.bind("OpenEditorAction.errorMessage"); ErrorDialog.openError(getViewSite().getShell(), title, message, e.getStatus()); } }
/** * This method logs an error and prints out a (hopefully helpful) dialog to * the user in an error dialog before closing the editor. * * @param logMessage * The message to print to the log. * @param dialogMessage * The message to show to the user. * @param e * The exception, or {@code null} if not available. */ private void throwCriticalException(String logMessage, String dialogMessage, Exception e) { // Log an error. logger.error(getClass().getName() + " Exception! " + logMessage, e); final Shell shell = getEditorSite().getShell(); // Print out an error dialog. final Status status = new Status(IStatus.ERROR, "org.eclipse.ice", 0, logMessage, e); final String message = dialogMessage; shell.getDisplay().asyncExec(new Runnable() { @Override public void run() { // Open an error dialog. ErrorDialog.openError(shell, "Visualization Failed", message, status); // Close the editor. getEditorSite().getPage().closeEditor(PlotEditor.this, false); }; }); return; }
@Override public void run() { Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); DirectoryDialog dialog = new DirectoryDialog(shell, SWT.OPEN); dialog.setMessage("Select the configuration folder of the openHAB runtime"); String selection = dialog.open(); if(selection!=null) { try { File file = new File(selection); if(isValidConfigurationFolder(file)) { ConfigurationFolderProvider.saveFolderToPreferences(selection); ConfigurationFolderProvider.setRootConfigurationFolder(new File(selection)); viewer.setInput(ConfigurationFolderProvider.getRootConfigurationFolder()); } else { MessageDialog.openError(shell, "No valid configuration directory", "The chosen directory is not a valid openHAB configuration" + " directory. Please choose a different one."); } } catch (CoreException e) { IStatus status = new Status(IStatus.ERROR, UIActivator.PLUGIN_ID, "An error occurred while opening the configuration folder", e); ErrorDialog.openError(shell, "Cannot open configuration folder!", null, status); } } }
public void run(IAction action) { AddResourcesToClientBundleDialog dlg = new AddResourcesToClientBundleDialog( getShell(), project, clientBundleType, files); if (dlg.open() != Window.OK) { return; } IType clientBundle = dlg.getClientBundleType(); try { // Update the type and open it addResourcesToClientBundle(clientBundle, dlg.getResources()); ResourceUtils.openInDefaultEditor(getShell(), (IFile) clientBundle.getResource(), true); } catch (CoreException e) { ErrorDialog.openError( getShell(), "Error Adding Resources", "One or more selected resources could not be added to the ClientBundle.", e.getStatus()); } }
public void saveWithoutDeploying() { try { saveParFile(createParBytes(getProjectClasspathUrls())); } catch (Exception e) { Logger.logError(e); ErrorDialog dialog = new ErrorDialog(shell, "Unexpected Exception While Saving", "An exception happened while saving the process definition archive", new Status( Status.ERROR, ActivitiPlugin.getDefault().getBundle() .getSymbolicName(), Status.ERROR, "An unexpected exception caused the save operation to fail", e), Status.ERROR); dialog.open(); } }
/** * Creates a new text editor for the messages bundle, which gets added to a new page */ protected void createMessagesBundlePage(MessagesBundle messagesBundle) { try { IMessagesResource resource = messagesBundle.getResource(); final TextEditor textEditor = (TextEditor) resource.getSource(); int index = addPage(textEditor, textEditor.getEditorInput()); setPageText(index, UIUtils.getDisplayName(messagesBundle.getLocale())); setPageImage(index, UIUtils.getImage(UIUtils.IMAGE_PROPERTIES_FILE)); localesIndex.add(messagesBundle.getLocale()); textEditorsIndex.add(textEditor); } catch (PartInitException e) { ErrorDialog.openError(getSite().getShell(), "Error creating text editor page.", //$NON-NLS-1$ null, e.getStatus()); } }
/** * Creates a new folder resource in the selected container and with the * selected name. Creates any missing resource containers along the path; * does nothing if the container resources already exist. * <p> * In normal usage, this method is invoked after the user has pressed Finish * on the wizard; the enablement of the Finish button implies that all * controls on this page currently contain valid values. * </p> * <p> * Note that this page caches the new folder once it has been successfully * created; subsequent invocations of this method will answer the same * folder resource without attempting to create it again. * </p> * <p> * This method should be called within a workspace modify operation since it * creates resources. * </p> * * @return the created folder resource, or <code>null</code> if the folder * was not created */ public IFolder createNewFolder(String containerName, String folderName, IProgressMonitor monitor) { // create the new folder and cache it if successful final IPath containerPath = new Path(containerName); IPath newFolderPath = containerPath.append(folderName); final IFolder newFolderHandle = createFolderHandle(newFolderPath); AbstractOperation op; op = new CreateFolderOperation(newFolderHandle, null, false, null, "New Folder"); try { op.execute(monitor, WorkspaceUndoUtil.getUIInfoAdapter(getShell())); } catch (final ExecutionException e) { getContainer().getShell().getDisplay().syncExec( new Runnable() { public void run() { if (e.getCause() instanceof CoreException) { ErrorDialog.openError(getContainer().getShell(), "Creation Problems", null, ((CoreException) e.getCause()).getStatus()); } else { MessageDialog.openError(getContainer().getShell(), "Creation problems", NLS.bind("Eclipse Internal error: {0}", e.getCause().getMessage())); } } }); } return newFolderHandle; }
/** * Opens an error dialog if necessary. Takes care of complex rules necessary for making the error dialog look nice. */ private void openError(final IStatus status) { if (status == null) { return; } final String genericTitle = WorkbenchNavigatorMessages.DropAdapter_title; final int codes = IStatus.ERROR | IStatus.WARNING; // simple case: one error, not a multistatus if (!status.isMultiStatus()) { ErrorDialog.openError(getShell(), genericTitle, null, status, codes); return; } // one error, single child of multistatus final IStatus[] children = status.getChildren(); if (children.length == 1) { ErrorDialog.openError(getShell(), status.getMessage(), null, children[0], codes); return; } // several problems ErrorDialog.openError(getShell(), genericTitle, null, status, codes); }
/** * Creates a status dialog using the given {@code status} and {@code title}. * * @param title of the dialog * @param status to derive the severity */ public static void statusDialog(String title, IStatus status) { Shell shell = getActiveWorkbenchWindow().getShell(); if (shell != null) { switch (status.getSeverity()) { case IStatus.ERROR: ErrorDialog.openError(shell, title, null, status); break; case IStatus.WARNING: MessageDialog.openWarning(shell, title, status.getMessage()); break; case IStatus.INFO: MessageDialog.openInformation(shell, title, status.getMessage()); break; } } }
private static void promptForCommitInsideDisplayThread(Shell shell, Optional<String> name) { InputDialog dialog = new InputDialog( shell, "Commit Message", "Please enter a commit message" + name.map(n -> " for the diagram: " + n).orElse(StringUtils.EMPTY) + ".", StringUtils.EMPTY, EditorLauncherBase::isValidCommitMessage); dialog.setBlockOnOpen(true); if (dialog.open() != InputDialog.OK) { return; } String commitMessage = dialog.getValue(); try { transformationManager.handleEditorMerge(commitMessage); } catch (CommitException e) { LOGGER.error("Failed to merge branch into master.", e); ErrorDialog.openError(shell, "Commit failed", "The requested commit failed. " + "The changes stay in the temporary branch but will not appear on the master branch.", new Status(Status.ERROR, null, "Merging of branches failed.", e)); } }
/** * Opens an error dialog if necessary. Takes care of complex rules necessary for making the error dialog look nice. * * @param status * the status */ private void openError(IStatus status) { if (status == null) { return; } String genericTitle = WorkbenchNavigatorMessages.DropAdapter_title; int codes = IStatus.ERROR | IStatus.WARNING; // simple case: one error, not a multistatus if (!status.isMultiStatus()) { ErrorDialog.openError(getShell(), genericTitle, null, status, codes); return; } // one error, single child of multistatus IStatus[] children = status.getChildren(); if (children.length == 1) { ErrorDialog.openError(getShell(), status.getMessage(), null, children[0], codes); return; } // several problems ErrorDialog.openError(getShell(), genericTitle, null, status, codes); }
protected void perform(CoreException e, Shell shell, String title, String message) { /* * if (!Activator.getDefault().getPreferenceStore().getBoolean( * PreferenceConstants.RESOURCE_SHOW_ERROR_INVALID_RESOURCE_NAME) && isInvalidResouceName(e)) { return; } */ IdeLog.logError(FormatterUIEplPlugin.getDefault(), e, IDebugScopes.DEBUG); IStatus status = e.getStatus(); if (status != null) { ErrorDialog.openError(shell, title, message, status); } else { displayMessageDialog(e, e.getMessage(), shell, title, message); } }
/** * Shows an error dialog based on the supplied arguments. * @param shell the shell * @param exception the core exception * @param msgKey key to the plugin message text */ public static void showErrorDialog( Shell shell, Exception exception, String msgKey) { exception.printStackTrace(); IStatus status = new Status( IStatus.ERROR, MessagesEditorPlugin.PLUGIN_ID, 0, MessagesEditorPlugin.getString(msgKey) + " " //$NON-NLS-1$ + MessagesEditorPlugin.getString("error.seeLogs"), //$NON-NLS-1$ exception); ErrorDialog.openError( shell, MessagesEditorPlugin.getString(msgKey), exception.getLocalizedMessage(), status); }