Java Code Examples for org.eclipse.jdt.internal.ui.util.ExceptionHandler#handle()

The following examples show how to use org.eclipse.jdt.internal.ui.util.ExceptionHandler#handle() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImportOrganizeInputDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void doBrowseTypes() {
	IRunnableContext context= new BusyIndicatorRunnableContext();
	IJavaSearchScope scope= SearchEngine.createWorkspaceScope();
	int style= IJavaElementSearchConstants.CONSIDER_ALL_TYPES;
	try {
		SelectionDialog dialog= JavaUI.createTypeDialog(getShell(), context, scope, style, false, fNameDialogField.getText());
		dialog.setTitle(PreferencesMessages.ImportOrganizeInputDialog_ChooseTypeDialog_title);
		dialog.setMessage(PreferencesMessages.ImportOrganizeInputDialog_ChooseTypeDialog_description);
		if (dialog.open() == Window.OK) {
			IType res= (IType) dialog.getResult()[0];
			fNameDialogField.setText(res.getFullyQualifiedName('.'));
		}
	} catch (JavaModelException e) {
		ExceptionHandler.handle(e, getShell(), PreferencesMessages.ImportOrganizeInputDialog_ChooseTypeDialog_title, PreferencesMessages.ImportOrganizeInputDialog_ChooseTypeDialog_error_message);
	}
}
 
Example 2
Source File: AddDelegateMethodsAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run(IStructuredSelection selection) {
	try {
		IField[] selectedFields= getSelectedFields(selection);
		if (canRunOn(selectedFields)) {
			run(selectedFields[0].getDeclaringType(), selectedFields, false);
			return;
		}
		Object firstElement= selection.getFirstElement();
		if (firstElement instanceof IType)
			run((IType) firstElement, new IField[0], false);
		else if (firstElement instanceof ICompilationUnit)
			run(JavaElementUtil.getMainType((ICompilationUnit) firstElement), new IField[0], false);
		else if (!(firstElement instanceof IField))
			MessageDialog.openInformation(getShell(), DIALOG_TITLE, ActionMessages.AddDelegateMethodsAction_not_applicable);
	} catch (CoreException e) {
		ExceptionHandler.handle(e, getShell(), DIALOG_TITLE, ActionMessages.AddDelegateMethodsAction_error_actionfailed);
	}

}
 
Example 3
Source File: CodeAssistFavoritesConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void doBrowseTypes() {
	IRunnableContext context= new BusyIndicatorRunnableContext();
	IJavaSearchScope scope= SearchEngine.createWorkspaceScope();
	int style= IJavaElementSearchConstants.CONSIDER_ALL_TYPES;
	try {
		SelectionDialog dialog= JavaUI.createTypeDialog(getShell(), context, scope, style, false, fNameDialogField.getText());
		dialog.setTitle(PreferencesMessages.FavoriteStaticMemberInputDialog_ChooseTypeDialog_title);
		dialog.setMessage(PreferencesMessages.FavoriteStaticMemberInputDialog_ChooseTypeDialog_description);
		if (dialog.open() == Window.OK) {
			IType res= (IType) dialog.getResult()[0];
			fNameDialogField.setText(res.getFullyQualifiedName('.'));
		}
	} catch (JavaModelException e) {
		ExceptionHandler.handle(e, getShell(), PreferencesMessages.FavoriteStaticMemberInputDialog_ChooseTypeDialog_title, PreferencesMessages.FavoriteStaticMemberInputDialog_ChooseTypeDialog_error_message);
	}
}
 
Example 4
Source File: PullUpMethodPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void initializeTreeViewer(final IProgressMonitor pm) {
	try {
		pm.beginTask(RefactoringCoreMessages.PullUpRefactoring_checking, 2);
		final IMember[] matchingMethods= fProcessor.getMatchingElements(new SubProgressMonitor(pm, 1), false);
		final ITypeHierarchy hierarchy= fProcessor.getDestinationTypeHierarchy(new SubProgressMonitor(pm, 1));
		removeAllTreeViewFilters();
		fTreeViewer.addFilter(new PullUpFilter(hierarchy, matchingMethods));
		fTreeViewer.setContentProvider(new PullUpHierarchyContentProvider(fProcessor.getDeclaringType(), matchingMethods));
		fTreeViewer.setInput(hierarchy);
		precheckElements(fTreeViewer);
		fTreeViewer.expandAll();
		updateSelectionLabel();
	} catch (JavaModelException e) {
		ExceptionHandler.handle(e, RefactoringMessages.PullUpInputPage_pull_up1, RefactoringMessages.PullUpInputPage_exception);
		fTreeViewer.setInput(null);
	} finally {
		pm.done();
	}
}
 
