下面列出了org.eclipse.ui.internal.ide.StatusUtil#org.eclipse.jface.dialogs.ErrorDialog 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Executes the merge in a separate minimal working copy.
*
* @throws InterruptedException
* @throws InvocationTargetException
* @throws SvnClientException
*/
private void mergeInMinimalWorkingCopy() throws InvocationTargetException, InterruptedException {
LogUtil.entering();
final ProgressMonitorDialog pmd = new ProgressMonitorDialog(shellProvider.getShell());
Dashboard.setShellProgressMonitorDialog(pmd);
pmd.run(true, true, monitor -> {
try {
boolean cancelled = MergeProcessorUtil.merge(pmd, monitor, configuration, mergeUnit);
if (cancelled) {
mergeUnit.setStatus(MergeUnitStatus.CANCELLED);
MergeProcessorUtil.canceled(mergeUnit);
} else {
mergeUnit.setStatus(MergeUnitStatus.DONE);
}
} catch (Throwable e) {
pmd.getShell().getDisplay().syncExec(() -> {
MultiStatus status = createMultiStatus(e);
ErrorDialog.openError(pmd.getShell(), "Error dusrching merge process",
"An Exception occured during the merge process. The merge didn't run successfully.",
status);
});
}
});
LogUtil.exiting();
}
/**
* See {@link ILaunchShortcut2#getLaunchConfigurations(ISelection)} for contract.
* @param file
* @return
*/
private ILaunchConfiguration[] getLaunchConfigurations(File file) {
if (file == null || !canLaunch(file)) {
return null;
}
try {
ILaunchConfiguration[] existing = Arrays.stream(launchManager.getLaunchConfigurations(configType))
.filter(launchConfig -> match(launchConfig, file)).toArray(ILaunchConfiguration[]::new);
if (existing.length != 0) {
return existing;
}
return new ILaunchConfiguration[0];
} catch (CoreException e) {
ErrorDialog.openError(Display.getDefault().getActiveShell(), "error", e.getMessage(), e.getStatus()); //$NON-NLS-1$
Activator.getDefault().getLog().log(e.getStatus());
}
return new ILaunchConfiguration[0];
}
@Override
protected void handleOpen(OpenEvent event) {
Object firstElement = ((IStructuredSelection) event.getSelection()).getFirstElement();
if (getDisplayedMatchCount(firstElement) == 0) {
try {
if (firstElement instanceof IAdaptable) {
IAdaptable iAdaptable = (IAdaptable) firstElement;
IFile file = iAdaptable.getAdapter(IFile.class);
if (file != null) {
open(getSite().getPage(), file, false);
}
}
} catch (PartInitException e) {
ErrorDialog.openError(getSite().getShell(),
"Open File",
"Opening the file failed.", e.getStatus());
}
return;
}
super.handleOpen(event);
}
public void launchWithParameters(ILaunchConfiguration configuration, String mode, ILaunch launch,
IProgressMonitor monitor, Map<String, Object> param, File debugAdapter) throws CoreException {
try {
List<String> debugCmdArgs = Collections.singletonList(debugAdapter.getAbsolutePath());
DSPLaunchDelegateLaunchBuilder builder = new DSPLaunchDelegateLaunchBuilder(configuration, mode, launch,
monitor);
builder.setLaunchDebugAdapter(InitializeLaunchConfigurations.getNodeJsLocation(), debugCmdArgs);
builder.setMonitorDebugAdapter(configuration.getAttribute(DSPPlugin.ATTR_DSP_MONITOR_DEBUG_ADAPTER, false));
builder.setDspParameters(param);
super.launch(builder);
} catch (Exception e) {
IStatus errorStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
Activator.getDefault().getLog().log(errorStatus);
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
ErrorDialog.openError(Display.getDefault().getActiveShell(), "Debug error", e.getMessage(), errorStatus); //$NON-NLS-1$
}
});
}
}
/**
* @see org.eclipse.debug.ui.console.IConsoleHyperlink#linkActivated()
*/
@Override
public void linkActivated() {
JSStackTraceLocationText locationText;
try {
String linkText = getLinkText();
locationText = new JSStackTraceLocationText(linkText);
} catch (CoreException e1) {
ErrorDialog.openError(
N4JSGracefulActivator.getActiveWorkbenchShell(),
ConsoleMessages.msgHyperlinkError(),
ConsoleMessages.msgHyperlinkError(),
e1.getStatus());
return;
}
startSourceSearch(locationText);
}
/**
* 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();
}
/**
* Opens a message dialog showing the status with given title. If you do not have a title, just call
* {@link #statusDialog(IStatus)}.
*/
public static void statusDialog(String title, IStatus status) {
Shell shell = getActiveWorkbenchShell();
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;
}
}
}
/**
* 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 );
}
}
}
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 );
}
}
/**
* Opens an error dialog if necessary. Takes care of complex rules necessary
* for making the error dialog look nice.
*/
private void openError(IStatus status) {
if (status == null) {
return;
}
String genericTitle = WorkbenchNavigatorMessages.resources_ResourceDropAdapterAssistant_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);
}
@Override
public void run() {
final IBreakpoint breakpoint = getBreakpoint();
if (breakpoint != null) {
new Job("Enabling / Disabling Breakpoint") { //$NON-NLS-1$
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
breakpoint.setEnabled(!breakpoint.isEnabled());
return Status.OK_STATUS;
} catch (final CoreException e) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
ErrorDialog.openError(getTextEditor().getEditorSite().getShell(),
"Enabling/disabling breakpoints",
"Exceptions occurred enabling disabling the breakpoint", e.getStatus());
}
});
}
return Status.CANCEL_STATUS;
}
}.schedule();
}
}
/**
* Opens an error dialog if necessary. Takes care of complex rules necessary
* for making the error dialog look nice.
*/
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);
}
private WSO2PluginSampleExt generateWSO2PluginSampleExt(String fileName, String pluginSamlpeId) {
Gson gson = new Gson();
WSO2PluginSampleExt wso2PluginSampleExt = null;
String fileToRead = fileName + pluginSamlpeId + File.separator + WSO2PluginConstants.SAMPLE_DESCRIPTION_FILE;
try {
BufferedReader br = new BufferedReader(new FileReader(fileToRead));
wso2PluginSampleExt = gson.fromJson(br, WSO2PluginSampleExt.class);
wso2PluginSampleExt.setIsUpdatedFromGit("true");
wso2PluginSampleExt.setPluginArchive(
fileName + pluginSamlpeId + File.separator + wso2PluginSampleExt.getPluginArchive());
} catch (JsonIOException | JsonSyntaxException | FileNotFoundException e) {
log.error("Could not load the plugin sample from the archive, error in the sample format " + e);
MultiStatus status = MessageDialogUtils.createMultiStatus(e.getLocalizedMessage(), e,
WSO2PluginConstants.PACKAGE_ID);
// show error dialog
ErrorDialog.openError(this.getShell(), WSO2PluginConstants.ERROR_DIALOG_TITLE,
"Could not load the plugin sample from the archive, error in the sample format ", status);
}
return wso2PluginSampleExt;
}
private void showMatch(final Match match, final boolean activateEditor) {
ISafeRunnable runnable = new ISafeRunnable() {
public void handleException(Throwable exception) {
if (exception instanceof PartInitException) {
PartInitException pie = (PartInitException) exception;
ErrorDialog.openError(getSite().getShell(), "Show match", "Could not find an editor for the current match", pie.getStatus());
}
}
public void run() throws Exception {
IRegion location= getCurrentMatchLocation(match);
showMatch(match, location.getOffset(), location.getLength(), activateEditor);
}
};
SafeRunner.run(runnable);
}
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);
}
/**
* Handles the connected event.
*/
private void handleConnected() {
try {
createControlService();
getConfigurationFromNode();
// Set connected only after the control service has been created and the jobs for creating the
// sub-nodes are completed.
} catch (final ExecutionException e) {
// Disconnect only if no control service, otherwise stay connected.
if (getControlService() == NULL_CONTROL_SERVICE) {
fState = TargetNodeState.CONNECTED;
disconnect();
}
// Notify user
Display.getDefault().asyncExec(() -> {
ErrorDialog er = new ErrorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
Messages.TraceControl_ErrorTitle, Messages.TraceControl_RetrieveNodeConfigurationFailure,
new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e),
IStatus.ERROR);
er.open();
});
Activator.getDefault().logError(Messages.TraceControl_RetrieveNodeConfigurationFailure + " (" + getName() + "). \n", e); //$NON-NLS-1$ //$NON-NLS-2$
}
}
@Override
protected void okPressed() {
// Validate input data
String sessionPath = fFileNameCombo.getText();
if (!"".equals(sessionPath)) { //$NON-NLS-1$
ImmutableList.Builder<String> builder = new ImmutableList.Builder<>();
try (BufferedRandomAccessFile rafile = new BufferedRandomAccessFile(sessionPath, "r")) { //$NON-NLS-1$
String line = rafile.getNextLine();
while (line != null) {
builder.add(line);
line = rafile.getNextLine();
}
} catch (IOException e) {
ErrorDialog.openError(getShell(), null, null, new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e.getLocalizedMessage(), e));
return;
}
saveWidgetValues();
fCommands = builder.build();
super.okPressed();
}
}
public void restoreFromClipboard() {
try {
String clipboardContents = ClipboardHandler.getClipboardContents();
PyUnitTestRun testRunRestored = PyUnitTestRun.fromXML(clipboardContents);
DummyPyUnitServer pyUnitServer = new DummyPyUnitServer(testRunRestored.getPyUnitLaunch());
final PyUnitViewServerListener serverListener = new PyUnitViewServerListener(pyUnitServer, testRunRestored);
PyUnitViewTestsHolder.addServerListener(serverListener);
this.setCurrentRun(testRunRestored);
} catch (Exception e) {
Log.log(e);
Status status = SharedCorePlugin.makeStatus(IStatus.ERROR, e.getMessage(), e);
ErrorDialog.openError(EditorUtils.getShell(), "Error restoring tests from clipboard",
"Error restoring tests from clipboard", status);
}
}
/**
* 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);
}
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);
}
}
public Object execute(ExecutionEvent event) throws ExecutionException {
try {
URL url = getURL();
IWebBrowser browser;
browser = PlatformUI.getWorkbench().getBrowserSupport().createBrowser(IWorkbenchBrowserSupport.AS_EDITOR,
BonitaPreferenceConstants.APPLICATION_BROWSER_ID, "Bonita Application", "");
browser.openURL(url);
} catch (Exception e) {
BonitaStudioLog.error(e);
ErrorDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
"error",
"error starting server",
Status.OK_STATUS);
}
return null;
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
if (selection == null || !(selection instanceof IStructuredSelection)) {
return null;
}
IStructuredSelection currentSelection = (IStructuredSelection) selection;
if (currentSelection.size() == 1) {
Term termToSplit = (Term) currentSelection.getFirstElement();
if (selectionValid(termToSplit)) {
SplitTermDialog dialog = new SplitTermDialog(null, termToSplit.getName());
if (dialog.open() == MessageDialog.OK && dialog.getReturnCode() == MessageDialog.OK) {
TermSplitter.split(termToSplit, dialog.getDefaultTermName(), dialog.getFurtherTermNames());
}
} else {
ErrorDialog.openError(null, "Error", null, new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Invalid selection. The selected term must not have children.", null));
}
}
return null;
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
if (selection == null || !(selection instanceof IStructuredSelection)) {
return null;
}
IStructuredSelection currentSelection = (IStructuredSelection) selection;
if (currentSelection.size() > 1) {
List<Term> termsToMerge = new ArrayList<>(currentSelection.size());
currentSelection.toList().stream().filter(s -> s instanceof Term).forEach(s -> termsToMerge.add((Term) s));
if (selectionValid(termsToMerge)) {
MergeTermsDialog dialog = new MergeTermsDialog(null, termsToMerge);
dialog.setBlockOnOpen(true);
if (dialog.open() == MessageDialog.OK && dialog.getReturnCode() == MessageDialog.OK) {
TermMerger.merge(termsToMerge, dialog.getTargetTerm());
}
} else {
ErrorDialog.openError(null, "Error", null, new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Invalid selection. The selected terms must not share their paths.", null));
}
}
return null;
}
/**
* Opens an error dialog if necessary. Takes care of complex rules necessary
* for making the error dialog look nice.
*/
private void openError(IStatus status) {
if (status == null) {
return;
}
String genericTitle = WorkbenchNavigatorMessages.resources_ResourceDropAdapterAssistant_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);
}
/**
* Exports the JAR package.
*
* @param op the op
* @return a boolean indicating success or failure
*/
protected boolean executeExportOperation(IJarExportRunnable op) {
try {
getContainer().run(true, true, op);
} catch (InterruptedException e) {
return false;
} catch (InvocationTargetException ex) {
if (ex.getTargetException() != null) {
ExceptionHandler.handle(ex, getShell(), JarPackagerMessages.JarPackageWizard_jarExportError_title, JarPackagerMessages.JarPackageWizard_jarExportError_message);
return false;
}
}
IStatus status= op.getStatus();
if (!status.isOK()) {
ErrorDialog.openError(getShell(), JarPackagerMessages.JarPackageWizard_jarExport_title, null, status);
return !(status.matches(IStatus.ERROR));
}
return true;
}
private void handleFinishedDropMove(DragSourceEvent event) {
MultiStatus status= new MultiStatus(
JavaPlugin.getPluginId(),
IJavaStatusConstants.INTERNAL_ERROR,
JavaUIMessages.ResourceTransferDragAdapter_cannot_delete_resource,
null);
List<IResource> resources= convertSelection();
for (Iterator<IResource> iter= resources.iterator(); iter.hasNext();) {
IResource resource= iter.next();
try {
resource.delete(true, null);
} catch (CoreException e) {
status.add(e.getStatus());
}
}
int childrenCount= status.getChildren().length;
if (childrenCount > 0) {
Shell parent= SWTUtil.getShell(event.widget);
ErrorDialog error= new ErrorDialog(parent,
JavaUIMessages.ResourceTransferDragAdapter_moving_resource,
childrenCount == 1 ? JavaUIMessages.ResourceTransferDragAdapter_cannot_delete_files_singular : Messages.format(
JavaUIMessages.ResourceTransferDragAdapter_cannot_delete_files_plural, String.valueOf(childrenCount)), status, IStatus.ERROR);
error.open();
}
}
/** Invoked when the wizard is closed with the "Finish" button.
*
* @return {@code true} for closing the wizard; {@code false} for keeping it open.
*/
public boolean performFinish() {
final IEclipsePreferences prefs = SARLEclipsePlugin.getDefault().getPreferences();
final String login = this.trackerLogin.getText();
if (Strings.isEmpty(login)) {
prefs.remove(PREFERENCE_LOGIN);
} else {
prefs.put(PREFERENCE_LOGIN, login);
}
try {
prefs.sync();
return true;
} catch (BackingStoreException e) {
ErrorDialog.openError(getShell(), e.getLocalizedMessage(), e.getLocalizedMessage(),
SARLEclipsePlugin.getDefault().createStatus(IStatus.ERROR, e));
return false;
}
}
/**
* Creates the provisional project on which the wizard is working on.
* The provisional project is typically created when the page is entered
* the first time. The early project creation is required to configure
* linked folders.
*
* @return the provisional project
*/
protected IProject createProvisonalProject() {
final IStatus status = changeToNewProject();
if (status != null) {
updateStatus(status);
if (!status.isOK()) {
ErrorDialog.openError(
getShell(),
NewWizardMessages.NewJavaProjectWizardPageTwo_error_title,
null,
status);
}
}
return this.currProject;
}
static File findDebugAdapter() {
URL fileURL;
try {
fileURL = FileLocator.toFileURL(
ChromeRunDAPDebugDelegate.class.getResource("/node_modules/debugger-for-chrome/out/src/chromeDebug.js"));
return new File(fileURL.toURI());
} catch (IOException | URISyntaxException e) {
IStatus errorStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
Activator.getDefault().getLog().log(errorStatus);
Display.getDefault().asyncExec(() -> ErrorDialog.openError(Display.getDefault().getActiveShell(), "Debug error", e.getMessage(), errorStatus)); //$NON-NLS-1$
}
return null;
}