Example 5
Source File: ConvertNestedToTopAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run(IStructuredSelection selection) {
	try {
		//we have to call this here - no selection changed event is sent
		// after a refactoring but it may still invalidate enablement
		if (RefactoringAvailabilityTester.isMoveInnerAvailable(selection)) {
			IType singleSelectedType= getSingleSelectedType(selection);
			if (! ActionUtil.isEditable(getShell(), singleSelectedType))
				return;
			RefactoringExecutionStarter.startMoveInnerRefactoring(singleSelectedType, getShell());
		}
	} catch (JavaModelException e) {
		ExceptionHandler.handle(e,
			RefactoringMessages.OpenRefactoringWizardAction_refactoring,
			RefactoringMessages.OpenRefactoringWizardAction_exception);
	}
}
 
Example 6
Source File: OpenJavaPerspectiveAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run() {
	IWorkbench workbench= JavaPlugin.getDefault().getWorkbench();
	IWorkbenchWindow window= workbench.getActiveWorkbenchWindow();
	IWorkbenchPage page= window.getActivePage();
	IAdaptable input;
	if (page != null)
		input= page.getInput();
	else
		input= ResourcesPlugin.getWorkspace().getRoot();
	try {
		workbench.showPerspective(JavaUI.ID_PERSPECTIVE, window, input);
	} catch (WorkbenchException e) {
		ExceptionHandler.handle(e, window.getShell(),
			ActionMessages.OpenJavaPerspectiveAction_dialog_title,
			ActionMessages.OpenJavaPerspectiveAction_error_open_failed);
	}
}
 
Example 7
Source File: OpenSuperImplementationAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public void run(IMethod method) {
	if (method == null)
		return;
	if (!ActionUtil.isProcessable(getShell(), method))
		return;

	if (!checkMethod(method)) {
		MessageDialog.openInformation(getShell(), getDialogTitle(),
			Messages.format(ActionMessages.OpenSuperImplementationAction_no_super_implementation, BasicElementLabels.getJavaElementName(method.getElementName())));
		return;
	}

	try {
		IMethod impl= findSuperImplementation(method);
		if (impl != null) {
			JavaUI.openInEditor(impl, true, true);
		}
	} catch (CoreException e) {
		ExceptionHandler.handle(e, getDialogTitle(), ActionMessages.OpenSuperImplementationAction_error_message);
	}
}
 
Example 8
Source File: ExtractInterfaceAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run(ITextSelection selection) {
	try {
		if (!ActionUtil.isEditable(fEditor))
			return;
		IType type= RefactoringActions.getEnclosingOrPrimaryType(fEditor);
		if (RefactoringAvailabilityTester.isExtractInterfaceAvailable(type)) {
			RefactoringExecutionStarter.startExtractInterfaceRefactoring(type, getShell());
		} else {
			String unavailable= RefactoringMessages.ExtractInterfaceAction_To_activate;
			MessageDialog.openInformation(getShell(), RefactoringMessages.OpenRefactoringWizardAction_unavailable, unavailable);
		}
	} catch (JavaModelException e) {
		ExceptionHandler.handle(e, RefactoringMessages.OpenRefactoringWizardAction_refactoring, RefactoringMessages.OpenRefactoringWizardAction_exception);
	}
}
 
Example 9
Source File: JavaSearchResultPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void handleOpen(OpenEvent event) {
	Object firstElement= ((IStructuredSelection)event.getSelection()).getFirstElement();
	if (firstElement instanceof ICompilationUnit ||
			firstElement instanceof IClassFile ||
			firstElement instanceof IMember) {
		if (getDisplayedMatchCount(firstElement) == 0) {
			try {
				fEditorOpener.openElement(firstElement);
			} catch (CoreException e) {
				ExceptionHandler.handle(e, getSite().getShell(), SearchMessages.JavaSearchResultPage_open_editor_error_title, SearchMessages.JavaSearchResultPage_open_editor_error_message);
			}
			return;
		}
	}
	super.handleOpen(event);
}
 
Example 10
Source File: EditFilterAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run() {
	Shell shell= getShell();

	try {
		EditFilterWizard wizard= createWizard();
		wizard.init(PlatformUI.getWorkbench(), new StructuredSelection(getSelectedElements().get(0)));

		WizardDialog dialog= new WizardDialog(shell, wizard);
		PixelConverter converter= new PixelConverter(JFaceResources.getDialogFont());
		dialog.setMinimumPageSize(converter.convertWidthInCharsToPixels(70), converter.convertHeightInCharsToPixels(20));
		dialog.create();
		int res= dialog.open();
		if (res == Window.OK) {
			BuildpathDelta delta= new BuildpathDelta(getToolTipText());

			ArrayList<CPListElement> newEntries= wizard.getExistingEntries();
			delta.setNewEntries(newEntries.toArray(new CPListElement[newEntries.size()]));

			IResource resource= wizard.getCreatedElement().getCorrespondingResource();
			delta.addCreatedResource(resource);

			delta.setDefaultOutputLocation(wizard.getOutputLocation());

			informListeners(delta);

			selectAndReveal(new StructuredSelection(wizard.getCreatedElement()));
		}

		notifyResult(res == Window.OK);
	} catch (CoreException e) {
		String title= NewWizardMessages.AbstractOpenWizardAction_createerror_title;
		String message= NewWizardMessages.AbstractOpenWizardAction_createerror_message;
		ExceptionHandler.handle(e, shell, title, message);
	}
}
 
Example 11
Source File: InlineMethodAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run(IStructuredSelection selection) {
	try {
		Assert.isTrue(RefactoringAvailabilityTester.isInlineMethodAvailable(selection));
		IMethod method= (IMethod) selection.getFirstElement();
		ISourceRange nameRange= method.getNameRange();
		run(nameRange.getOffset(), nameRange.getLength(), method.getTypeRoot());
	} catch (JavaModelException e) {
		ExceptionHandler.handle(e, getShell(), RefactoringMessages.InlineMethodAction_dialog_title, RefactoringMessages.InlineMethodAction_unexpected_exception);
	}
}
 
Example 12
Source File: GenerateMethodAbstractAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run(IStructuredSelection selection) {
	try {
		checkAndRun(getSelectedType(selection));
	} catch (CoreException exception) {
		ExceptionHandler.handle(exception, getShell(), getErrorCaption(), ActionMessages.GenerateMethodAbstractAction_error_cannot_create);
	}
}
 
Example 13
Source File: ModifyParametersAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run(ITextSelection selection) {
	try {
		if (! ActionUtil.isEditable(fEditor))
			return;
		IMethod method= getSingleSelectedMethod(selection);
		if (RefactoringAvailabilityTester.isChangeSignatureAvailable(method)){
			RefactoringExecutionStarter.startChangeSignatureRefactoring(method, this, getShell());
		} else {
			MessageDialog.openInformation(getShell(), RefactoringMessages.OpenRefactoringWizardAction_unavailable, RefactoringMessages.ModifyParametersAction_unavailable);
		}
	} catch (JavaModelException e) {
		ExceptionHandler.handle(e, RefactoringMessages.OpenRefactoringWizardAction_refactoring, RefactoringMessages.OpenRefactoringWizardAction_exception);
	}
}
 
Example 14
Source File: MoveInstanceMethodAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run(ITextSelection selection) {
	try {
		run(selection, SelectionConverter.getInputAsCompilationUnit(fEditor));
	} catch (JavaModelException e) {
		ExceptionHandler.handle(e, getShell(), RefactoringMessages.MoveInstanceMethodAction_dialog_title, RefactoringMessages.MoveInstanceMethodAction_unexpected_exception);
	}
}
 
Example 15
Source File: IntroduceParameterObjectAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run(IStructuredSelection selection) {
	try {
		IMethod singleSelectedMethod= getSingleSelectedMethod(selection);
		if (!ActionUtil.isEditable(getShell(), singleSelectedMethod))
			return;
		run(singleSelectedMethod);
	} catch (CoreException e) {
		ExceptionHandler.handle(e, getShell(), ActionMessages.IntroduceParameterObjectAction_exceptiondialog_title,	ActionMessages.IntroduceParameterObjectAction_unexpected_exception);
	}
}
 
Example 16
Source File: AbstractOpenWizardAction.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run() {
  Shell localShell = getShell();
  if (!doCreateProjectFirstOnEmptyWorkspace(localShell)) {
    return;
  }

  try {
    INewWizard wizard = createWizard();
    wizard.init(PlatformUI.getWorkbench(), getSelection());

    WizardDialog dialog = new WizardDialog(localShell, wizard);
    IPixelConverter converter =
        PixelConverterFactory.createPixelConverter(JFaceResources.getDialogFont());
    dialog.setMinimumPageSize(converter.convertWidthInCharsToPixels(70),
        converter.convertHeightInCharsToPixels(20));
    dialog.create();
    int res = dialog.open();
    if (res == Window.OK && wizard instanceof NewElementWizard) {
      createdElement = ((NewElementWizard) wizard).getCreatedElement();
    }

    notifyResult(res == Window.OK);
  } catch (CoreException e) {
    String title = NewWizardMessages.AbstractOpenWizardAction_createerror_title;
    String message = NewWizardMessages.AbstractOpenWizardAction_createerror_message;
    ExceptionHandler.handle(e, localShell, title, message);
  }
}
 
Example 17
Source File: CreateLinkedSourceFolderAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void run() {
	Shell shell= getShell();

	try {
		IJavaProject javaProject= (IJavaProject)getSelectedElements().get(0);

		CPListElement newEntrie= new CPListElement(javaProject, IClasspathEntry.CPE_SOURCE);
           CPListElement[] existing= CPListElement.createFromExisting(javaProject);
           boolean isProjectSrcFolder= CPListElement.isProjectSourceFolder(existing, javaProject);

		AddSourceFolderWizard wizard= new AddSourceFolderWizard(existing, newEntrie, getOutputLocation(javaProject), true, false, false, isProjectSrcFolder, isProjectSrcFolder);
		wizard.init(PlatformUI.getWorkbench(), new StructuredSelection(javaProject));

		WizardDialog dialog= new WizardDialog(shell, wizard);
		PixelConverter converter= new PixelConverter(JFaceResources.getDialogFont());
		dialog.setMinimumPageSize(converter.convertWidthInCharsToPixels(70), converter.convertHeightInCharsToPixels(20));
		dialog.create();
		int res= dialog.open();
		if (res == Window.OK) {

			BuildpathDelta delta= new BuildpathDelta(getToolTipText());

			ArrayList<CPListElement> newEntries= wizard.getExistingEntries();
			delta.setNewEntries(newEntries.toArray(new CPListElement[newEntries.size()]));

			IResource resource= wizard.getCreatedElement().getCorrespondingResource();
			delta.addCreatedResource(resource);

			delta.setDefaultOutputLocation(wizard.getOutputLocation());

			informListeners(delta);

			selectAndReveal(new StructuredSelection(wizard.getCreatedElement()));
		}

		notifyResult(res == Window.OK);
	} catch (CoreException e) {
		String title= NewWizardMessages.AbstractOpenWizardAction_createerror_title;
		String message= NewWizardMessages.AbstractOpenWizardAction_createerror_message;
		ExceptionHandler.handle(e, shell, title, message);
	}
}
 
Example 18
Source File: ReplaceInvocationsAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void handleException(CoreException e) {
	ExceptionHandler.handle(e, RefactoringMessages.ReplaceInvocationsAction_dialog_title, RefactoringMessages.ReplaceInvocationsAction_unavailable);
}
 
Example 19
Source File: PropertyKeyHyperlink.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void showError(CoreException e) {
	ExceptionHandler.handle(e, fShell, getErrorDialogTitle(), PropertiesFileEditorMessages.OpenAction_error_message);
}
 
Example 20
Source File: ClasspathContainerWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void handlePageCreationFailed(CoreException e) {
	String title= NewWizardMessages.ClasspathContainerWizard_pagecreationerror_title;
	String message= NewWizardMessages.ClasspathContainerWizard_pagecreationerror_message;
	ExceptionHandler.handle(e, getShell(), title, message);
}