diff options
Diffstat (limited to 'bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions')
92 files changed, 0 insertions, 19341 deletions
diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/AbstractOpenWizardAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/AbstractOpenWizardAction.java deleted file mode 100644 index 5357800f..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/AbstractOpenWizardAction.java +++ /dev/null @@ -1,179 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.window.Window; -import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.INewWizard; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.actions.NewProjectAction; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; -import org.eclipse.wst.jsdt.internal.ui.util.PixelConverter; -import org.eclipse.wst.jsdt.internal.ui.wizards.NewElementWizard; -import org.eclipse.wst.jsdt.internal.ui.wizards.NewWizardMessages; - -/** - * <p>Abstract base classed used for the open wizard actions.</p> - * - * <p> - * Note: This class is for internal use only. Clients should not use this class. - * </p> - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public abstract class AbstractOpenWizardAction extends Action { - - private Shell fShell; - private IStructuredSelection fSelection; - private IJavaScriptElement fCreatedElement; - - /** - * Creates the action. - */ - protected AbstractOpenWizardAction() { - fShell= null; - fSelection= null; - fCreatedElement= null; - } - - /* (non-Javadoc) - * @see org.eclipse.jface.action.Action#run() - */ - public void run() { - Shell shell= getShell(); - if (!doCreateProjectFirstOnEmptyWorkspace(shell)) { - return; - } - try { - INewWizard wizard= createWizard(); - wizard.init(PlatformUI.getWorkbench(), getSelection()); - - 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 && wizard instanceof NewElementWizard) { - fCreatedElement= ((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, shell, title, message); - } - } - - /** - * Creates and configures the wizard. This method should only be called once. - * @return returns the created wizard. - * @throws CoreException exception is thrown when the creation was not successful. - */ - abstract protected INewWizard createWizard() throws CoreException; - - /** - * Returns the configured selection. If no selection has been configured using {@link #setSelection(IStructuredSelection)}, - * the currently selected element of the active workbench is returned. - * @return the configured selection - */ - protected IStructuredSelection getSelection() { - if (fSelection == null) { - return evaluateCurrentSelection(); - } - return fSelection; - } - - private IStructuredSelection evaluateCurrentSelection() { - IWorkbenchWindow window= JavaScriptPlugin.getActiveWorkbenchWindow(); - if (window != null) { - ISelection selection= window.getSelectionService().getSelection(); - if (selection instanceof IStructuredSelection) { - return (IStructuredSelection) selection; - } - } - return StructuredSelection.EMPTY; - } - - /** - * Configures the selection to be used as initial selection of the wizard. - * @param selection the selection to be set or <code>null</code> to use the selection of the active workbench window - */ - public void setSelection(IStructuredSelection selection) { - fSelection= selection; - } - - /** - * Returns the configured shell. If no shell has been configured using {@link #setShell(Shell)}, - * the shell of the currently active workbench is returned. - * @return the configured shell - */ - protected Shell getShell() { - if (fShell == null) { - return JavaScriptPlugin.getActiveWorkbenchShell(); - } - return fShell; - } - - /** - * Configures the shell to be used as parent shell by the wizard. - * @param shell the shell to be set or <code>null</code> to use the shell of the active workbench window - */ - public void setShell(Shell shell) { - fShell= shell; - } - - /** - * Opens the new project dialog if the workspace is empty. This method is called on {@link #run()}. - * @param shell the shell to use - * @return returns <code>true</code> when a project has been created, or <code>false</code> when the - * new project has been canceled. - */ - protected boolean doCreateProjectFirstOnEmptyWorkspace(Shell shell) { - IWorkspaceRoot workspaceRoot= ResourcesPlugin.getWorkspace().getRoot(); - if (workspaceRoot.getProjects().length == 0) { - String title= NewWizardMessages.AbstractOpenWizardAction_noproject_title; - String message= NewWizardMessages.AbstractOpenWizardAction_noproject_message; - if (MessageDialog.openQuestion(shell, title, message)) { - new NewProjectAction().run(); - return workspaceRoot.getProjects().length != 0; - } - return false; - } - return true; - } - - /** - * Returns the created element or <code>null</code> if the wizard has not run or was canceled. - * @return the created element or <code>null</code> - */ - public IJavaScriptElement getCreatedElement() { - return fCreatedElement; - } - - -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/AddDelegateMethodsAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/AddDelegateMethodsAction.java deleted file mode 100644 index dca9ed18..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/AddDelegateMethodsAction.java +++ /dev/null @@ -1,596 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Martin Moebius (m.moebius@gmx.de) - initial API and implementation - * (report 28793) - * IBM Corporation - updates - *******************************************************************************/ - -package org.eclipse.wst.jsdt.ui.actions; - -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.operation.IRunnableContext; -import org.eclipse.jface.text.IRewriteTarget; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerComparator; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Link; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.ISelectionStatusValidator; -import org.eclipse.wst.jsdt.core.IField; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.IJavaScriptUnit; -import org.eclipse.wst.jsdt.core.IType; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.core.Signature; -import org.eclipse.wst.jsdt.core.dom.AST; -import org.eclipse.wst.jsdt.core.dom.IBinding; -import org.eclipse.wst.jsdt.core.dom.IFunctionBinding; -import org.eclipse.wst.jsdt.core.dom.ITypeBinding; -import org.eclipse.wst.jsdt.core.dom.IVariableBinding; -import org.eclipse.wst.jsdt.core.dom.JavaScriptUnit; -import org.eclipse.wst.jsdt.core.dom.VariableDeclarationFragment; -import org.eclipse.wst.jsdt.internal.corext.codemanipulation.AddDelegateMethodsOperation; -import org.eclipse.wst.jsdt.internal.corext.codemanipulation.CodeGenerationSettings; -import org.eclipse.wst.jsdt.internal.corext.codemanipulation.StubUtility2; -import org.eclipse.wst.jsdt.internal.corext.dom.ASTNodes; -import org.eclipse.wst.jsdt.internal.corext.dom.Bindings; -import org.eclipse.wst.jsdt.internal.corext.refactoring.structure.ASTNodeSearchUtil; -import org.eclipse.wst.jsdt.internal.corext.refactoring.util.JavaElementUtil; -import org.eclipse.wst.jsdt.internal.corext.refactoring.util.RefactoringASTParser; -import org.eclipse.wst.jsdt.internal.corext.template.java.CodeTemplateContextType; -import org.eclipse.wst.jsdt.internal.corext.util.JavaModelUtil; -import org.eclipse.wst.jsdt.internal.corext.util.Messages; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.actions.WorkbenchRunnableAdapter; -import org.eclipse.wst.jsdt.internal.ui.dialogs.SourceActionDialog; -import org.eclipse.wst.jsdt.internal.ui.dialogs.StatusInfo; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.CompilationUnitEditor; -import org.eclipse.wst.jsdt.internal.ui.preferences.JavaPreferencesSettings; -import org.eclipse.wst.jsdt.internal.ui.util.BusyIndicatorRunnableContext; -import org.eclipse.wst.jsdt.internal.ui.util.ElementValidator; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; -import org.eclipse.wst.jsdt.internal.ui.viewsupport.BindingLabelProvider; -import org.eclipse.wst.jsdt.ui.JavaScriptUI; - -import com.ibm.icu.text.Collator; - -/** - * Creates delegate methods for a type's fields. Opens a dialog with a list of fields for - * which delegate methods can be generated. User is able to check or uncheck items before - * methods are generated. - * <p> - * Will open the parent compilation unit in a JavaScript editor. The result is unsaved, so the - * user can decide if the changes are acceptable. - * <p> - * The action is applicable to structured selections containing elements of type - * <code>IField</code> or <code>IType</code>. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class AddDelegateMethodsAction extends SelectionDispatchAction { - - // ---- Helpers ------------------------------------------------------------------- - - private static class AddDelegateMethodsActionStatusValidator implements ISelectionStatusValidator { - - private static int fEntries; - - AddDelegateMethodsActionStatusValidator(int entries) { - fEntries= entries; - } - - public IStatus validate(Object[] selection) { - StatusInfo info= new StatusInfo(); - if (selection != null && selection.length > 0) { - int count= 0; - List bindings= new ArrayList(selection.length); - IFunctionBinding binding= null; - for (int index= 0; index < selection.length; index++) { - if (selection[index] instanceof IBinding[]) { - count++; - binding= (IFunctionBinding) ((IBinding[]) selection[index])[1]; - IFunctionBinding existing= null; - for (int offset= 0; offset < bindings.size(); offset++) { - existing= (IFunctionBinding) bindings.get(offset); - if (Bindings.isEqualMethod(binding, existing.getName(), existing.getParameterTypes())) { - return new StatusInfo(IStatus.ERROR, ActionMessages.AddDelegateMethodsAction_duplicate_methods); - } - } - bindings.add(binding); - info= new StatusInfo(IStatus.INFO, Messages.format(ActionMessages.AddDelegateMethodsAction_selectioninfo_more, new Object[] { String.valueOf(count), String.valueOf(fEntries)})); - } - } - } - return info; - } - } - - private static class AddDelegateMethodsContentProvider implements ITreeContentProvider { - - private IBinding[][] fBindings= new IBinding[0][0]; - - private int fCount= 0; - - private IVariableBinding[] fExpanded= new IVariableBinding[0]; - - private final JavaScriptUnit fUnit; - - AddDelegateMethodsContentProvider(IType type, IField[] fields) throws JavaScriptModelException { - RefactoringASTParser parser= new RefactoringASTParser(AST.JLS3); - fUnit= parser.parse(type.getJavaScriptUnit(), true); - final ITypeBinding binding= ASTNodes.getTypeBinding(fUnit, type); - if (binding != null) { - IBinding[][] bindings= StubUtility2.getDelegatableMethods(fUnit.getAST(), binding); - if (bindings != null) { - fBindings= bindings; - fCount= bindings.length; - } - List expanded= new ArrayList(); - for (int index= 0; index < fields.length; index++) { - VariableDeclarationFragment fragment= ASTNodeSearchUtil.getFieldDeclarationFragmentNode(fields[index], fUnit); - if (fragment != null) { - IVariableBinding variableBinding= fragment.resolveBinding(); - if (variableBinding != null) - expanded.add(variableBinding); - } - } - IVariableBinding[] result= new IVariableBinding[expanded.size()]; - expanded.toArray(result); - fExpanded= result; - } - } - - public JavaScriptUnit getCompilationUnit() { - return fUnit; - } - - public void dispose() { - } - - public Object[] getChildren(Object element) { - if (element instanceof IVariableBinding) { - IVariableBinding binding= (IVariableBinding) element; - List result= new ArrayList(); - final String key= binding.getKey(); - for (int index= 0; index < fBindings.length; index++) - if (fBindings[index][0].getKey().equals(key)) - result.add(fBindings[index]); - return result.toArray(); - } - return null; - } - - public int getCount() { - return fCount; - } - - public Object[] getElements(Object inputElement) { - Set keys= new HashSet(); - List result= new ArrayList(); - for (int index= 0; index < fBindings.length; index++) { - IBinding[] bindings= fBindings[index]; - final String key= bindings[0].getKey(); - if (!keys.contains(key)) { - keys.add(key); - result.add(bindings[0]); - } - } - return result.toArray(); - } - - public IVariableBinding[] getExpandedElements() { - return fExpanded; - } - - public IBinding[][] getInitiallySelectedElements() { - List result= new ArrayList(); - for (int index= 0; index < fBindings.length; index++) - for (int offset= 0; offset < fExpanded.length; offset++) - if (fExpanded[offset].getKey().equals(fBindings[index][0].getKey())) - result.add(fBindings[index]); - return (IBinding[][]) result.toArray(new IBinding[result.size()][2]); - } - - public Object getParent(Object element) { - if (element instanceof IBinding[]) - return ((IBinding[]) element)[0]; - return null; - } - - public boolean hasChildren(Object element) { - return element instanceof IVariableBinding; - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - } - - private static class AddDelegateMethodsDialog extends SourceActionDialog { - - public AddDelegateMethodsDialog(Shell parent, ILabelProvider labelProvider, ITreeContentProvider contentProvider, CompilationUnitEditor editor, IType type, boolean isConstructor) throws JavaScriptModelException { - super(parent, labelProvider, contentProvider, editor, type, isConstructor); - } - - protected void configureShell(Shell shell) { - super.configureShell(shell); - PlatformUI.getWorkbench().getHelpSystem().setHelp(shell, IJavaHelpContextIds.ADD_DELEGATE_METHODS_SELECTION_DIALOG); - } - - /* - * @see org.eclipse.wst.jsdt.internal.ui.dialogs.SourceActionDialog#createLinkControl(org.eclipse.swt.widgets.Composite) - */ - protected Control createLinkControl(Composite composite) { - Link link= new Link(composite, SWT.WRAP); - link.setText(ActionMessages.AddDelegateMethodsAction_template_link_message); - link.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - openCodeTempatePage(CodeTemplateContextType.OVERRIDECOMMENT_ID); - } - }); - link.setToolTipText(ActionMessages.AddDelegateMethodsAction_template_link_tooltip); - - GridData gridData= new GridData(SWT.FILL, SWT.BEGINNING, true, false); - gridData.widthHint= convertWidthInCharsToPixels(40); // only expand further if anyone else requires it - link.setLayoutData(gridData); - return link; - } - } - - private static class AddDelegateMethodsLabelProvider extends BindingLabelProvider { - - public Image getImage(Object element) { - if (element instanceof IBinding[]) { - return super.getImage((((IBinding[]) element)[1])); - } else if (element instanceof IVariableBinding) { - return super.getImage(element); - } - return null; - } - - public String getText(Object element) { - if (element instanceof IBinding[]) { - return super.getText((((IBinding[]) element)[1])); - } else if (element instanceof IVariableBinding) { - return super.getText(element); - } - return null; - } - } - - private static class AddDelegateMethodsViewerComparator extends ViewerComparator { - - private final BindingLabelProvider fProvider= new BindingLabelProvider(); - private final Collator fCollator= Collator.getInstance(); - - public int category(Object element) { - if (element instanceof IBinding[]) - return 0; - return 1; - } - - public int compare(Viewer viewer, Object object1, Object object2) { - String first= ""; //$NON-NLS-1$ - String second= ""; //$NON-NLS-1$ - if (object1 instanceof IBinding[]) - first= fProvider.getText(((IBinding[]) object1)[1]); - else if (object1 instanceof IVariableBinding) - first= ((IBinding) object1).getName(); - if (object2 instanceof IBinding[]) - second= fProvider.getText(((IBinding[]) object2)[1]); - else if (object2 instanceof IVariableBinding) - second= ((IBinding) object2).getName(); - return fCollator.compare(first, second); - } - } - - private static final String DIALOG_TITLE= ActionMessages.AddDelegateMethodsAction_error_title; - - private static boolean hasPrimitiveType(IField field) throws JavaScriptModelException { - String signature= field.getTypeSignature(); - char first= Signature.getElementType(signature).charAt(0); - return (first != Signature.C_RESOLVED && first != Signature.C_UNRESOLVED); - } - - private static boolean isArray(IField field) throws JavaScriptModelException { - return Signature.getArrayCount(field.getTypeSignature()) > 0; - } - - private CompilationUnitEditor fEditor; - - /** - * Note: This constructor is for internal use only. Clients should not call this - * constructor. - * - * @param editor the compilation unit editor - */ - public AddDelegateMethodsAction(CompilationUnitEditor editor) { - this(editor.getEditorSite()); - fEditor= editor; - setEnabled(SelectionConverter.getInputAsCompilationUnit(editor) != null); - } - - /** - * Creates a new <code>AddDelegateMethodsAction</code>. The action requires that - * the selection provided by the site's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public AddDelegateMethodsAction(IWorkbenchSite site) { - super(site); - setText(ActionMessages.AddDelegateMethodsAction_label); - setDescription(ActionMessages.AddDelegateMethodsAction_description); - setToolTipText(ActionMessages.AddDelegateMethodsAction_tooltip); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.ADD_DELEGATE_METHODS_ACTION); - } - - private boolean canEnable(IStructuredSelection selection) throws JavaScriptModelException { - if (getSelectedFields(selection) != null) - return true; - - if ((selection.size() == 1) && (selection.getFirstElement() instanceof IType)) { - IType type= (IType) selection.getFirstElement(); - return type.getJavaScriptUnit() != null; - } - - if ((selection.size() == 1) && (selection.getFirstElement() instanceof IJavaScriptUnit)) - return true; - - return false; - } - - private boolean canRunOn(IField[] fields) throws JavaScriptModelException { - if (fields == null || fields.length == 0) - return false; - int count= 0; - for (int index= 0; index < fields.length; index++) { - if (!hasPrimitiveType(fields[index]) || isArray(fields[index])) - count++; - } - if (count == 0) - MessageDialog.openInformation(getShell(), DIALOG_TITLE, ActionMessages.AddDelegateMethodsAction_not_applicable); - return (count > 0); - } - - private boolean canRunOn(IType type) throws JavaScriptModelException { - if (type == null || type.getJavaScriptUnit() == null) { - MessageDialog.openInformation(getShell(), DIALOG_TITLE, ActionMessages.AddDelegateMethodsAction_not_in_source_file); - return false; - } - return canRunOn(type.getFields()); - } - - private IField[] getSelectedFields(IStructuredSelection selection) { - List elements= selection.toList(); - if (elements.size() > 0) { - IField[] result= new IField[elements.size()]; - IJavaScriptUnit unit= null; - for (int index= 0; index < elements.size(); index++) { - if (elements.get(index) instanceof IField) { - IField field= (IField) elements.get(index); - - if (index == 0) { - // remember the CU of the first element - unit= field.getJavaScriptUnit(); - if (unit == null) { - return null; - } - } else if (!unit.equals(field.getJavaScriptUnit())) { - // all fields must be in the same CU - return null; - } - - result[index]= field; - } else { - return null; - } - } - return result; - } - return null; - } - - /* - * (non-Javadoc) Method declared on SelectionDispatchAction - */ - 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 IJavaScriptUnit) - run(JavaElementUtil.getMainType((IJavaScriptUnit) 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); - } - - } - - /* - * (non-Javadoc) Method declared on SelectionDispatchAction - */ - public void run(ITextSelection selection) { - try { - if (!ActionUtil.isProcessable(fEditor)) - return; - - IJavaScriptElement[] elements= SelectionConverter.codeResolveForked(fEditor, true); - if (elements.length == 1 && (elements[0] instanceof IField)) { - IField field= (IField) elements[0]; - run(field.getDeclaringType(), new IField[] { field}, true); - return; - } - IJavaScriptElement element= SelectionConverter.getElementAtOffset(fEditor); - if (element != null) { - IType type= (IType) element.getAncestor(IJavaScriptElement.TYPE); - if (type != null) { - if (type.getFields().length > 0) { - run(type, new IField[0], true); - return; - } - } - } - MessageDialog.openInformation(getShell(), DIALOG_TITLE, ActionMessages.AddDelegateMethodsAction_not_applicable); - } catch (CoreException e) { - ExceptionHandler.handle(e, getShell(), DIALOG_TITLE, ActionMessages.AddDelegateMethodsAction_error_actionfailed); - } catch (InvocationTargetException e) { - ExceptionHandler.handle(e, getShell(), DIALOG_TITLE, ActionMessages.AddDelegateMethodsAction_error_actionfailed); - } catch (InterruptedException e) { - // cancelled - } - } - - private void run(IType type, IField[] preselected, boolean editor) throws CoreException { - if (!ElementValidator.check(type, getShell(), DIALOG_TITLE, editor)) - return; - if (!ActionUtil.isEditable(fEditor, getShell(), type)) - return; - if (!canRunOn(type)) - return; - showUI(type, preselected); - } - - // ---- Structured Viewer ----------------------------------------------------------- - - /* - * (non-Javadoc) Method declared on SelectionDispatchAction - */ - public void selectionChanged(IStructuredSelection selection) { - try { - setEnabled(canEnable(selection)); - } catch (JavaScriptModelException e) { - // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253 - if (JavaModelUtil.isExceptionToBeLogged(e)) - JavaScriptPlugin.log(e); - setEnabled(false); - } - } - - // ---- JavaScript Editor -------------------------------------------------------------- - - /* - * (non-Javadoc) Method declared on SelectionDispatchAction - */ - public void selectionChanged(ITextSelection selection) { - } - - private void showUI(IType type, IField[] fields) { - try { - AddDelegateMethodsContentProvider provider= new AddDelegateMethodsContentProvider(type, fields); - SourceActionDialog dialog= new AddDelegateMethodsDialog(getShell(), new AddDelegateMethodsLabelProvider(), provider, fEditor, type, false); - dialog.setValidator(new AddDelegateMethodsActionStatusValidator(provider.getCount())); - AddDelegateMethodsViewerComparator comparator= new AddDelegateMethodsViewerComparator(); - dialog.setComparator(comparator); - dialog.setInput(new Object()); - dialog.setContainerMode(true); - dialog.setMessage(ActionMessages.AddDelegateMethodsAction_message); - dialog.setTitle(ActionMessages.AddDelegateMethodsAction_title); - IVariableBinding[] expanded= provider.getExpandedElements(); - if (expanded.length > 0) { - dialog.setExpandedElements(expanded); - } else { - Object[] elements= provider.getElements(null); - if (elements.length > 0) { - comparator.sort(null, elements); - Object[] expand= { elements[0]}; - dialog.setExpandedElements(expand); - } - } - dialog.setInitialSelections(provider.getInitiallySelectedElements()); - dialog.setSize(60, 18); - int result= dialog.open(); - if (result == Window.OK) { - Object[] object= dialog.getResult(); - if (object == null) { - notifyResult(false); - return; - } - List tuples= new ArrayList(object.length); - for (int index= 0; index < object.length; index++) { - if (object[index] instanceof IBinding[]) - tuples.add(object[index]); - } - IEditorPart part= JavaScriptUI.openInEditor(type); - IRewriteTarget target= (IRewriteTarget) part.getAdapter(IRewriteTarget.class); - try { - if (target != null) - target.beginCompoundChange(); - CodeGenerationSettings settings= JavaPreferencesSettings.getCodeGenerationSettings(type.getJavaScriptProject()); - settings.createComments= dialog.getGenerateComment(); - final int size= tuples.size(); - String[] methodKeys= new String[size]; - String[] variableKeys= new String[size]; - for (int index= 0; index < size; index++) { - final IBinding[] tuple= (IBinding[]) tuples.get(index); - variableKeys[index]= tuple[0].getKey(); - methodKeys[index]= tuple[1].getKey(); - } - AddDelegateMethodsOperation operation= new AddDelegateMethodsOperation(type, dialog.getElementPosition(), provider.getCompilationUnit(), variableKeys, methodKeys, settings, true, false); - IRunnableContext context= JavaScriptPlugin.getActiveWorkbenchWindow(); - if (context == null) - context= new BusyIndicatorRunnableContext(); - try { - PlatformUI.getWorkbench().getProgressService().runInUI(context, new WorkbenchRunnableAdapter(operation, operation.getSchedulingRule()), operation.getSchedulingRule()); - } catch (InterruptedException exception) { - // User interruption - } - } finally { - if (target != null) - target.endCompoundChange(); - } - } - notifyResult(result == Window.OK); - } catch (CoreException exception) { - ExceptionHandler.handle(exception, DIALOG_TITLE, ActionMessages.AddDelegateMethodsAction_error_actionfailed); - } catch (InvocationTargetException e) { - ExceptionHandler.handle(e, DIALOG_TITLE, ActionMessages.AddDelegateMethodsAction_error_actionfailed); - } - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/AddGetterSetterAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/AddGetterSetterAction.java deleted file mode 100644 index 5da2e015..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/AddGetterSetterAction.java +++ /dev/null @@ -1,1083 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Philippe Ombredanne - bug 149382 - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.IDialogSettings; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.operation.IRunnableContext; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.text.IRewriteTarget; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.CheckboxTreeViewer; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerFilter; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Link; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.ISelectionStatusValidator; -import org.eclipse.wst.jsdt.core.Flags; -import org.eclipse.wst.jsdt.core.IField; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.IJavaScriptUnit; -import org.eclipse.wst.jsdt.core.IMember; -import org.eclipse.wst.jsdt.core.IType; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.core.Signature; -import org.eclipse.wst.jsdt.core.dom.AST; -import org.eclipse.wst.jsdt.core.dom.JavaScriptUnit; -import org.eclipse.wst.jsdt.internal.corext.codemanipulation.AddGetterSetterOperation; -import org.eclipse.wst.jsdt.internal.corext.codemanipulation.CodeGenerationSettings; -import org.eclipse.wst.jsdt.internal.corext.codemanipulation.GetterSetterUtil; -import org.eclipse.wst.jsdt.internal.corext.codemanipulation.IRequestQuery; -import org.eclipse.wst.jsdt.internal.corext.refactoring.util.RefactoringASTParser; -import org.eclipse.wst.jsdt.internal.corext.template.java.CodeTemplateContextType; -import org.eclipse.wst.jsdt.internal.corext.util.JavaModelUtil; -import org.eclipse.wst.jsdt.internal.corext.util.Messages; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.actions.WorkbenchRunnableAdapter; -import org.eclipse.wst.jsdt.internal.ui.dialogs.SourceActionDialog; -import org.eclipse.wst.jsdt.internal.ui.dialogs.StatusInfo; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.CompilationUnitEditor; -import org.eclipse.wst.jsdt.internal.ui.preferences.JavaPreferencesSettings; -import org.eclipse.wst.jsdt.internal.ui.util.BusyIndicatorRunnableContext; -import org.eclipse.wst.jsdt.internal.ui.util.ElementValidator; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; -import org.eclipse.wst.jsdt.internal.ui.viewsupport.JavaElementImageProvider; -import org.eclipse.wst.jsdt.ui.JavaScriptElementComparator; -import org.eclipse.wst.jsdt.ui.JavaScriptElementImageDescriptor; -import org.eclipse.wst.jsdt.ui.JavaScriptElementLabelProvider; -import org.eclipse.wst.jsdt.ui.JavaScriptElementLabels; -import org.eclipse.wst.jsdt.ui.JavaScriptUI; - -/** - * Creates getter and setter methods for a type's fields. Opens a dialog with a list of - * fields for which a setter or getter can be generated. User is able to check or uncheck - * items before setters or getters are generated. - * <p> - * Will open the parent compilation unit in a JavaScript editor. The result is unsaved, so the - * user can decide if the changes are acceptable. - * <p> - * The action is applicable to structured selections containing elements of type - * <code>IField</code> or <code>IType</code>. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class AddGetterSetterAction extends SelectionDispatchAction { - - private boolean fSort; - - //private boolean fFinal; - - private int fVisibility; - - private boolean fGenerateComment; - - private int fNumEntries; - - private CompilationUnitEditor fEditor; - - private static final String DIALOG_TITLE= ActionMessages.AddGetterSetterAction_error_title; - - /** - * Creates a new <code>AddGetterSetterAction</code>. The action requires that the - * selection provided by the site's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public AddGetterSetterAction(IWorkbenchSite site) { - super(site); - setText(ActionMessages.AddGetterSetterAction_label); - setDescription(ActionMessages.AddGetterSetterAction_description); - setToolTipText(ActionMessages.AddGetterSetterAction_tooltip); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.GETTERSETTER_ACTION); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this - * constructor. - * - * @param editor the compilation unit editor - */ - public AddGetterSetterAction(CompilationUnitEditor editor) { - this(editor.getEditorSite()); - fEditor= editor; - setEnabled(SelectionConverter.getInputAsCompilationUnit(editor) != null); - fEditor.getEditorSite(); - } - - // ---- Structured Viewer ----------------------------------------------------------- - - /* - * (non-Javadoc) Method declared on SelectionDispatchAction - */ - public void selectionChanged(IStructuredSelection selection) { - try { - setEnabled(canEnable(selection)); - } catch (JavaScriptModelException e) { - // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253 - if (JavaModelUtil.isExceptionToBeLogged(e)) - JavaScriptPlugin.log(e); - setEnabled(false); - } - } - - /* - * (non-Javadoc) Method declared on SelectionDispatchAction - */ - 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 IJavaScriptUnit) { - // http://bugs.eclipse.org/bugs/show_bug.cgi?id=38500 - IType type= ((IJavaScriptUnit) firstElement).findPrimaryType(); - // type can be null if file has a bad encoding - if (type == null) { - MessageDialog.openError(getShell(), - ActionMessages.AddGetterSetterAction_no_primary_type_title, - ActionMessages.AddGetterSetterAction_no_primary_type_message); - notifyResult(false); - return; - } - - run(((IJavaScriptUnit) firstElement).findPrimaryType(), new IField[0], false); - } - } catch (CoreException e) { - ExceptionHandler.handle(e, getShell(), DIALOG_TITLE, ActionMessages.AddGetterSetterAction_error_actionfailed); - } - - } - - private boolean canEnable(IStructuredSelection selection) throws JavaScriptModelException { - if (getSelectedFields(selection) != null) - return true; - - if ((selection.size() == 1) && (selection.getFirstElement() instanceof IType)) { - IType type= (IType) selection.getFirstElement(); - return type.getJavaScriptUnit() != null && !type.isLocal(); - } - - if ((selection.size() == 1) && (selection.getFirstElement() instanceof IJavaScriptUnit)) - return true; - - return false; - } - - private boolean canRunOn(IField[] fields) throws JavaScriptModelException { - if (fields == null || fields.length == 0) - return false; - int count= 0; - for (int index= 0; index < fields.length; index++) { - count++; - } - if (count == 0) - MessageDialog.openInformation(getShell(), DIALOG_TITLE, ActionMessages.AddGetterSetterAction_not_applicable); - return (count > 0); - } - - private void resetNumEntries() { - fNumEntries= 0; - } - - private void incNumEntries() { - fNumEntries++; - } - - private void run(IType type, IField[] preselected, boolean editor) throws CoreException { - if (type.getJavaScriptUnit() == null) { - MessageDialog.openInformation(getShell(), DIALOG_TITLE, ActionMessages.AddGetterSetterAction_error_not_in_source_file); - notifyResult(false); - return; - } - if (!ElementValidator.check(type, getShell(), DIALOG_TITLE, editor)) { - notifyResult(false); - return; - } - if (!ActionUtil.isEditable(getShell(), type)) { - notifyResult(false); - return; - } - - ILabelProvider lp= new AddGetterSetterLabelProvider(); - resetNumEntries(); - Map entries= createGetterSetterMapping(type); - if (entries.isEmpty()) { - MessageDialog.openInformation(getShell(), DIALOG_TITLE, ActionMessages.AddGettSetterAction_typeContainsNoFields_message); - notifyResult(false); - return; - } - AddGetterSetterContentProvider cp= new AddGetterSetterContentProvider(entries); - GetterSetterTreeSelectionDialog dialog= new GetterSetterTreeSelectionDialog(getShell(), lp, cp, fEditor, type); - dialog.setComparator(new JavaScriptElementComparator()); - dialog.setTitle(DIALOG_TITLE); - String message= ActionMessages.AddGetterSetterAction_dialog_label; - dialog.setMessage(message); - dialog.setValidator(createValidator(fNumEntries)); - dialog.setContainerMode(true); - dialog.setSize(60, 18); - dialog.setInput(type); - - if (preselected.length > 0) { - dialog.setInitialSelections(preselected); - dialog.setExpandedElements(preselected); - } - final Set keySet= new LinkedHashSet(entries.keySet()); - int dialogResult= dialog.open(); - if (dialogResult == Window.OK) { - Object[] result= dialog.getResult(); - if (result == null) { - notifyResult(false); - return; - } - fSort= dialog.getSortOrder(); - //fFinal= dialog.getFinal(); - fVisibility= dialog.getVisibilityModifier(); - fGenerateComment= dialog.getGenerateComment(); - IField[] getterFields, setterFields, getterSetterFields; - if (fSort) { - getterFields= getGetterFields(result, keySet); - setterFields= getSetterFields(result, keySet); - getterSetterFields= new IField[0]; - } else { - getterFields= getGetterOnlyFields(result, keySet); - setterFields= getSetterOnlyFields(result, keySet); - getterSetterFields= getGetterSetterFields(result, keySet); - } - generate(type, getterFields, setterFields, getterSetterFields, new RefactoringASTParser(AST.JLS3).parse(type.getJavaScriptUnit(), true), dialog.getElementPosition()); - } - notifyResult(dialogResult == Window.OK); - } - - private static class AddGetterSetterSelectionStatusValidator implements ISelectionStatusValidator { - - private static int fEntries; - - AddGetterSetterSelectionStatusValidator(int entries) { - fEntries= entries; - } - - public IStatus validate(Object[] selection) { - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=38478 - HashSet map= null; - if ((selection != null) && (selection.length > 1)) { - map= new HashSet(selection.length); - } - - int count= 0; - for (int i= 0; i < selection.length; i++) { - try { - if (selection[i] instanceof GetterSetterEntry) { - Object key= selection[i]; - IField getsetField= ((GetterSetterEntry) selection[i]).field; - if (((GetterSetterEntry) selection[i]).isGetter) { - if (!map.add(GetterSetterUtil.getGetterName(getsetField, null))) - return new StatusInfo(IStatus.WARNING, ActionMessages.AddGetterSetterAction_error_duplicate_methods); - } else { - key= createSignatureKey(GetterSetterUtil.getSetterName(getsetField, null), getsetField); - if (!map.add(key)) - return new StatusInfo(IStatus.WARNING, ActionMessages.AddGetterSetterAction_error_duplicate_methods); - } - count++; - } - } catch (JavaScriptModelException e) { - } - } - - if (count == 0) - return new StatusInfo(IStatus.ERROR, ""); //$NON-NLS-1$ - String message= Messages.format(ActionMessages.AddGetterSetterAction_methods_selected, - new Object[] { String.valueOf(count), String.valueOf(fEntries)}); - return new StatusInfo(IStatus.INFO, message); - } - } - - /** - * Creates a key used in hash maps for a method signature - * (gettersettername+arguments(fqn)). - */ - private static String createSignatureKey(String methodName, IField field) throws JavaScriptModelException { - StringBuffer buffer= new StringBuffer(); - buffer.append(methodName); - String fieldType= field.getTypeSignature(); - String signature= Signature.getSimpleName(Signature.toString(fieldType)); - buffer.append("#"); //$NON-NLS-1$ - buffer.append(signature); - - return buffer.toString(); - } - - private static ISelectionStatusValidator createValidator(int entries) { - AddGetterSetterSelectionStatusValidator validator= new AddGetterSetterSelectionStatusValidator(entries); - return validator; - } - - // returns a list of fields with setter entries checked - private static IField[] getSetterFields(Object[] result, Set set) { - List list= new ArrayList(0); - Object each= null; - GetterSetterEntry entry= null; - for (int i= 0; i < result.length; i++) { - each= result[i]; - if ((each instanceof GetterSetterEntry)) { - entry= (GetterSetterEntry) each; - if (!entry.isGetter) { - list.add(entry.field); - } - } - } - list= reorderFields(list, set); - return (IField[]) list.toArray(new IField[list.size()]); - } - - // returns a list of fields with getter entries checked - private static IField[] getGetterFields(Object[] result, Set set) { - List list= new ArrayList(0); - Object each= null; - GetterSetterEntry entry= null; - for (int i= 0; i < result.length; i++) { - each= result[i]; - if ((each instanceof GetterSetterEntry)) { - entry= (GetterSetterEntry) each; - if (entry.isGetter) { - list.add(entry.field); - } - } - } - list= reorderFields(list, set); - return (IField[]) list.toArray(new IField[list.size()]); - } - - // returns a list of fields with only getter entries checked - private static IField[] getGetterOnlyFields(Object[] result, Set set) { - List list= new ArrayList(0); - Object each= null; - GetterSetterEntry entry= null; - boolean getterSet= false; - for (int i= 0; i < result.length; i++) { - each= result[i]; - if ((each instanceof GetterSetterEntry)) { - entry= (GetterSetterEntry) each; - if (entry.isGetter) { - list.add(entry.field); - getterSet= true; - } - if ((!entry.isGetter) && (getterSet == true)) { - list.remove(entry.field); - getterSet= false; - } - } else - getterSet= false; - } - list= reorderFields(list, set); - return (IField[]) list.toArray(new IField[list.size()]); - } - - // returns a list of fields with only setter entries checked - private static IField[] getSetterOnlyFields(Object[] result, Set set) { - List list= new ArrayList(0); - Object each= null; - GetterSetterEntry entry= null; - boolean getterSet= false; - for (int i= 0; i < result.length; i++) { - each= result[i]; - if ((each instanceof GetterSetterEntry)) { - entry= (GetterSetterEntry) each; - if (entry.isGetter) { - getterSet= true; - } - if ((!entry.isGetter) && (getterSet != true)) { - list.add(entry.field); - getterSet= false; - } - } else - getterSet= false; - } - list= reorderFields(list, set); - return (IField[]) list.toArray(new IField[list.size()]); - } - - // returns a list of fields with both entries checked - private static IField[] getGetterSetterFields(Object[] result, Set set) { - List list= new ArrayList(0); - Object each= null; - GetterSetterEntry entry= null; - boolean getterSet= false; - for (int i= 0; i < result.length; i++) { - each= result[i]; - if ((each instanceof GetterSetterEntry)) { - entry= (GetterSetterEntry) each; - if (entry.isGetter) { - getterSet= true; - } - if ((!entry.isGetter) && (getterSet == true)) { - list.add(entry.field); - getterSet= false; - } - } else - getterSet= false; - } - list= reorderFields(list, set); - return (IField[]) list.toArray(new IField[list.size()]); - } - - private static List reorderFields(List collection, Set set) { - final List list= new ArrayList(collection.size()); - for (final Iterator iterator= set.iterator(); iterator.hasNext();) { - final IField field= (IField) iterator.next(); - if (collection.contains(field)) - list.add(field); - } - return list; - } - - private void generate(IType type, IField[] getterFields, IField[] setterFields, IField[] getterSetterFields, JavaScriptUnit unit, IJavaScriptElement elementPosition) throws CoreException { - if (getterFields.length == 0 && setterFields.length == 0 && getterSetterFields.length == 0) - return; - - IJavaScriptUnit cu= null; - if (getterFields.length != 0) - cu= getterFields[0].getJavaScriptUnit(); - else if (setterFields.length != 0) - cu= setterFields[0].getJavaScriptUnit(); - else - cu= getterSetterFields[0].getJavaScriptUnit(); - // open the editor, forces the creation of a working copy - run(cu, type, getterFields, setterFields, getterSetterFields, JavaScriptUI.openInEditor(cu), unit, elementPosition); - } - - // ---- JavaScript Editor -------------------------------------------------------------- - - /* - * (non-Javadoc) Method declared on SelectionDispatchAction - */ - public void selectionChanged(ITextSelection selection) { - } - - /* - * (non-Javadoc) Method declared on SelectionDispatchAction - */ - public void run(ITextSelection selection) { - try { - if (!ActionUtil.isProcessable(fEditor)) { - notifyResult(false); - return; - } - - IJavaScriptElement[] elements= SelectionConverter.codeResolveForked(fEditor, true); - if (elements.length == 1 && (elements[0] instanceof IField)) { - IField field= (IField) elements[0]; - run(field.getDeclaringType(), new IField[] { field}, true); - return; - } - IJavaScriptElement element= SelectionConverter.getElementAtOffset(fEditor); - - if (element != null) { - IType type= (IType) element.getAncestor(IJavaScriptElement.TYPE); - if (type != null) { - if (type.getFields().length > 0) { - run(type, new IField[0], true); - return; - } - } - } - MessageDialog.openInformation(getShell(), DIALOG_TITLE, ActionMessages.AddGetterSetterAction_not_applicable); - } catch (CoreException e) { - ExceptionHandler.handle(e, getShell(), DIALOG_TITLE, ActionMessages.AddGetterSetterAction_error_actionfailed); - } catch (InvocationTargetException e) { - ExceptionHandler.handle(e, getShell(), DIALOG_TITLE, ActionMessages.AddGetterSetterAction_error_actionfailed); - } catch (InterruptedException e) { - // cancelled - } - } - - // ---- Helpers ------------------------------------------------------------------- - - private void run(IJavaScriptUnit cu, IType type, IField[] getterFields, IField[] setterFields, IField[] getterSetterFields, IEditorPart editor, JavaScriptUnit unit, IJavaScriptElement elementPosition) { - IRewriteTarget target= (IRewriteTarget) editor.getAdapter(IRewriteTarget.class); - if (target != null) { - target.beginCompoundChange(); - } - try { - CodeGenerationSettings settings= JavaPreferencesSettings.getCodeGenerationSettings(cu.getJavaScriptProject()); - settings.createComments= fGenerateComment; - - AddGetterSetterOperation op= new AddGetterSetterOperation(type, getterFields, setterFields, getterSetterFields, unit, skipReplaceQuery(), elementPosition, settings, true, false); - setOperationStatusFields(op); - - IRunnableContext context= JavaScriptPlugin.getActiveWorkbenchWindow(); - if (context == null) { - context= new BusyIndicatorRunnableContext(); - } - - PlatformUI.getWorkbench().getProgressService().runInUI(context, new WorkbenchRunnableAdapter(op, op.getSchedulingRule()), op.getSchedulingRule()); - - } catch (InvocationTargetException e) { - String message= ActionMessages.AddGetterSetterAction_error_actionfailed; - ExceptionHandler.handle(e, getShell(), DIALOG_TITLE, message); - } catch (InterruptedException e) { - // operation canceled - } finally { - if (target != null) { - target.endCompoundChange(); - } - } - } - - private void setOperationStatusFields(AddGetterSetterOperation op) { - // Set the status fields corresponding to the visibility and modifiers set - int flags= fVisibility; - - op.setSort(fSort); - op.setVisibility(flags); - } - - private IRequestQuery skipReplaceQuery() { - return new IRequestQuery() { - - public int doQuery(IMember method) { - int[] returnCodes= { IRequestQuery.YES, IRequestQuery.NO, IRequestQuery.YES_ALL, IRequestQuery.CANCEL}; - String skipLabel= ActionMessages.AddGetterSetterAction_SkipExistingDialog_skip_label; - String replaceLabel= ActionMessages.AddGetterSetterAction_SkipExistingDialog_replace_label; - String skipAllLabel= ActionMessages.AddGetterSetterAction_SkipExistingDialog_skipAll_label; - String[] options= { skipLabel, replaceLabel, skipAllLabel, IDialogConstants.CANCEL_LABEL}; - String methodName= JavaScriptElementLabels.getElementLabel(method, JavaScriptElementLabels.M_PARAMETER_TYPES); - String formattedMessage= Messages.format(ActionMessages.AddGetterSetterAction_SkipExistingDialog_message, methodName); - return showQueryDialog(formattedMessage, options, returnCodes); - } - }; - } - - private int showQueryDialog(final String message, final String[] buttonLabels, int[] returnCodes) { - final Shell shell= getShell(); - if (shell == null) { - JavaScriptPlugin.logErrorMessage("AddGetterSetterAction.showQueryDialog: No active shell found"); //$NON-NLS-1$ - return IRequestQuery.CANCEL; - } - final int[] result= { Window.CANCEL}; - shell.getDisplay().syncExec(new Runnable() { - - public void run() { - String title= ActionMessages.AddGetterSetterAction_QueryDialog_title; - MessageDialog dialog= new MessageDialog(shell, title, null, message, MessageDialog.QUESTION, buttonLabels, 0); - result[0]= dialog.open(); - } - }); - int returnVal= result[0]; - return returnVal < 0 ? IRequestQuery.CANCEL : returnCodes[returnVal]; - } - - /* - * Returns fields in the selection or <code>null</code> if the selection is empty or - * not valid. - */ - private IField[] getSelectedFields(IStructuredSelection selection) { - List elements= selection.toList(); - int nElements= elements.size(); - if (nElements > 0) { - IField[] res= new IField[nElements]; - IJavaScriptUnit cu= null; - for (int i= 0; i < nElements; i++) { - Object curr= elements.get(i); - if (curr instanceof IField) { - IField fld= (IField) curr; - - if (i == 0) { - // remember the cu of the first element - cu= fld.getJavaScriptUnit(); - if (cu == null) { - return null; - } - } else if (!cu.equals(fld.getJavaScriptUnit())) { - // all fields must be in the same CU - return null; - } - - final IType declaringType= fld.getDeclaringType(); - if (declaringType==null) - return null; - - res[i]= fld; - } else { - return null; - } - } - return res; - } - return null; - } - - private static class AddGetterSetterLabelProvider extends JavaScriptElementLabelProvider { - - AddGetterSetterLabelProvider() { - } - - /* - * @see ILabelProvider#getText(Object) - */ - public String getText(Object element) { - if (element instanceof GetterSetterEntry) { - GetterSetterEntry entry= (GetterSetterEntry) element; - try { - if (entry.isGetter) { - return GetterSetterUtil.getGetterName(entry.field, null) + "()"; //$NON-NLS-1$ - } else { - return GetterSetterUtil.getSetterName(entry.field, null) + '(' + Signature.getSimpleName(Signature.toString(entry.field.getTypeSignature())) + ')'; - } - } catch (JavaScriptModelException e) { - return ""; //$NON-NLS-1$ - } - } - return super.getText(element); - } - - /* - * @see ILabelProvider#getImage(Object) - */ - public Image getImage(Object element) { - if (element instanceof GetterSetterEntry) { - int flags= 0; - try { - flags= ((GetterSetterEntry) element).field.getFlags(); - } catch (JavaScriptModelException e) { - JavaScriptPlugin.log(e); - } - ImageDescriptor desc= JavaElementImageProvider.getFieldImageDescriptor(false, Flags.AccPublic); - int adornmentFlags= Flags.isStatic(flags) ? JavaScriptElementImageDescriptor.STATIC : 0; - desc= new JavaScriptElementImageDescriptor(desc, adornmentFlags, JavaElementImageProvider.BIG_SIZE); - return JavaScriptPlugin.getImageDescriptorRegistry().get(desc); - } - return super.getImage(element); - } - } - - /** - * @return map IField -> GetterSetterEntry[] - */ - private Map createGetterSetterMapping(IType type) throws JavaScriptModelException { - IField[] fields= type.getFields(); - Map result= new LinkedHashMap(); - for (int i= 0; i < fields.length; i++) { - IField field= fields[i]; - - List l= new ArrayList(2); - if (GetterSetterUtil.getGetter(field) == null) { - l.add(new GetterSetterEntry(field, true, false)); - incNumEntries(); - } - - if (GetterSetterUtil.getSetter(field) == null) { - l.add(new GetterSetterEntry(field, false, false)); - incNumEntries(); - } - - if (!l.isEmpty()) - result.put(field, l.toArray(new GetterSetterEntry[l.size()])); - - } - return result; - } - - private static class AddGetterSetterContentProvider implements ITreeContentProvider { - - private static final Object[] EMPTY= new Object[0]; - - //private Viewer fViewer; - - private Map fGetterSetterEntries; - - public AddGetterSetterContentProvider(Map entries) { - fGetterSetterEntries= entries; - } - - /* - * @see IContentProvider#inputChanged(Viewer, Object, Object) - */ - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - //fViewer= viewer; - } - -// public Viewer getViewer() { -// return fViewer; -// } - - /* - * @see ITreeContentProvider#getChildren(Object) - */ - public Object[] getChildren(Object parentElement) { - if (parentElement instanceof IField) - return (Object[]) fGetterSetterEntries.get(parentElement); - return EMPTY; - } - - /* - * @see ITreeContentProvider#getParent(Object) - */ - public Object getParent(Object element) { - if (element instanceof IMember) - { IMember member=(IMember) element; - return member.getDeclaringType()!=null ? - member.getDeclaringType() :(Object)member.getJavaScriptUnit(); - } - if (element instanceof GetterSetterEntry) - return ((GetterSetterEntry) element).field; - return null; - } - - /* - * @see ITreeContentProvider#hasChildren(Object) - */ - public boolean hasChildren(Object element) { - return getChildren(element).length > 0; - } - - /* - * @see IStructuredContentProvider#getElements(Object) - */ - public Object[] getElements(Object inputElement) { - return fGetterSetterEntries.keySet().toArray(); - } - - /* - * @see IContentProvider#dispose() - */ - public void dispose() { - fGetterSetterEntries.clear(); - fGetterSetterEntries= null; - } - } - - private static class SettersForFinalFieldsFilter extends ViewerFilter { - - private final AddGetterSetterContentProvider fContentProvider; - - public SettersForFinalFieldsFilter(AddGetterSetterContentProvider contentProvider) { - fContentProvider= contentProvider; - } - - public boolean select(Viewer viewer, Object parentElement, Object element) { - if (element instanceof GetterSetterEntry) { - GetterSetterEntry getterSetterEntry= (GetterSetterEntry) element; - return getterSetterEntry.isGetter || !getterSetterEntry.isFinal; - } else if (element instanceof IField) { - Object[] children= fContentProvider.getChildren(element); - for (int i= 0; i < children.length; i++) { - GetterSetterEntry curr= (GetterSetterEntry) children[i]; - if (curr.isGetter || !curr.isFinal) { - return true; - } - } - return false; - } - return true; - } - } - - - private static class GetterSetterTreeSelectionDialog extends SourceActionDialog { - - private AddGetterSetterContentProvider fContentProvider; - - private static final int SELECT_GETTERS_ID= IDialogConstants.CLIENT_ID + 1; - private static final int SELECT_SETTERS_ID= IDialogConstants.CLIENT_ID + 2; - private final String SETTINGS_SECTION= "AddGetterSetterDialog"; //$NON-NLS-1$ - private final String SORT_ORDER= "SortOrdering"; //$NON-NLS-1$ - private final String ALLOW_SETTERS_FOR_FINALS= "RemoveFinal"; //$NON-NLS-1$ - - private IDialogSettings fSettings; - private SettersForFinalFieldsFilter fSettersForFinalFieldsFilter; - - private boolean fSortOrder; - private boolean fAllowSettersForFinals; - - private ArrayList fPreviousSelectedFinals; - - - public GetterSetterTreeSelectionDialog(Shell parent, ILabelProvider labelProvider, AddGetterSetterContentProvider contentProvider, CompilationUnitEditor editor, IType type) throws JavaScriptModelException { - super(parent, labelProvider, contentProvider, editor, type, false); - fContentProvider= contentProvider; - fPreviousSelectedFinals= new ArrayList(); - - // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253 - IDialogSettings dialogSettings= JavaScriptPlugin.getDefault().getDialogSettings(); - fSettings= dialogSettings.getSection(SETTINGS_SECTION); - if (fSettings == null) { - fSettings= dialogSettings.addNewSection(SETTINGS_SECTION); - fSettings.put(SORT_ORDER, false); - fSettings.put(ALLOW_SETTERS_FOR_FINALS, false); - } - - fSortOrder= fSettings.getBoolean(SORT_ORDER); - fAllowSettersForFinals= fSettings.getBoolean(ALLOW_SETTERS_FOR_FINALS); - - fSettersForFinalFieldsFilter= new SettersForFinalFieldsFilter(contentProvider); - } - - public boolean getSortOrder() { - return fSortOrder; - } - - public void setSortOrder(boolean sort) { - if (fSortOrder != sort) { - fSortOrder= sort; - fSettings.put(SORT_ORDER, sort); - if (getTreeViewer() != null) { - getTreeViewer().refresh(); - } - } - } - - private boolean allowSettersForFinals() { - return fAllowSettersForFinals; - } - - public void allowSettersForFinals(boolean allowSettersForFinals) { - if (fAllowSettersForFinals != allowSettersForFinals) { - fAllowSettersForFinals= allowSettersForFinals; - fSettings.put(ALLOW_SETTERS_FOR_FINALS, allowSettersForFinals); - CheckboxTreeViewer treeViewer= getTreeViewer(); - if (treeViewer != null) { - ArrayList newChecked= new ArrayList(); - if (allowSettersForFinals) { - newChecked.addAll(fPreviousSelectedFinals); - } - fPreviousSelectedFinals.clear(); - Object[] checkedElements= treeViewer.getCheckedElements(); - for (int i= 0; i < checkedElements.length; i++) { - if (checkedElements[i] instanceof GetterSetterEntry) { - GetterSetterEntry entry= (GetterSetterEntry) checkedElements[i]; - if (allowSettersForFinals || entry.isGetter || !entry.isFinal) { - newChecked.add(entry); - } else { - fPreviousSelectedFinals.add(entry); - } - } - } - if (allowSettersForFinals) { - treeViewer.removeFilter(fSettersForFinalFieldsFilter); - } else { - treeViewer.addFilter(fSettersForFinalFieldsFilter); - } - treeViewer.setCheckedElements(newChecked.toArray()); - } - updateOKStatus(); - } - } - - /* (non-Javadoc) - * @see org.eclipse.ui.dialogs.CheckedTreeSelectionDialog#createTreeViewer(org.eclipse.swt.widgets.Composite) - */ - protected CheckboxTreeViewer createTreeViewer(Composite parent) { - CheckboxTreeViewer treeViewer= super.createTreeViewer(parent); - if (!fAllowSettersForFinals) { - treeViewer.addFilter(fSettersForFinalFieldsFilter); - } - return treeViewer; - } - - protected void configureShell(Shell shell) { - super.configureShell(shell); - PlatformUI.getWorkbench().getHelpSystem().setHelp(shell, IJavaHelpContextIds.ADD_GETTER_SETTER_SELECTION_DIALOG); - } - - private void createGetterSetterButtons(Composite buttonComposite) { - createButton(buttonComposite, SELECT_GETTERS_ID, ActionMessages.GetterSetterTreeSelectionDialog_select_getters, false); - createButton(buttonComposite, SELECT_SETTERS_ID, ActionMessages.GetterSetterTreeSelectionDialog_select_setters, false); - } - - protected void buttonPressed(int buttonId) { - super.buttonPressed(buttonId); - switch (buttonId) { - case SELECT_GETTERS_ID: { - getTreeViewer().setCheckedElements(getGetterSetterElements(true)); - updateOKStatus(); - break; - } - case SELECT_SETTERS_ID: { - getTreeViewer().setCheckedElements(getGetterSetterElements(false)); - updateOKStatus(); - break; - } - } - } - - protected Composite createInsertPositionCombo(Composite composite) { - Button addRemoveFinalCheckbox= addAllowSettersForFinalslCheckbox(composite); - addRemoveFinalCheckbox.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - Composite entryComposite= super.createInsertPositionCombo(composite); - addSortOrder(entryComposite); - addVisibilityAndModifiersChoices(entryComposite); - return entryComposite; - } - - private Button addAllowSettersForFinalslCheckbox(Composite entryComposite) { - Button allowSettersForFinalsButton= new Button(entryComposite, SWT.CHECK); - allowSettersForFinalsButton.setText(ActionMessages.AddGetterSetterAction_allow_setters_for_finals_description); - - allowSettersForFinalsButton.addSelectionListener(new SelectionListener() { - public void widgetSelected(SelectionEvent e) { - boolean isSelected= (((Button) e.widget).getSelection()); - allowSettersForFinals(isSelected); - } - - public void widgetDefaultSelected(SelectionEvent e) { - widgetSelected(e); - } - }); - allowSettersForFinalsButton.setSelection(allowSettersForFinals()); - return allowSettersForFinalsButton; - } - - private Composite addSortOrder(Composite composite) { - Label label= new Label(composite, SWT.NONE); - label.setText(ActionMessages.GetterSetterTreeSelectionDialog_sort_label); - GridData gd= new GridData(GridData.FILL_BOTH); - label.setLayoutData(gd); - - final Combo combo= new Combo(composite, SWT.READ_ONLY); - combo.setItems(new String[] { ActionMessages.GetterSetterTreeSelectionDialog_alpha_pair_sort, - ActionMessages.GetterSetterTreeSelectionDialog_alpha_method_sort}); - final int methodIndex= 1; // Hard-coded. Change this if the - // list gets more complicated. - // http://bugs.eclipse.org/bugs/show_bug.cgi?id=38400 - int sort= getSortOrder() ? 1 : 0; - combo.setText(combo.getItem(sort)); - gd= new GridData(GridData.FILL_BOTH); - combo.setLayoutData(gd); - combo.addSelectionListener(new SelectionAdapter() { - - public void widgetSelected(SelectionEvent e) { - setSortOrder(combo.getSelectionIndex() == methodIndex); - } - }); - return composite; - } - - private Object[] getGetterSetterElements(boolean isGetter) { - Object[] allFields= fContentProvider.getElements(null); - Set result= new HashSet(); - for (int i= 0; i < allFields.length; i++) { - IField field= (IField) allFields[i]; - GetterSetterEntry[] entries= getEntries(field); - for (int j= 0; j < entries.length; j++) { - AddGetterSetterAction.GetterSetterEntry entry= entries[j]; - if (entry.isGetter == isGetter) - result.add(entry); - } - } - return result.toArray(); - } - - private GetterSetterEntry[] getEntries(IField field) { - List result= Arrays.asList(fContentProvider.getChildren(field)); - return (GetterSetterEntry[]) result.toArray(new GetterSetterEntry[result.size()]); - } - - protected Composite createSelectionButtons(Composite composite) { - Composite buttonComposite= super.createSelectionButtons(composite); - - GridLayout layout= new GridLayout(); - buttonComposite.setLayout(layout); - - createGetterSetterButtons(buttonComposite); - - layout.marginHeight= 0; - layout.marginWidth= 0; - layout.numColumns= 1; - - return buttonComposite; - } - - /* - * @see org.eclipse.wst.jsdt.internal.ui.dialogs.SourceActionDialog#createLinkControl(org.eclipse.swt.widgets.Composite) - */ - protected Control createLinkControl(Composite composite) { - Link link= new Link(composite, SWT.WRAP); - link.setText(ActionMessages.AddGetterSetterAction_template_link_description); - link.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - openCodeTempatePage(CodeTemplateContextType.GETTERCOMMENT_ID); - } - }); - link.setToolTipText(ActionMessages.AddGetterSetterAction_template_link_tooltip); - - GridData gridData= new GridData(SWT.FILL, SWT.BEGINNING, true, false); - gridData.widthHint= convertWidthInCharsToPixels(40); // only expand further if anyone else requires it - link.setLayoutData(gridData); - return link; - } - } - - private static class GetterSetterEntry { - public final IField field; - public final boolean isGetter; - public final boolean isFinal; - - GetterSetterEntry(IField field, boolean isGetterEntry, boolean isFinal) { - this.field= field; - this.isGetter= isGetterEntry; - this.isFinal= isFinal; - } - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/AddJavaDocStubAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/AddJavaDocStubAction.java deleted file mode 100644 index 1d6b186a..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/AddJavaDocStubAction.java +++ /dev/null @@ -1,223 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.lang.reflect.InvocationTargetException; -import java.util.List; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IJavaScriptUnit; -import org.eclipse.wst.jsdt.core.IField; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.IMember; -import org.eclipse.wst.jsdt.core.IFunction; -import org.eclipse.wst.jsdt.core.IType; -import org.eclipse.wst.jsdt.internal.corext.codemanipulation.AddJavaDocStubOperation; -import org.eclipse.wst.jsdt.internal.corext.util.JavaModelUtil; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.actions.WorkbenchRunnableAdapter; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.CompilationUnitEditor; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.EditorUtility; -import org.eclipse.wst.jsdt.internal.ui.util.ElementValidator; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; -import org.eclipse.wst.jsdt.ui.JavaScriptUI; - -/** - * Create Javadoc comment stubs for the selected members. - * <p> - * Will open the parent compilation unit in a JavaScript editor. The result is - * unsaved, so the user can decide if the changes are acceptable. - * <p> - * The action is applicable to structured selections containing elements - * of type <code>IMember</code>. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class AddJavaDocStubAction extends SelectionDispatchAction { - - private CompilationUnitEditor fEditor; - - /** - * Creates a new <code>AddJavaDocStubAction</code>. The action requires - * that the selection provided by the site's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public AddJavaDocStubAction(IWorkbenchSite site) { - super(site); - setText(ActionMessages.AddJavaDocStubAction_label); - setDescription(ActionMessages.AddJavaDocStubAction_description); - setToolTipText(ActionMessages.AddJavaDocStubAction_tooltip); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.ADD_JAVADOC_STUB_ACTION); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the compilation unit editor - */ - public AddJavaDocStubAction(CompilationUnitEditor editor) { - this(editor.getEditorSite()); - fEditor= editor; - setEnabled(checkEnabledEditor()); - } - - //---- Structured Viewer ----------------------------------------------------------- - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction - */ - public void selectionChanged(IStructuredSelection selection) { - IMember[] members= getSelectedMembers(selection); - setEnabled(members != null && members.length > 0); - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction - */ - public void run(IStructuredSelection selection) { - IMember[] members= getSelectedMembers(selection); - if (members == null || members.length == 0) { - return; - } - - try { - IJavaScriptUnit cu= members[0].getJavaScriptUnit(); - if (!ActionUtil.isEditable(getShell(), cu)) { - return; - } - - // open the editor, forces the creation of a working copy - IEditorPart editor= JavaScriptUI.openInEditor(cu); - - if (ElementValidator.check(members, getShell(), getDialogTitle(), false)) - run(cu, members); - JavaModelUtil.reconcile(cu); - EditorUtility.revealInEditor(editor, members[0]); - - } catch (CoreException e) { - ExceptionHandler.handle(e, getShell(), getDialogTitle(), ActionMessages.AddJavaDocStubsAction_error_actionFailed); - } - } - - //---- JavaScript Editor -------------------------------------------------------------- - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction - */ - public void selectionChanged(ITextSelection selection) { - } - - private boolean checkEnabledEditor() { - return fEditor != null && SelectionConverter.canOperateOn(fEditor); - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction - */ - public void run(ITextSelection selection) { - try { - IJavaScriptElement element= SelectionConverter.getElementAtOffset(fEditor); - if (!ActionUtil.isEditable(fEditor, getShell(), element)) - return; - int type= element != null ? element.getElementType() : -1; - if (type != IJavaScriptElement.METHOD && type != IJavaScriptElement.TYPE && type != IJavaScriptElement.FIELD) { - element= SelectionConverter.getTypeAtOffset(fEditor); - if (element == null) { - MessageDialog.openInformation(getShell(), getDialogTitle(), - ActionMessages.AddJavaDocStubsAction_not_applicable); - return; - } - } - IMember[] members= new IMember[] { (IMember)element }; - if (ElementValidator.checkValidateEdit(members, getShell(), getDialogTitle())) - run(members[0].getJavaScriptUnit(), members); - } catch (CoreException e) { - ExceptionHandler.handle(e, getShell(), getDialogTitle(), ActionMessages.AddJavaDocStubsAction_error_actionFailed); - } - } - - //---- Helpers ------------------------------------------------------------------- - - /** - * Note this method is for internal use only. - * - * @param cu the compilation unit - * @param members an array of members - */ - public void run(IJavaScriptUnit cu, IMember[] members) { - try { - AddJavaDocStubOperation op= new AddJavaDocStubOperation(members); - PlatformUI.getWorkbench().getProgressService().runInUI( - PlatformUI.getWorkbench().getProgressService(), - new WorkbenchRunnableAdapter(op, op.getScheduleRule()), - op.getScheduleRule()); - } catch (InvocationTargetException e) { - ExceptionHandler.handle(e, getShell(), getDialogTitle(), ActionMessages.AddJavaDocStubsAction_error_actionFailed); - } catch (InterruptedException e) { - // operation canceled - } - } - - private IMember[] getSelectedMembers(IStructuredSelection selection) { - List elements= selection.toList(); - int nElements= elements.size(); - if (nElements > 0) { - IMember[] res= new IMember[nElements]; - IJavaScriptUnit cu= null; - for (int i= 0; i < nElements; i++) { - Object curr= elements.get(i); - if (curr instanceof IFunction || curr instanceof IType || curr instanceof IField) { - IMember member= (IMember)curr; // limit to methods, types & fields - if (! member.exists()) { - return null; - } - if (i == 0) { - cu= member.getJavaScriptUnit(); - if (cu == null) { - return null; - } - } else if (!cu.equals(member.getJavaScriptUnit())) { - return null; - } - if (member instanceof IType && member.getElementName().length() == 0) { - return null; // anonymous type - } - res[i]= member; - } else { - return null; - } - } - return res; - } - return null; - } - - private String getDialogTitle() { - return ActionMessages.AddJavaDocStubsAction_error_dialogTitle; - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/AddToClasspathAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/AddToClasspathAction.java deleted file mode 100644 index e87a176e..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/AddToClasspathAction.java +++ /dev/null @@ -1,166 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Iterator; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IIncludePathEntry; -import org.eclipse.wst.jsdt.core.IJavaScriptProject; -import org.eclipse.wst.jsdt.core.JavaScriptCore; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.internal.corext.util.JavaModelUtil; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages; -import org.eclipse.wst.jsdt.internal.ui.actions.WorkbenchRunnableAdapter; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; -import org.eclipse.wst.jsdt.internal.ui.wizards.buildpaths.ArchiveFileFilter; - -/** - * Action to add a JAR to the classpath of its parent project. - * Action is applicable to selections containing archives (JAR or zip) - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class AddToClasspathAction extends SelectionDispatchAction { - - /** - * Creates a new <code>AddToClasspathAction</code>. The action requires that - * the selection provided by the site's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public AddToClasspathAction(IWorkbenchSite site) { - super(site); - setText(ActionMessages.AddToClasspathAction_label); - setToolTipText(ActionMessages.AddToClasspathAction_toolTip); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.ADD_TO_CLASSPATH_ACTION); - } - - /* (non-Javadoc) - * Method declared in SelectionDispatchAction - */ - public void selectionChanged(IStructuredSelection selection) { - try { - setEnabled(checkEnabled(selection)); - } catch (JavaScriptModelException e) { - // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253 - if (JavaModelUtil.isExceptionToBeLogged(e)) - JavaScriptPlugin.log(e); - setEnabled(false); - } - } - - private static boolean checkEnabled(IStructuredSelection selection) throws JavaScriptModelException { - if (selection.isEmpty()) - return false; - for (Iterator iter= selection.iterator(); iter.hasNext();) { - if (! canBeAddedToBuildPath(iter.next())) - return false; - } - return true; - } - - private static boolean canBeAddedToBuildPath(Object element) throws JavaScriptModelException{ - return (element instanceof IAdaptable) && getCandidate((IAdaptable) element) != null; - } - - private static IFile getCandidate(IAdaptable element) throws JavaScriptModelException { - IResource resource= (IResource)element.getAdapter(IResource.class); - if (! (resource instanceof IFile) || ! ArchiveFileFilter.isArchivePath(resource.getFullPath())) - return null; - - IJavaScriptProject project= JavaScriptCore.create(resource.getProject()); - if (project != null && project.exists() && (project.findPackageFragmentRoot(resource.getFullPath()) == null)) - return (IFile) resource; - return null; - } - - /* (non-Javadoc) - * Method declared in SelectionDispatchAction - */ - public void run(IStructuredSelection selection) { - try { - final IFile[] files= getJARFiles(selection); - - IWorkspaceRunnable operation= new IWorkspaceRunnable() { - public void run(IProgressMonitor monitor) throws CoreException { - monitor.beginTask(ActionMessages.AddToClasspathAction_progressMessage, files.length); - for (int i= 0; i < files.length; i++) { - monitor.subTask(files[i].getFullPath().toString()); - IJavaScriptProject project= JavaScriptCore.create(files[i].getProject()); - addToClassPath(project, files[i].getFullPath(), new SubProgressMonitor(monitor, 1)); - } - } - - private void addToClassPath(IJavaScriptProject project, IPath jarPath, IProgressMonitor monitor) throws JavaScriptModelException { - if (monitor.isCanceled()) - throw new OperationCanceledException(); - IIncludePathEntry[] entries= project.getRawIncludepath(); - IIncludePathEntry[] newEntries= new IIncludePathEntry[entries.length + 1]; - System.arraycopy(entries, 0, newEntries, 0, entries.length); - newEntries[entries.length]= JavaScriptCore.newLibraryEntry(jarPath, null, null, false); - project.setRawIncludepath(newEntries, monitor); - } - }; - - PlatformUI.getWorkbench().getActiveWorkbenchWindow().run(true, true, new WorkbenchRunnableAdapter(operation)); - } catch (InvocationTargetException e) { - ExceptionHandler.handle(e, getShell(), - ActionMessages.AddToClasspathAction_error_title, - ActionMessages.AddToClasspathAction_error_message); - } catch (JavaScriptModelException e) { - ExceptionHandler.handle(e, getShell(), - ActionMessages.AddToClasspathAction_error_title, - ActionMessages.AddToClasspathAction_error_message); - } catch (InterruptedException e) { - // canceled - } - - } - - private static IFile[] getJARFiles(IStructuredSelection selection) throws JavaScriptModelException { - ArrayList list= new ArrayList(); - for (Iterator iter= selection.iterator(); iter.hasNext();) { - Object element= iter.next(); - if (element instanceof IAdaptable) { - IFile file= getCandidate((IAdaptable) element); - if (file != null) { - list.add(file); - } - } - } - return (IFile[]) list.toArray(new IFile[list.size()]); - } -} - diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/AddUnimplementedConstructorsAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/AddUnimplementedConstructorsAction.java deleted file mode 100644 index 8819fb2a..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/AddUnimplementedConstructorsAction.java +++ /dev/null @@ -1,597 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; - -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.IDialogSettings; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.operation.IRunnableContext; -import org.eclipse.jface.text.IRewriteTarget; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.CheckboxTreeViewer; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Link; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.ISelectionStatusValidator; -import org.eclipse.wst.jsdt.core.IJavaScriptUnit; -import org.eclipse.wst.jsdt.core.IType; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.core.dom.AST; -import org.eclipse.wst.jsdt.core.dom.AbstractTypeDeclaration; -import org.eclipse.wst.jsdt.core.dom.JavaScriptUnit; -import org.eclipse.wst.jsdt.core.dom.IFunctionBinding; -import org.eclipse.wst.jsdt.core.dom.ITypeBinding; -import org.eclipse.wst.jsdt.internal.corext.codemanipulation.AddUnimplementedConstructorsOperation; -import org.eclipse.wst.jsdt.internal.corext.codemanipulation.CodeGenerationSettings; -import org.eclipse.wst.jsdt.internal.corext.codemanipulation.StubUtility2; -import org.eclipse.wst.jsdt.internal.corext.dom.ASTNodes; -import org.eclipse.wst.jsdt.internal.corext.dom.NodeFinder; -import org.eclipse.wst.jsdt.internal.corext.refactoring.util.RefactoringASTParser; -import org.eclipse.wst.jsdt.internal.corext.template.java.CodeTemplateContextType; -import org.eclipse.wst.jsdt.internal.corext.util.JavaModelUtil; -import org.eclipse.wst.jsdt.internal.corext.util.Messages; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.actions.WorkbenchRunnableAdapter; -import org.eclipse.wst.jsdt.internal.ui.dialogs.SourceActionDialog; -import org.eclipse.wst.jsdt.internal.ui.dialogs.StatusInfo; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.CompilationUnitEditor; -import org.eclipse.wst.jsdt.internal.ui.preferences.JavaPreferencesSettings; -import org.eclipse.wst.jsdt.internal.ui.refactoring.IVisibilityChangeListener; -import org.eclipse.wst.jsdt.internal.ui.util.BusyIndicatorRunnableContext; -import org.eclipse.wst.jsdt.internal.ui.util.ElementValidator; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; -import org.eclipse.wst.jsdt.internal.ui.viewsupport.BindingLabelProvider; -import org.eclipse.wst.jsdt.ui.JavaScriptElementComparator; -import org.eclipse.wst.jsdt.ui.JavaScriptUI; - -/** - * Creates unimplemented constructors for a type. - * <p> - * Will open the parent compilation unit in a JavaScript editor. Opens a dialog with a list of - * constructors from the super class which can be generated. User is able to check or - * uncheck items before constructors are generated. The result is unsaved, so the user can - * decide if the changes are acceptable. - * <p> - * The action is applicable to structured selections containing elements of type - * <code>IType</code>. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class AddUnimplementedConstructorsAction extends SelectionDispatchAction { - - private static class AddUnimplementedConstructorsContentProvider implements ITreeContentProvider { - - private static final Object[] EMPTY= new Object[0]; - - private IFunctionBinding[] fMethodsList= new IFunctionBinding[0]; - - private final JavaScriptUnit fUnit; - - public AddUnimplementedConstructorsContentProvider(IType type) throws JavaScriptModelException { - RefactoringASTParser parser= new RefactoringASTParser(AST.JLS3); - fUnit= parser.parse(type.getJavaScriptUnit(), true); - AbstractTypeDeclaration declaration= (AbstractTypeDeclaration) ASTNodes.getParent(NodeFinder.perform(fUnit, type.getNameRange()), AbstractTypeDeclaration.class); - if (declaration != null) { - ITypeBinding binding= declaration.resolveBinding(); - if (binding != null) - fMethodsList= StubUtility2.getVisibleConstructors(binding, true, false); - } - } - - public JavaScriptUnit getCompilationUnit() { - return fUnit; - } - - /* - * @see IContentProvider#dispose() - */ - public void dispose() { - } - - /* - * @see ITreeContentProvider#getChildren(Object) - */ - public Object[] getChildren(Object parentElement) { - return EMPTY; - } - - /* - * @see IStructuredContentProvider#getElements(Object) - */ - public Object[] getElements(Object inputElement) { - return fMethodsList; - } - - /* - * @see ITreeContentProvider#getParent(Object) - */ - public Object getParent(Object element) { - return null; - } - - /* - * @see ITreeContentProvider#hasChildren(Object) - */ - public boolean hasChildren(Object element) { - return getChildren(element).length > 0; - } - - /* - * @see IContentProvider#inputChanged(Viewer, Object, Object) - */ - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - - } - - private static class AddUnimplementedConstructorsDialog extends SourceActionDialog { - - private IDialogSettings fAddConstructorsSettings; - - private int fHeight= 18; - - private boolean fOmitSuper; - - private int fWidth= 60; - - private final String OMIT_SUPER= "OmitCallToSuper"; //$NON-NLS-1$ - - private final String SETTINGS_SECTION= "AddUnimplementedConstructorsDialog"; //$NON-NLS-1$ - - public AddUnimplementedConstructorsDialog(Shell parent, ILabelProvider labelProvider, ITreeContentProvider contentProvider, CompilationUnitEditor editor, IType type) throws JavaScriptModelException { - super(parent, labelProvider, contentProvider, editor, type, true); - - IDialogSettings dialogSettings= JavaScriptPlugin.getDefault().getDialogSettings(); - fAddConstructorsSettings= dialogSettings.getSection(SETTINGS_SECTION); - if (fAddConstructorsSettings == null) { - fAddConstructorsSettings= dialogSettings.addNewSection(SETTINGS_SECTION); - fAddConstructorsSettings.put(OMIT_SUPER, false); - } - - fOmitSuper= fAddConstructorsSettings.getBoolean(OMIT_SUPER); - } - - protected void configureShell(Shell shell) { - super.configureShell(shell); - PlatformUI.getWorkbench().getHelpSystem().setHelp(shell, IJavaHelpContextIds.ADD_UNIMPLEMENTED_CONSTRUCTORS_DIALOG); - } - - protected Control createDialogArea(Composite parent) { - initializeDialogUnits(parent); - - Composite composite= new Composite(parent, SWT.NONE); - GridLayout layout= new GridLayout(); - GridData gd= null; - - layout.marginHeight= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); - layout.marginWidth= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); - layout.verticalSpacing= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); - layout.horizontalSpacing= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); - composite.setLayout(layout); - - Label messageLabel= createMessageArea(composite); - if (messageLabel != null) { - gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL); - gd.horizontalSpan= 2; - messageLabel.setLayoutData(gd); - } - - Composite inner= new Composite(composite, SWT.NONE); - GridLayout innerLayout= new GridLayout(); - innerLayout.numColumns= 2; - innerLayout.marginHeight= 0; - innerLayout.marginWidth= 0; - inner.setLayout(innerLayout); - inner.setFont(parent.getFont()); - - CheckboxTreeViewer treeViewer= createTreeViewer(inner); - gd= new GridData(GridData.FILL_BOTH); - gd.widthHint= convertWidthInCharsToPixels(fWidth); - gd.heightHint= convertHeightInCharsToPixels(fHeight); - treeViewer.getControl().setLayoutData(gd); - - Composite buttonComposite= createSelectionButtons(inner); - gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL); - buttonComposite.setLayoutData(gd); - - gd= new GridData(GridData.FILL_BOTH); - inner.setLayoutData(gd); - - Composite entryComposite= createInsertPositionCombo(composite); - entryComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - Composite commentComposite= createCommentSelection(composite); - commentComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - Composite overrideSuperComposite= createOmitSuper(composite); - overrideSuperComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - Control linkControl= createLinkControl(composite); - if (linkControl != null) - linkControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - gd= new GridData(GridData.FILL_BOTH); - composite.setLayoutData(gd); - - applyDialogFont(composite); - - return composite; - } - - protected Composite createInsertPositionCombo(Composite composite) { - Composite entryComposite= super.createInsertPositionCombo(composite); - addVisibilityAndModifiersChoices(entryComposite); - - return entryComposite; - } - - /* - * @see org.eclipse.wst.jsdt.internal.ui.dialogs.SourceActionDialog#createLinkControl(org.eclipse.swt.widgets.Composite) - */ - protected Control createLinkControl(Composite composite) { - Link link= new Link(composite, SWT.WRAP); - link.setText(ActionMessages.AddUnimplementedConstructorsAction_template_link_message); - link.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - openCodeTempatePage(CodeTemplateContextType.CONSTRUCTORCOMMENT_ID); - } - }); - link.setToolTipText(ActionMessages.AddUnimplementedConstructorsAction_template_link_tooltip); - - GridData gridData= new GridData(SWT.FILL, SWT.BEGINNING, true, false); - gridData.widthHint= convertWidthInCharsToPixels(40); // only expand further if anyone else requires it - link.setLayoutData(gridData); - return link; - } - - private Composite createOmitSuper(Composite composite) { - Composite omitSuperComposite= new Composite(composite, SWT.NONE); - GridLayout layout= new GridLayout(); - layout.marginHeight= 0; - layout.marginWidth= 0; - omitSuperComposite.setLayout(layout); - omitSuperComposite.setFont(composite.getFont()); - - Button omitSuperButton= new Button(omitSuperComposite, SWT.CHECK); - omitSuperButton.setText(ActionMessages.AddUnimplementedConstructorsDialog_omit_super); - omitSuperButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); - - omitSuperButton.addSelectionListener(new SelectionListener() { - - public void widgetDefaultSelected(SelectionEvent e) { - widgetSelected(e); - } - - public void widgetSelected(SelectionEvent e) { - boolean isSelected= (((Button) e.widget).getSelection()); - setOmitSuper(isSelected); - } - }); - omitSuperButton.setSelection(isOmitSuper()); - GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL); - gd.horizontalSpan= 2; - omitSuperButton.setLayoutData(gd); - - return omitSuperComposite; - } - - protected Composite createVisibilityControlAndModifiers(Composite parent, final IVisibilityChangeListener visibilityChangeListener, int[] availableVisibilities, int correctVisibility) { - Composite visibilityComposite= createVisibilityControl(parent, visibilityChangeListener, availableVisibilities, correctVisibility); - return visibilityComposite; - } - - public boolean isOmitSuper() { - return fOmitSuper; - } - - public void setOmitSuper(boolean omitSuper) { - if (fOmitSuper != omitSuper) { - fOmitSuper= omitSuper; - fAddConstructorsSettings.put(OMIT_SUPER, omitSuper); - } - } - } - - private static class AddUnimplementedConstructorsValidator implements ISelectionStatusValidator { - - private static int fEntries; - - AddUnimplementedConstructorsValidator(int entries) { - super(); - fEntries= entries; - } - - private int countSelectedMethods(Object[] selection) { - int count= 0; - for (int i= 0; i < selection.length; i++) { - if (selection[i] instanceof IFunctionBinding) - count++; - } - return count; - } - - public IStatus validate(Object[] selection) { - int count= countSelectedMethods(selection); - if (count == 0) - return new StatusInfo(IStatus.ERROR, ""); //$NON-NLS-1$ - String message= Messages.format(ActionMessages.AddUnimplementedConstructorsAction_methods_selected, new Object[] { String.valueOf(count), String.valueOf(fEntries)}); - return new StatusInfo(IStatus.INFO, message); - } - } - - private static final String DIALOG_TITLE= ActionMessages.AddUnimplementedConstructorsAction_error_title; - - private CompilationUnitEditor fEditor; - - /** - * Note: This constructor is for internal use only. Clients should not call this - * constructor. - * - * @param editor the compilation unit editor - */ - public AddUnimplementedConstructorsAction(CompilationUnitEditor editor) { - this(editor.getEditorSite()); - fEditor= editor; - setEnabled(checkEnabledEditor()); - } - - /** - * Creates a new <code>AddUnimplementedConstructorsAction</code>. The action - * requires that the selection provided by the site's selection provider is of type - * <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public AddUnimplementedConstructorsAction(IWorkbenchSite site) { - super(site); - setText(ActionMessages.AddUnimplementedConstructorsAction_label); - setDescription(ActionMessages.AddUnimplementedConstructorsAction_description); - setToolTipText(ActionMessages.AddUnimplementedConstructorsAction_tooltip); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.ADD_UNIMPLEMENTED_CONSTRUCTORS_ACTION); - } - - private boolean canEnable(IStructuredSelection selection) throws JavaScriptModelException { - if ((selection.size() == 1) && (selection.getFirstElement() instanceof IType)) { - IType type= (IType) selection.getFirstElement(); - return type.getJavaScriptUnit() != null; - } - - if ((selection.size() == 1) && (selection.getFirstElement() instanceof IJavaScriptUnit)) - return true; - - return false; - } - - private boolean checkEnabledEditor() { - return fEditor != null && SelectionConverter.canOperateOn(fEditor); - } - - private String getDialogTitle() { - return DIALOG_TITLE; - } - - private IType getSelectedType(IStructuredSelection selection) throws JavaScriptModelException { - Object[] elements= selection.toArray(); - if (elements.length == 1 && (elements[0] instanceof IType)) { - IType type= (IType) elements[0]; - if (type.getJavaScriptUnit() != null) { - return type; - } - } else if (elements[0] instanceof IJavaScriptUnit) { - IJavaScriptUnit cu= (IJavaScriptUnit) elements[0]; - IType type= cu.findPrimaryType(); - if (type != null) - return type; - } - return null; - } - - /* - * (non-Javadoc) Method declared on SelectionDispatchAction - */ - public void run(IStructuredSelection selection) { - Shell shell= getShell(); - try { - IType type= getSelectedType(selection); - if (type == null) { - MessageDialog.openInformation(getShell(), getDialogTitle(), ActionMessages.AddUnimplementedConstructorsAction_not_applicable); - return; - } - run(shell, type, false); - } catch (CoreException e) { - ExceptionHandler.handle(e, shell, getDialogTitle(), null); - } - } - - /* - * (non-Javadoc) Method declared on SelectionDispatchAction - */ - public void run(ITextSelection selection) { - if (!ActionUtil.isProcessable(fEditor)) - return; - try { - Shell shell= getShell(); - IType type= SelectionConverter.getTypeAtOffset(fEditor); - if (type != null) - run(shell, type, true); - else - MessageDialog.openInformation(shell, getDialogTitle(), ActionMessages.AddUnimplementedConstructorsAction_not_applicable); - } catch (JavaScriptModelException e) { - ExceptionHandler.handle(e, getShell(), getDialogTitle(), null); - } catch (CoreException e) { - ExceptionHandler.handle(e, getShell(), getDialogTitle(), null); - } - } - - // ---- Helpers ------------------------------------------------------------------- - - private void run(Shell shell, IType type, boolean activatedFromEditor) throws CoreException { - if (!ElementValidator.check(type, getShell(), getDialogTitle(), activatedFromEditor)) { - notifyResult(false); - return; - } - if (!ActionUtil.isEditable(fEditor, getShell(), type)) { - notifyResult(false); - return; - } - - AddUnimplementedConstructorsContentProvider provider= new AddUnimplementedConstructorsContentProvider(type); - Object[] constructors= provider.getElements(null); - if (constructors.length == 0) { - MessageDialog.openInformation(getShell(), getDialogTitle(), ActionMessages.AddUnimplementedConstructorsAction_error_nothing_found); - notifyResult(false); - return; - } - - AddUnimplementedConstructorsDialog dialog= new AddUnimplementedConstructorsDialog(shell, new BindingLabelProvider(), provider, fEditor, type); - dialog.setCommentString(ActionMessages.SourceActionDialog_createConstructorComment); - dialog.setTitle(ActionMessages.AddUnimplementedConstructorsAction_dialog_title); - dialog.setInitialSelections(constructors); - dialog.setContainerMode(true); - dialog.setComparator(new JavaScriptElementComparator()); - dialog.setSize(60, 18); - dialog.setInput(new Object()); - dialog.setMessage(ActionMessages.AddUnimplementedConstructorsAction_dialog_label); - dialog.setValidator(new AddUnimplementedConstructorsValidator(constructors.length)); - - final int dialogResult= dialog.open(); - if (dialogResult == Window.OK) { - Object[] elements= dialog.getResult(); - if (elements == null) { - notifyResult(false); - return; - } - - ArrayList result= new ArrayList(); - for (int i= 0; i < elements.length; i++) { - Object elem= elements[i]; - if (elem instanceof IFunctionBinding) { - result.add(elem); - } - } - IFunctionBinding[] selected= (IFunctionBinding[]) result.toArray(new IFunctionBinding[result.size()]); - - CodeGenerationSettings settings= JavaPreferencesSettings.getCodeGenerationSettings(type.getJavaScriptProject()); - settings.createComments= dialog.getGenerateComment(); - IEditorPart editor= JavaScriptUI.openInEditor(type, true, false); - IRewriteTarget target= editor != null ? (IRewriteTarget) editor.getAdapter(IRewriteTarget.class) : null; - if (target != null) - target.beginCompoundChange(); - try { - JavaScriptUnit astRoot= provider.getCompilationUnit(); - final ITypeBinding typeBinding= ASTNodes.getTypeBinding(astRoot, type); - int insertPos= dialog.getInsertOffset(); - - AddUnimplementedConstructorsOperation operation= (AddUnimplementedConstructorsOperation) createRunnable(astRoot, typeBinding, selected, insertPos, dialog.getGenerateComment(), dialog.getVisibilityModifier(), dialog.isOmitSuper()); - IRunnableContext context= JavaScriptPlugin.getActiveWorkbenchWindow(); - if (context == null) - context= new BusyIndicatorRunnableContext(); - PlatformUI.getWorkbench().getProgressService().runInUI(context, new WorkbenchRunnableAdapter(operation, operation.getSchedulingRule()), operation.getSchedulingRule()); - String[] created= operation.getCreatedConstructors(); - if (created == null || created.length == 0) - MessageDialog.openInformation(shell, getDialogTitle(), ActionMessages.AddUnimplementedConstructorsAction_error_nothing_found); - } catch (InvocationTargetException e) { - ExceptionHandler.handle(e, shell, getDialogTitle(), null); - } catch (InterruptedException e) { - // Do nothing. Operation has been canceled by user. - } finally { - if (target != null) { - target.endCompoundChange(); - } - } - } - notifyResult(dialogResult == Window.OK); - } - - /** - * Returns a runnable that creates the constructor stubs. - * - * @param astRoot the AST of the compilation unit to work on. The AST must have been created from a {@link IJavaScriptUnit}, that - * means {@link org.eclipse.wst.jsdt.core.dom.ASTParser#setSource(IJavaScriptUnit)} was used. - * @param type the binding of the type to add the new methods to. The type binding must correspond to a type declaration in the AST. - * @param constructorsToOverride the bindings of constructors to override or <code>null</code> to implement all visible constructors from the super class. - * @param insertPos a hint for a location in the source where to insert the new methods or <code>-1</code> to use the default behavior. - * @param createComments if set, comments will be added to the new methods. - * @param visibility the visibility for the new modifiers. (see {@link org.eclipse.wst.jsdt.core.Flags}) for visibility constants. - * @param omitSuper if set, no <code>super()</code> call without arguments will be created. - * @return returns a runnable that creates the constructor stubs. - * @throws IllegalArgumentException a {@link IllegalArgumentException} is thrown if the AST passed has not been created from a {@link IJavaScriptUnit}. - * - * - */ - public static IWorkspaceRunnable createRunnable(JavaScriptUnit astRoot, ITypeBinding type, IFunctionBinding[] constructorsToOverride, int insertPos, boolean createComments, int visibility, boolean omitSuper) { - AddUnimplementedConstructorsOperation operation= new AddUnimplementedConstructorsOperation(astRoot, type, constructorsToOverride, insertPos, true, true, false); - operation.setCreateComments(createComments); - operation.setOmitSuper(omitSuper); - operation.setVisibility(visibility); - return operation; - } - - // ---- Structured Viewer ----------------------------------------------------------- - - /* - * (non-Javadoc) Method declared on SelectionDispatchAction - */ - public void selectionChanged(IStructuredSelection selection) { - try { - setEnabled(canEnable(selection)); - } catch (JavaScriptModelException e) { - // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253 - if (JavaModelUtil.isExceptionToBeLogged(e)) - JavaScriptPlugin.log(e); - setEnabled(false); - } - } - - // ---- JavaScript Editor -------------------------------------------------------------- - - /* - * (non-Javadoc) Method declared on SelectionDispatchAction - */ - public void selectionChanged(ITextSelection selection) { - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/BuildActionGroup.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/BuildActionGroup.java deleted file mode 100644 index c521f669..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/BuildActionGroup.java +++ /dev/null @@ -1,133 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.core.resources.IncrementalProjectBuilder; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.actions.ActionFactory; -import org.eclipse.ui.actions.ActionGroup; -import org.eclipse.ui.actions.BuildAction; -import org.eclipse.ui.ide.IDEActionFactory; -import org.eclipse.wst.jsdt.core.IJavaScriptProject; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages; -import org.eclipse.wst.jsdt.ui.IContextMenuConstants; - -/** - * Contributes all build related actions to the context menu and installs handlers for the - * corresponding global menu actions. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class BuildActionGroup extends ActionGroup { - - private IWorkbenchSite fSite; - - private BuildAction fBuildAction; - private RefreshAction fRefreshAction; - - /** - * Creates a new <code>BuildActionGroup</code>. The group requires that - * the selection provided by the view part's selection provider is of type - * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param part the view part that owns this action group - */ - public BuildActionGroup(IViewPart part) { - fSite= part.getSite(); - Shell shell= fSite.getShell(); - ISelectionProvider provider= fSite.getSelectionProvider(); - - fBuildAction= new BuildAction(shell, IncrementalProjectBuilder.INCREMENTAL_BUILD); - fBuildAction.setText(ActionMessages.BuildAction_label); - fBuildAction.setActionDefinitionId("org.eclipse.ui.project.buildProject"); //$NON-NLS-1$ - - fRefreshAction= new RefreshAction(fSite); - fRefreshAction.setActionDefinitionId("org.eclipse.ui.file.refresh"); //$NON-NLS-1$ - - provider.addSelectionChangedListener(fBuildAction); - provider.addSelectionChangedListener(fRefreshAction); - } - - /** - * Returns the refresh action managed by this group. - * - * @return the refresh action. If this group doesn't manage a refresh action - * <code>null</code> is returned - */ - public IAction getRefreshAction() { - return fRefreshAction; - } - - /* (non-Javadoc) - * Method declared in ActionGroup - */ - public void fillActionBars(IActionBars actionBar) { - super.fillActionBars(actionBar); - setGlobalActionHandlers(actionBar); - } - - /* (non-Javadoc) - * Method declared in ActionGroup - */ - public void fillContextMenu(IMenuManager menu) { - ISelection selection= getContext().getSelection(); - if (!ResourcesPlugin.getWorkspace().isAutoBuilding() && isBuildTarget(selection)) { - appendToGroup(menu, fBuildAction); - } - appendToGroup(menu, fRefreshAction); - super.fillContextMenu(menu); - } - - /* (non-Javadoc) - * Method declared in ActionGroup - */ - public void dispose() { - ISelectionProvider provider= fSite.getSelectionProvider(); - provider.removeSelectionChangedListener(fBuildAction); - provider.removeSelectionChangedListener(fRefreshAction); - super.dispose(); - } - - private void setGlobalActionHandlers(IActionBars actionBar) { - actionBar.setGlobalActionHandler(IDEActionFactory.BUILD_PROJECT.getId(), fBuildAction); - actionBar.setGlobalActionHandler(ActionFactory.REFRESH.getId(), fRefreshAction); - } - - private void appendToGroup(IMenuManager menu, IAction action) { - if (action.isEnabled()) - menu.appendToGroup(IContextMenuConstants.GROUP_BUILD, action); - } - - private boolean isBuildTarget(ISelection s) { - if (!(s instanceof IStructuredSelection)) - return false; - IStructuredSelection selection= (IStructuredSelection)s; - if (selection.size() != 1) - return false; - return selection.getFirstElement() instanceof IJavaScriptProject; - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/CCPActionGroup.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/CCPActionGroup.java deleted file mode 100644 index 6e084a95..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/CCPActionGroup.java +++ /dev/null @@ -1,176 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.swt.dnd.Clipboard; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.actions.ActionFactory; -import org.eclipse.ui.actions.ActionGroup; -import org.eclipse.ui.navigator.ICommonMenuConstants; -import org.eclipse.ui.part.Page; -import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds; -import org.eclipse.wst.jsdt.internal.ui.actions.CopyQualifiedNameAction; -import org.eclipse.wst.jsdt.internal.ui.refactoring.reorg.CopyToClipboardAction; -import org.eclipse.wst.jsdt.internal.ui.refactoring.reorg.CutAction; -import org.eclipse.wst.jsdt.internal.ui.refactoring.reorg.DeleteAction; -import org.eclipse.wst.jsdt.internal.ui.refactoring.reorg.PasteAction; - -/** - * Action group that adds the copy, cut, paste actions to a view part's context - * menu and installs handlers for the corresponding global menu actions. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class CCPActionGroup extends ActionGroup { - - private IWorkbenchSite fSite; - private Clipboard fClipboard; - - private SelectionDispatchAction[] fActions; - - private SelectionDispatchAction fDeleteAction; - private SelectionDispatchAction fCopyAction; - private SelectionDispatchAction fCopyQualifiedNameAction; - private SelectionDispatchAction fPasteAction; - private SelectionDispatchAction fCutAction; - - private boolean showLimited; - - /** - * Creates a new <code>CCPActionGroup</code>. The group requires that - * the selection provided by the view part's selection provider is of type - * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param part the view part that owns this action group - */ - public CCPActionGroup(IViewPart part) { - this(part.getSite()); - } - - /** - * Creates a new <code>CCPActionGroup</code>. The group requires that - * the selection provided by the page's selection provider is of type - * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param page the page that owns this action group - */ - public CCPActionGroup(Page page) { - this(page.getSite()); - } - - private CCPActionGroup(IWorkbenchSite site) { - fSite= site; - fClipboard= new Clipboard(site.getShell().getDisplay()); - - fPasteAction= new PasteAction(fSite, fClipboard); - fPasteAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.PASTE); - - fCopyAction= new CopyToClipboardAction(fSite, fClipboard); - fCopyAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.COPY); - - fCopyQualifiedNameAction= new CopyQualifiedNameAction(fSite); - fCopyQualifiedNameAction.setActionDefinitionId(CopyQualifiedNameAction.ACTION_DEFINITION_ID); - - fCutAction= new CutAction(fSite, fClipboard); - fCutAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.CUT); - - fDeleteAction= new DeleteAction(fSite); - fDeleteAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.DELETE); - - fActions= new SelectionDispatchAction[] { fCutAction, fCopyAction, fCopyQualifiedNameAction, fPasteAction, fDeleteAction }; - registerActionsAsSelectionChangeListeners(); - } - - private void registerActionsAsSelectionChangeListeners() { - ISelectionProvider provider = fSite.getSelectionProvider(); - ISelection selection= provider.getSelection(); - for (int i= 0; i < fActions.length; i++) { - SelectionDispatchAction action= fActions[i]; - action.update(selection); - provider.addSelectionChangedListener(action); - } - } - - private void deregisterActionsAsSelectionChangeListeners() { - ISelectionProvider provider = fSite.getSelectionProvider(); - for (int i= 0; i < fActions.length; i++) { - provider.removeSelectionChangedListener(fActions[i]); - } - } - - - /** - * Returns the delete action managed by this action group. - * - * @return the delete action. Returns <code>null</code> if the group - * doesn't provide any delete action - */ - public IAction getDeleteAction() { - return fDeleteAction; - } - - /* (non-Javadoc) - * Method declared in ActionGroup - */ - public void fillActionBars(IActionBars actionBars) { - super.fillActionBars(actionBars); - actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), fDeleteAction); - actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), fCopyAction); - actionBars.setGlobalActionHandler(CopyQualifiedNameAction.ACTION_HANDLER_ID, fCopyQualifiedNameAction); - actionBars.setGlobalActionHandler(ActionFactory.CUT.getId(), fCutAction); - actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), fPasteAction); - } - - /* (non-Javadoc) - * Method declared in ActionGroup - */ - public void fillContextMenu(IMenuManager menu) { - super.fillContextMenu(menu); - for (int i= 0; i < fActions.length; i++) { - SelectionDispatchAction action= fActions[i]; - if (action == fCutAction && !fCutAction.isEnabled()) - continue; - if (this.showLimited/* -- in case you want paste action to always show up-- && action!=fPasteAction */) - continue; - menu.appendToGroup(ICommonMenuConstants.GROUP_EDIT, action); - } - } - - /* - * @see ActionGroup#dispose() - */ - public void dispose() { - super.dispose(); - if (fClipboard != null){ - fClipboard.dispose(); - fClipboard= null; - } - deregisterActionsAsSelectionChangeListeners(); - } - public void setShowLimited(boolean showLimited) { - this.showLimited = showLimited; - } - - -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ChangeTypeAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ChangeTypeAction.java deleted file mode 100644 index 5ad46653..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ChangeTypeAction.java +++ /dev/null @@ -1,157 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IField; -import org.eclipse.wst.jsdt.core.IFunction; -import org.eclipse.wst.jsdt.core.IMember; -import org.eclipse.wst.jsdt.core.ISourceRange; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.core.Signature; -import org.eclipse.wst.jsdt.core.dom.PrimitiveType; -import org.eclipse.wst.jsdt.internal.corext.refactoring.RefactoringAvailabilityTester; -import org.eclipse.wst.jsdt.internal.corext.refactoring.RefactoringExecutionStarter; -import org.eclipse.wst.jsdt.internal.corext.util.JavaModelUtil; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaTextSelection; -import org.eclipse.wst.jsdt.internal.ui.refactoring.RefactoringMessages; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; - -/** - * Action to generalize the type of a local or field declaration or the - * return type of a method declaration. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class ChangeTypeAction extends SelectionDispatchAction { - - private JavaEditor fEditor; - - /** - * Note: This constructor is for internal use only. Clients should not call - * this constructor. - * @param editor the JavaScript editor - */ - public ChangeTypeAction(JavaEditor editor) { - this(editor.getEditorSite()); - fEditor= editor; - setEnabled(SelectionConverter.getInputAsCompilationUnit(fEditor) != null); - } - - /** - * Creates a new <code>ChangeTypeAction</code>. The action requires that - * the selection provided by the site's selection provider is of type - * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public ChangeTypeAction(IWorkbenchSite site) { - super(site); - setText(RefactoringMessages.ChangeTypeAction_label); - setToolTipText(RefactoringMessages.ChangeTypeAction_tooltipText); - setDescription(RefactoringMessages.ChangeTypeAction_description); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.CHANGE_TYPE_ACTION); - } - - //---- structured selection --------------------------------------------- - - public void selectionChanged(IStructuredSelection selection) { - try { - setEnabled(RefactoringAvailabilityTester.isGeneralizeTypeAvailable(selection)); - } catch (JavaScriptModelException e) { - if (JavaModelUtil.isExceptionToBeLogged(e)) - JavaScriptPlugin.log(e); - setEnabled(false); - } - } - - public void run(IStructuredSelection selection) { - try { - IMember member= getMember(selection); - if (member == null || !ActionUtil.isEditable(getShell(), member)) - return; - ISourceRange range= member.getNameRange(); - RefactoringExecutionStarter.startChangeTypeRefactoring(member.getJavaScriptUnit(), getShell(), range.getOffset(), range.getLength()); - } catch (CoreException e) { - ExceptionHandler.handle(e, RefactoringMessages.ChangeTypeAction_dialog_title, RefactoringMessages.ChangeTypeAction_exception); - } - } - - private static IMember getMember(IStructuredSelection selection) throws JavaScriptModelException { - if (selection.size() != 1) - return null; - - Object element= selection.getFirstElement(); - if (!(element instanceof IMember)) - return null; - - if (element instanceof IFunction) { - IFunction method= (IFunction)element; - String returnType= method.getReturnType(); - if (PrimitiveType.toCode(Signature.toString(returnType)) != null) - return null; - return method; - } else if (element instanceof IField) { - return (IField)element; - } - return null; - } - - //---- text selection ------------------------------------------------------------ - - /* - * (non-Javadoc) Method declared on SelectionDispatchAction - */ - public void selectionChanged(ITextSelection selection) { - setEnabled(true); - } - - /** - * Note: This method is for internal use only. Clients should not call this method. - * @param selection the JavaScript text selection - */ - public void selectionChanged(JavaTextSelection selection) { - try { - setEnabled(RefactoringAvailabilityTester.isGeneralizeTypeAvailable(selection)); - } catch (JavaScriptModelException e) { - setEnabled(false); - } - } - - /* - * (non-Javadoc) Method declared on SelectionDispatchAction - */ - public void run(ITextSelection selection) { - if (!ActionUtil.isEditable(fEditor)) - return; - try { - RefactoringExecutionStarter.startChangeTypeRefactoring(SelectionConverter.getInputAsCompilationUnit(fEditor), getShell(), selection.getOffset(), selection.getLength()); - } catch (CoreException e) { - ExceptionHandler.handle(e, RefactoringMessages.ChangeTypeAction_dialog_title, RefactoringMessages.ChangeTypeAction_exception); - } - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ConvertAnonymousToNestedAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ConvertAnonymousToNestedAction.java deleted file mode 100644 index 2539c750..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ConvertAnonymousToNestedAction.java +++ /dev/null @@ -1,161 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - - -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IJavaScriptUnit; -import org.eclipse.wst.jsdt.core.ISourceRange; -import org.eclipse.wst.jsdt.core.IType; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.internal.corext.refactoring.RefactoringAvailabilityTester; -import org.eclipse.wst.jsdt.internal.corext.refactoring.RefactoringExecutionStarter; -import org.eclipse.wst.jsdt.internal.corext.util.JavaModelUtil; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaTextSelection; -import org.eclipse.wst.jsdt.internal.ui.refactoring.RefactoringMessages; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; - -/** - * Action to convert an anonymous inner class to a nested class. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class ConvertAnonymousToNestedAction extends SelectionDispatchAction { - - private final JavaEditor fEditor; - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public ConvertAnonymousToNestedAction(JavaEditor editor) { - super(editor.getEditorSite()); - setText(RefactoringMessages.ConvertAnonymousToNestedAction_Convert_Anonymous); - fEditor= editor; - setEnabled(SelectionConverter.getInputAsCompilationUnit(fEditor) != null); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.CONVERT_ANONYMOUS_TO_NESTED_ACTION); - } - - /** - * Creates a new <code>ConvertAnonymousToNestedAction</code>. The action requires - * that the selection provided by the site's selection provider is of type - * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public ConvertAnonymousToNestedAction(IWorkbenchSite site) { - super(site); - fEditor= null; - setText(RefactoringMessages.ConvertAnonymousToNestedAction_Convert_Anonymous); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.CONVERT_ANONYMOUS_TO_NESTED_ACTION); - } - - //---- Structured selection ----------------------------------------------------- - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction - */ - public void selectionChanged(IStructuredSelection selection) { - try { - setEnabled(RefactoringAvailabilityTester.isConvertAnonymousAvailable(selection)); - } catch (JavaScriptModelException e) { - if (JavaModelUtil.isExceptionToBeLogged(e)) - JavaScriptPlugin.log(e); - setEnabled(false); - } - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction - */ - public void run(IStructuredSelection selection) { - IType type= getElement(selection); - if (type == null) - return; - ISourceRange range; - try { - range= type.getNameRange(); - run(type.getJavaScriptUnit(), range.getOffset(), range.getLength()); - } catch (JavaScriptModelException e) { - ExceptionHandler.handle(e, RefactoringMessages.ConvertAnonymousToNestedAction_dialog_title, RefactoringMessages.NewTextRefactoringAction_exception); - } - } - - private IType getElement(IStructuredSelection selection) { - if (selection.size() != 1) - return null; - Object element= selection.getFirstElement(); - if (!(element instanceof IType)) - return null; - IType type= (IType)element; - try { - if (type.isAnonymous()) - return type; - } catch (JavaScriptModelException e) { - // fall through - } - return null; - } - - //---- Text selection ----------------------------------------------------------- - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction - */ - public void run(ITextSelection selection) { - try{ - run(SelectionConverter.getInputAsCompilationUnit(fEditor), selection.getOffset(), selection.getLength()); - } catch (JavaScriptModelException e){ - ExceptionHandler.handle(e, RefactoringMessages.ConvertAnonymousToNestedAction_dialog_title, RefactoringMessages.NewTextRefactoringAction_exception); - } - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction - */ - public void selectionChanged(ITextSelection selection) { - setEnabled(fEditor != null && SelectionConverter.getInputAsCompilationUnit(fEditor) != null); - } - - /** - * Note: This method is for internal use only. Clients should not call this method. - */ - public void selectionChanged(JavaTextSelection selection) { - try { - setEnabled(RefactoringAvailabilityTester.isConvertAnonymousAvailable(selection)); - } catch (JavaScriptModelException e) { - setEnabled(false); - } - } - - //---- helpers ------------------------------------------------------------------- - - private void run(IJavaScriptUnit unit, int offset, int length) throws JavaScriptModelException { - if (!ActionUtil.isEditable(fEditor, getShell(), unit)) - return; - RefactoringExecutionStarter.startConvertAnonymousRefactoring(unit, offset, length, getShell()); - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ConvertLocalToFieldAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ConvertLocalToFieldAction.java deleted file mode 100644 index 2b896cf2..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ConvertLocalToFieldAction.java +++ /dev/null @@ -1,91 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IJavaScriptUnit; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.internal.corext.refactoring.RefactoringAvailabilityTester; -import org.eclipse.wst.jsdt.internal.corext.refactoring.code.PromoteTempToFieldRefactoring; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaTextSelection; -import org.eclipse.wst.jsdt.internal.ui.refactoring.PromoteTempWizard; -import org.eclipse.wst.jsdt.internal.ui.refactoring.RefactoringMessages; -import org.eclipse.wst.jsdt.internal.ui.refactoring.RefactoringSaveHelper; -import org.eclipse.wst.jsdt.internal.ui.refactoring.actions.RefactoringStarter; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; - -/** - * Action to convert a local variable to a field. - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class ConvertLocalToFieldAction extends SelectionDispatchAction { - - private final JavaEditor fEditor; - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * - * @param editor the JavaScript editor - */ - public ConvertLocalToFieldAction(JavaEditor editor) { - super(editor.getEditorSite()); - setText(RefactoringMessages.ConvertLocalToField_label); - fEditor= editor; - setEnabled(SelectionConverter.getInputAsCompilationUnit(fEditor) != null); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.PROMOTE_TEMP_TO_FIELD_ACTION); - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction - */ - public void selectionChanged(ITextSelection selection) { - setEnabled(fEditor != null && SelectionConverter.getInputAsCompilationUnit(fEditor) != null); - } - - /** - * Note: This method is for internal use only. Clients should not call this method. - */ - public void selectionChanged(JavaTextSelection selection) { - try { - setEnabled(RefactoringAvailabilityTester.isPromoteTempAvailable(selection)); - } catch (JavaScriptModelException e) { - setEnabled(false); - } - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction - */ - public void run(ITextSelection selection) { - if (!ActionUtil.isEditable(fEditor)) - return; - try{ - IJavaScriptUnit cunit= SelectionConverter.getInputAsCompilationUnit(fEditor); - final PromoteTempToFieldRefactoring refactoring= new PromoteTempToFieldRefactoring(cunit, selection.getOffset(), selection.getLength()); - new RefactoringStarter().activate(refactoring, new PromoteTempWizard(refactoring), getShell(), RefactoringMessages.ConvertLocalToField_title, RefactoringSaveHelper.SAVE_NOTHING); - } catch (JavaScriptModelException e){ - ExceptionHandler.handle(e, RefactoringMessages.ConvertLocalToField_title, RefactoringMessages.NewTextRefactoringAction_exception); - } - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ConvertNestedToTopAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ConvertNestedToTopAction.java deleted file mode 100644 index 54f40f2d..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ConvertNestedToTopAction.java +++ /dev/null @@ -1,167 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - - -import java.io.CharConversionException; - -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IJavaScriptUnit; -import org.eclipse.wst.jsdt.core.IType; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.internal.corext.refactoring.RefactoringAvailabilityTester; -import org.eclipse.wst.jsdt.internal.corext.refactoring.RefactoringExecutionStarter; -import org.eclipse.wst.jsdt.internal.corext.refactoring.util.JavaElementUtil; -import org.eclipse.wst.jsdt.internal.corext.util.JavaModelUtil; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaTextSelection; -import org.eclipse.wst.jsdt.internal.ui.refactoring.RefactoringMessages; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; - -/** - * Action to convert a nested class to a top level class. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class ConvertNestedToTopAction extends SelectionDispatchAction { - - private JavaEditor fEditor; - - /** - * Note: This constructor is for internal use only. Clients should not call - * this constructor. - * @param editor the JavaScript editor - */ - public ConvertNestedToTopAction(JavaEditor editor) { - this(editor.getEditorSite()); - fEditor= editor; - setEnabled(SelectionConverter.canOperateOn(fEditor)); - } - - /** - * Creates a new <code>MoveInnerToTopAction</code>. The action requires - * that the selection provided by the site's selection provider is of type - * <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site - * the site providing context information for this action - */ - public ConvertNestedToTopAction(IWorkbenchSite site) { - super(site); - setText(RefactoringMessages.ConvertNestedToTopAction_Convert); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.MOVE_INNER_TO_TOP_ACTION); - } - - //---- Structured selection ------------------------------------------------ - - /* - * @see SelectionDispatchAction#selectionChanged(IStructuredSelection) - */ - public void selectionChanged(IStructuredSelection selection) { - try { - setEnabled(RefactoringAvailabilityTester.isMoveInnerAvailable(selection)); - } catch (JavaScriptModelException e) { - // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253 - if (!(e.getException() instanceof CharConversionException) && JavaModelUtil.isExceptionToBeLogged(e)) - JavaScriptPlugin.log(e); - setEnabled(false);//no UI - } - } - - /* - * @see SelectionDispatchAction#run(IStructuredSelection) - */ - 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 (JavaScriptModelException e) { - ExceptionHandler.handle(e, - RefactoringMessages.OpenRefactoringWizardAction_refactoring, - RefactoringMessages.OpenRefactoringWizardAction_exception); - } - } - - private static IType getSingleSelectedType(IStructuredSelection selection) throws JavaScriptModelException { - if (selection.isEmpty() || selection.size() != 1) - return null; - - Object first= selection.getFirstElement(); - if (first instanceof IType) - return (IType)first; - if (first instanceof IJavaScriptUnit) - return JavaElementUtil.getMainType((IJavaScriptUnit)first); - return null; - } - - //---- Text Selection ------------------------------------------------------- - - /* - * @see SelectionDispatchAction#selectionChanged(ITextSelection) - */ - public void selectionChanged(ITextSelection selection) { - setEnabled(true); - } - - /** - * Note: This method is for internal use only. Clients should not call this method. - */ - public void selectionChanged(JavaTextSelection selection) { - try { - setEnabled(RefactoringAvailabilityTester.isMoveInnerAvailable(selection)); - } catch (JavaScriptModelException e) { - setEnabled(false); - } - } - - /* - * @see SelectionDispatchAction#run(ITextSelection) - */ - public void run(ITextSelection selection) { - try { - IType type= RefactoringAvailabilityTester.getDeclaringType(SelectionConverter.resolveEnclosingElement(fEditor, selection)); - if (type != null && RefactoringAvailabilityTester.isMoveInnerAvailable(type)) { - if (! ActionUtil.isEditable(fEditor, getShell(), type)) - return; - RefactoringExecutionStarter.startMoveInnerRefactoring(type, getShell()); - } else { - MessageDialog.openInformation(getShell(), RefactoringMessages.OpenRefactoringWizardAction_unavailable, RefactoringMessages.ConvertNestedToTopAction_To_activate); - } - } catch (JavaScriptModelException e) { - ExceptionHandler.handle(e, - RefactoringMessages.OpenRefactoringWizardAction_refactoring, - RefactoringMessages.OpenRefactoringWizardAction_exception); - } - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ConvertingSelectionProvider.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ConvertingSelectionProvider.java deleted file mode 100644 index f7ba16a5..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ConvertingSelectionProvider.java +++ /dev/null @@ -1,177 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.ListenerList; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; - - - -/** - * A converting selection provider is a special selection provider which converts - * a selection before notifying any listeners. Additional it converts the selection - * on <code>getSelection</code> and <code>setSelection</code>. The default strategy - * used to adapt the elements of the selection to {@link IJavaScriptElement} or a {@link IResource}, - * but implementors can override this behavior. - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class ConvertingSelectionProvider implements ISelectionProvider { - - private final ISelectionProvider fProvider; - private SelectionChangedListener fListener; - - private class SelectionChangedListener implements ISelectionChangedListener { - - ListenerList fListeners= new ListenerList(); - - public void selectionChanged(SelectionChangedEvent event) { - ISelection selection= convertFrom(event.getSelection()); - SelectionChangedEvent newEvent= new SelectionChangedEvent(ConvertingSelectionProvider.this, selection); - Object[] listeners= fListeners.getListeners(); - for (int i= 0; i < listeners.length; i++) { - ((ISelectionChangedListener)listeners[i]).selectionChanged(newEvent); - } - } - public void addListener(ISelectionChangedListener listener) { - fListeners.add(listener); - } - public void removeListener(ISelectionChangedListener listener) { - fListeners.remove(listener); - } - public boolean isEmpty() { - return fListeners.isEmpty(); - } - } - - /** - * Creates a {@link ConvertingSelectionProvider} to convert from a given selection provider - * using the default mechanism. - * - * @param provider the provider to covert from and to - */ - public ConvertingSelectionProvider(ISelectionProvider provider) { - Assert.isNotNull(provider); - fProvider= provider; - } - - /** - * Converts the given original viewer selection into a new - * selection. The default behavior adapts the elements in the selection - * first to {@link IJavaScriptElement} then to {@link IResource}. - * Implementors want to override this method. - * - * @param viewerSelection the original viewer selection - * - * @return the new selection to be used - */ - public ISelection convertFrom(ISelection viewerSelection) { - return convertFromUsingDefaultMechanism(viewerSelection); - } - - - private ISelection convertFromUsingDefaultMechanism(ISelection viewerSelection) { - if (! (viewerSelection instanceof IStructuredSelection)) - return viewerSelection; - IStructuredSelection selection= (IStructuredSelection)viewerSelection; - List result= new ArrayList(selection.size()); - for (Iterator iter= selection.iterator(); iter.hasNext();) { - Object element= iter.next(); - if (element instanceof IResource || element instanceof IJavaScriptElement) { - result.add(element); - } else if (element instanceof IAdaptable) { - IAdaptable adaptable= (IAdaptable)element; - IJavaScriptElement jElement= (IJavaScriptElement)adaptable.getAdapter(IJavaScriptElement.class); - if (jElement != null) { - result.add(jElement); - } else { - IResource resource= (IResource)adaptable.getAdapter(IResource.class); - if (resource != null) { - result.add(resource); - } else { - result.add(element); - } - } - } else { - result.add(element); - } - } - return new StructuredSelection(result); - } - - /** - * Converts a selection to a viewer selection. The default implementation does not convert - * the selection. Implementors want to override this behavior. - * - * @param selection the selection to convert - * - * @return a viewer selection - */ - public ISelection convertTo(ISelection selection) { - return selection; - } - - - /** - * {@inheritDoc} - */ - public final ISelection getSelection() { - return convertFrom(fProvider.getSelection()); - } - - /** - * {@inheritDoc} - */ - public final void setSelection(ISelection selection) { - fProvider.setSelection(convertTo(selection)); - } - - /** - * {@inheritDoc} - */ - public void addSelectionChangedListener(ISelectionChangedListener listener) { - if (fListener == null) { - fListener= new SelectionChangedListener(); - fProvider.addSelectionChangedListener(fListener); - } - fListener.addListener(listener); - } - - /** - * {@inheritDoc} - */ - public void removeSelectionChangedListener(ISelectionChangedListener listener) { - if (fListener == null) - return; - fListener.removeListener(listener); - if (fListener.isEmpty()) { - fProvider.removeSelectionChangedListener(fListener); - fListener= null; - } - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/CustomFiltersActionGroup.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/CustomFiltersActionGroup.java deleted file mode 100644 index 6bfdc187..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/CustomFiltersActionGroup.java +++ /dev/null @@ -1,757 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.SortedSet; -import java.util.Stack; -import java.util.StringTokenizer; -import java.util.TreeSet; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.ContributionItem; -import org.eclipse.jface.action.GroupMarker; -import org.eclipse.jface.action.IContributionItem; -import org.eclipse.jface.action.IMenuListener; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.viewers.IContentProvider; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.StructuredViewer; -import org.eclipse.jface.viewers.ViewerFilter; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.MenuItem; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IMemento; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.actions.ActionGroup; -import org.eclipse.wst.jsdt.core.IJavaScriptModel; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.JavaPluginImages; -import org.eclipse.wst.jsdt.internal.ui.filters.CustomFiltersDialog; -import org.eclipse.wst.jsdt.internal.ui.filters.FilterDescriptor; -import org.eclipse.wst.jsdt.internal.ui.filters.FilterMessages; -import org.eclipse.wst.jsdt.internal.ui.filters.NamePatternFilter; - -/** - * Action group to add the filter action to a view part's tool bar - * menu. - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class CustomFiltersActionGroup extends ActionGroup { - - private static final String TAG_DUMMY_TO_TEST_EXISTENCE= "TAG_DUMMY_TO_TEST_EXISTENCE"; //$NON-NLS-1$ - - class ShowFilterDialogAction extends Action { - ShowFilterDialogAction() { - setText(FilterMessages.OpenCustomFiltersDialogAction_text); - setImageDescriptor(JavaPluginImages.DESC_ELCL_FILTER); - setDisabledImageDescriptor(JavaPluginImages.DESC_DLCL_FILTER); - } - - public void run() { - openDialog(); - } - } - - /** - * Menu contribution item which shows and lets check and uncheck filters. - * - * - */ - class FilterActionMenuContributionItem extends ContributionItem { - - private int fItemNumber; - private boolean fState; - private String fFilterId; - private String fFilterName; - private CustomFiltersActionGroup fActionGroup; - - /** - * Constructor for FilterActionMenuContributionItem. - * - * @param actionGroup the action group - * @param filterId the id of the filter - * @param filterName the name of the filter - * @param state the initial state of the filter - * @param itemNumber the menu item index - */ - public FilterActionMenuContributionItem(CustomFiltersActionGroup actionGroup, String filterId, String filterName, boolean state, int itemNumber) { - super(filterId); - Assert.isNotNull(actionGroup); - Assert.isNotNull(filterId); - Assert.isNotNull(filterName); - fActionGroup= actionGroup; - fFilterId= filterId; - fFilterName= filterName; - fState= state; - fItemNumber= itemNumber; - } - - /* - * Overrides method from ContributionItem. - */ - public void fill(Menu menu, int index) { - MenuItem mi= new MenuItem(menu, SWT.CHECK, index); - mi.setText("&" + fItemNumber + " " + fFilterName); //$NON-NLS-1$ //$NON-NLS-2$ - /* - * XXX: Don't set the image - would look bad because other menu items don't provide image - * XXX: Get working set specific image name from XML - would need to cache icons - */ -// mi.setImage(JavaPluginImages.get(JavaPluginImages.IMG_OBJS_JAVA_WORKING_SET)); - mi.setSelection(fState); - mi.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - fState= !fState; - fActionGroup.setFilter(fFilterId, fState); - } - }); - } - - /* - * @see org.eclipse.jface.action.IContributionItem#isDynamic() - */ - public boolean isDynamic() { - return true; - } - } - - private static final String TAG_CUSTOM_FILTERS = "customFilters"; //$NON-NLS-1$ - private static final String TAG_USER_DEFINED_PATTERNS_ENABLED= "userDefinedPatternsEnabled"; //$NON-NLS-1$ - private static final String TAG_USER_DEFINED_PATTERNS= "userDefinedPatterns"; //$NON-NLS-1$ - private static final String TAG_XML_DEFINED_FILTERS= "xmlDefinedFilters"; //$NON-NLS-1$ - private static final String TAG_LRU_FILTERS = "lastRecentlyUsedFilters"; //$NON-NLS-1$ - - private static final String TAG_CHILD= "child"; //$NON-NLS-1$ - private static final String TAG_PATTERN= "pattern"; //$NON-NLS-1$ - private static final String TAG_FILTER_ID= "filterId"; //$NON-NLS-1$ - private static final String TAG_IS_ENABLED= "isEnabled"; //$NON-NLS-1$ - - private static final String SEPARATOR= ","; //$NON-NLS-1$ - - private static final int MAX_FILTER_MENU_ENTRIES= 3; - private static final String RECENT_FILTERS_GROUP_NAME= "recentFiltersGroup"; //$NON-NLS-1$ - - private static class FilterItem { - boolean enabled; - boolean previouslyEnabled; - FilterDescriptor descriptor; - String id; - - private ViewerFilter filterInstance= null; - - public FilterItem(FilterDescriptor descriptor) { - this.descriptor= descriptor; - this.id= descriptor.getId(); - this.previouslyEnabled= false; - this.enabled= descriptor.isEnabled(); - } - - public ViewerFilter getFilterInstance() { - if (filterInstance == null) { - filterInstance= descriptor.createViewerFilter(); - } - return filterInstance; - - } - } - - - private final StructuredViewer fViewer; - private final NamePatternFilter fPatternFilter; - - private boolean fUserDefinedPatternsEnabled; - private String[] fUserDefinedPatterns; - - private String[] fPreviousPatterns; - - private final Map/*String, FilterItem*/ fFilterItems; - - /** - * Recently changed filter Ids stack with oldest on top (i.e. at the end). - * - * - */ - private Stack fLRUFilterIdsStack; - /** - * Handle to menu manager to dynamically update - * the last recently used filters. - * - * - */ - private IMenuManager fMenuManager; - /** - * The menu listener which dynamically updates - * the last recently used filters. - * - * - */ - private IMenuListener fMenuListener; - /** - * Filter Ids used in the last view menu invocation. - * - * - */ - private String[] fFilterIdsUsedInLastViewMenu; - - private final String fTargetId; - - /** - * Creates a new <code>CustomFiltersActionGroup</code>. - * - * @param part the view part that owns this action group - * @param viewer the viewer to be filtered - */ - public CustomFiltersActionGroup(IViewPart part, StructuredViewer viewer) { - this(part.getViewSite().getId(), viewer); - } - - /** - * Creates a new <code>CustomFiltersActionGroup</code>. - * - * @param ownerId the id of this action group's owner - * @param viewer the viewer to be filtered - */ - public CustomFiltersActionGroup(String ownerId, StructuredViewer viewer) { - Assert.isNotNull(ownerId); - Assert.isNotNull(viewer); - fTargetId= ownerId; - fViewer= viewer; - fPatternFilter= new NamePatternFilter(); - - fLRUFilterIdsStack= new Stack(); - - fUserDefinedPatterns= new String[0]; - fUserDefinedPatternsEnabled= false; - fPreviousPatterns= new String[0]; - - fFilterItems= new HashMap(); - FilterDescriptor[] filterDescriptors= FilterDescriptor.getFilterDescriptors(fTargetId); - for (int i= 0; i < filterDescriptors.length; i++) { - FilterItem item= new FilterItem(filterDescriptors[i]); - Object existing= fFilterItems.put(item.id, item); - if (existing != null) { - JavaScriptPlugin.logErrorMessage("WARNING: Duplicate id for extension-point \"org.eclipse.wst.jsdt.ui.javaElementFilters\" in " + ownerId); //$NON-NLS-1$ - } - } - - initializeWithViewDefaults(); - - updateViewerFilters(); - } - - /* - * Method declared on ActionGroup. - */ - public void fillActionBars(IActionBars actionBars) { - fillToolBar(actionBars.getToolBarManager()); - fillViewMenu(actionBars.getMenuManager()); - } - - /** - * Returns a list of currently enabled filters. The filter - * is identified by its id. - * <p> - * This method is for internal use only and should not - * be called by clients outside of JDT/UI. - * </p> - * - * @return a list of currently enabled filters - * - * - */ - public String[] internalGetEnabledFilterIds() { - ArrayList enabledFilterIds= new ArrayList(); - for (Iterator iterator= fFilterItems.values().iterator(); iterator.hasNext();) { - FilterItem item= (FilterItem) iterator.next(); - if (item.enabled) { - enabledFilterIds.add(item.id); - } - } - return (String[])enabledFilterIds.toArray(new String[enabledFilterIds.size()]); - } - - /** - * Removes filters for the given parent and element - * - * @param parent the parent of the element - * @param element the element - * @param contentProvider the content provider of the viewer from which - * the filters will be removed - * - * @return the array of new filter ids - */ - public String[] removeFiltersFor(Object parent, Object element, IContentProvider contentProvider) { - ArrayList newFilters= new ArrayList(); - for (Iterator iterator= fFilterItems.values().iterator(); iterator.hasNext();) { - FilterItem item= (FilterItem) iterator.next(); - if (item.enabled) { - ViewerFilter filter= item.getFilterInstance(); - if (filter != null && isSelected(parent, element, contentProvider, filter)) - newFilters.add(item.id); - } - } - return (String[])newFilters.toArray(new String[newFilters.size()]); - } - - /** - * Sets the filters to the given array of new filters - * - * @param newFilters the new filters - */ - public void setFilters(String[] newFilters) { - setEnabledFilterIds(newFilters); - updateViewerFilters(); - } - - private boolean isSelected(Object parent, Object element, IContentProvider contentProvider, ViewerFilter filter) { - if (contentProvider instanceof ITreeContentProvider) { - // the element and all its parents have to be selected - ITreeContentProvider provider = (ITreeContentProvider) contentProvider; - while (element != null && !(element instanceof IJavaScriptModel)) { - if (!filter.select(fViewer, parent, element)) - return false; - element= provider.getParent( element); - } - return true; - } - return filter.select(fViewer, parent, element); - } - - /** - * Sets the enable state of the given filter. - * - * @param filterId the id of the filter - * @param state the filter state - */ - private void setFilter(String filterId, boolean state) { - // Renew filter id in LRU stack - fLRUFilterIdsStack.remove(filterId); - fLRUFilterIdsStack.add(0, filterId); - - FilterItem item= (FilterItem) fFilterItems.get(filterId); - if (item != null) { - item.enabled= state; - storeViewDefaults(); - - updateViewerFilters(); - } - } - - private void setEnabledFilterIds(String[] enabledIds) { - // set all to false - for (Iterator iterator= fFilterItems.values().iterator(); iterator.hasNext();) { - FilterItem item= (FilterItem) iterator.next(); - item.enabled= false; - } - // set enabled to true - for (int i= 0; i < enabledIds.length; i++) { - FilterItem item= (FilterItem) fFilterItems.get(enabledIds[i]); - if (item != null) { - item.enabled= true; - } - } - } - - private void setUserDefinedPatterns(String[] patterns) { - fUserDefinedPatterns= patterns; - } - - /** - * Sets the recently changed filters. - * - * @param changeHistory the change history - * - */ - private void setRecentlyChangedFilters(Stack changeHistory) { - Stack oldestFirstStack= new Stack(); - - int length= Math.min(changeHistory.size(), MAX_FILTER_MENU_ENTRIES); - for (int i= 0; i < length; i++) - oldestFirstStack.push(((FilterDescriptor)changeHistory.pop()).getId()); - - length= Math.min(fLRUFilterIdsStack.size(), MAX_FILTER_MENU_ENTRIES - oldestFirstStack.size()); - int NEWEST= 0; - for (int i= 0; i < length; i++) { - Object filter= fLRUFilterIdsStack.remove(NEWEST); - if (!oldestFirstStack.contains(filter)) - oldestFirstStack.push(filter); - } - fLRUFilterIdsStack= oldestFirstStack; - } - - private boolean areUserDefinedPatternsEnabled() { - return fUserDefinedPatternsEnabled; - } - - private void setUserDefinedPatternsEnabled(boolean state) { - fUserDefinedPatternsEnabled= state; - } - - private void fillToolBar(IToolBarManager tooBar) { - } - - /** - * Fills the given view menu with the entries managed by the - * group. - * - * @param viewMenu the menu to fill - */ - public void fillViewMenu(IMenuManager viewMenu) { - /* - * Don't change the separator group name. - * Using this name ensures that other filters - * get contributed to the same group. - */ - viewMenu.add(new Separator("filters")); //$NON-NLS-1$ - viewMenu.add(new GroupMarker(RECENT_FILTERS_GROUP_NAME)); - viewMenu.add(new ShowFilterDialogAction()); - - fMenuManager= viewMenu; - fMenuListener= new IMenuListener() { - public void menuAboutToShow(IMenuManager manager) { - removePreviousLRUFilterActions(manager); - addLRUFilterActions(manager); - } - }; - fMenuManager.addMenuListener(fMenuListener); - } - - private void removePreviousLRUFilterActions(IMenuManager mm) { - if (fFilterIdsUsedInLastViewMenu == null) - return; - - for (int i= 0; i < fFilterIdsUsedInLastViewMenu.length; i++) - mm.remove(fFilterIdsUsedInLastViewMenu[i]); - } - - private void addLRUFilterActions(IMenuManager mm) { - if (fLRUFilterIdsStack.isEmpty()) { - fFilterIdsUsedInLastViewMenu= null; - return; - } - - SortedSet sortedFilters= new TreeSet(fLRUFilterIdsStack); - String[] recentlyChangedFilterIds= (String[])sortedFilters.toArray(new String[sortedFilters.size()]); - - fFilterIdsUsedInLastViewMenu= new String[recentlyChangedFilterIds.length]; - for (int i= 0; i < recentlyChangedFilterIds.length; i++) { - String id= recentlyChangedFilterIds[i]; - fFilterIdsUsedInLastViewMenu[i]= id; - FilterItem filterItem= (FilterItem) fFilterItems.get(id); - if (filterItem != null) { - IContributionItem item= new FilterActionMenuContributionItem(this, id, filterItem.descriptor.getName(), filterItem.enabled, i+1); - mm.insertBefore(RECENT_FILTERS_GROUP_NAME, item); - } - } - } - - /* - * Method declared on ActionGroup. - */ - public void dispose() { - if (fMenuManager != null) - fMenuManager.removeMenuListener(fMenuListener); - fFilterItems.clear(); - super.dispose(); - } - - // ---------- viewer filter handling ---------- - - private boolean updateViewerFilters() { - ViewerFilter[] installedFilters= fViewer.getFilters(); - ArrayList viewerFilters= new ArrayList(Arrays.asList(installedFilters)); - HashSet patterns= new HashSet(); - - boolean hasChange= false; - boolean patternChange= false; - - for (Iterator iterator= fFilterItems.values().iterator(); iterator.hasNext();) { - FilterItem item= (FilterItem) iterator.next(); - if (item.descriptor.isCustomFilter()) { - if (item.enabled != item.previouslyEnabled) { - ViewerFilter filter= item.getFilterInstance(); // only create when changed - if (filter != null) { - if (item.enabled) { - viewerFilters.add(filter); - } else { - viewerFilters.remove(filter); - } - hasChange= true; - } - } - } else if (item.descriptor.isPatternFilter()) { - if (item.enabled) { - patterns.add(item.descriptor.getPattern()); - } - patternChange |= (item.enabled != item.previouslyEnabled); - } - item.previouslyEnabled= item.enabled; - } - - if (areUserDefinedPatternsEnabled()) { - for (int i= 0; i < fUserDefinedPatterns.length; i++) { - patterns.add(fUserDefinedPatterns[i]); - } - } - if (!patternChange) { // no pattern change so far, test if the user patterns made a difference - patternChange= hasChanges(patterns, fPreviousPatterns); - } - - fPreviousPatterns= (String[]) patterns.toArray(new String[patterns.size()]); - if (patternChange) { - fPatternFilter.setPatterns(fPreviousPatterns); - if (patterns.isEmpty()) { - viewerFilters.remove(fPatternFilter); - } else if (!viewerFilters.contains(fPatternFilter)) { - viewerFilters.add(fPatternFilter); - } - hasChange= true; - } - if (hasChange) { - fViewer.setFilters((ViewerFilter[]) viewerFilters.toArray(new ViewerFilter[viewerFilters.size()])); // will refresh - } - return hasChange; - } - - private boolean hasChanges(HashSet patterns, String[] oldPatterns) { - HashSet copy= (HashSet) patterns.clone(); - for (int i= 0; i < oldPatterns.length; i++) { - boolean found= copy.remove(oldPatterns[i]); - if (!found) - return true; - } - return !copy.isEmpty(); - } - - // ---------- view kind/defaults persistency ---------- - - private void initializeWithViewDefaults() { - // get default values for view - IPreferenceStore store= JavaScriptPlugin.getDefault().getPreferenceStore(); - - // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=22533 - if (!store.contains(getPreferenceKey(TAG_DUMMY_TO_TEST_EXISTENCE))) - return; - - fUserDefinedPatternsEnabled= store.getBoolean(getPreferenceKey(TAG_USER_DEFINED_PATTERNS_ENABLED)); - setUserDefinedPatterns(CustomFiltersDialog.convertFromString(store.getString(getPreferenceKey(TAG_USER_DEFINED_PATTERNS)), SEPARATOR)); - - for (Iterator iterator= fFilterItems.values().iterator(); iterator.hasNext();) { - FilterItem item= (FilterItem) iterator.next(); - String id= item.id; - // set default to value from plugin contributions (fixes https://bugs.eclipse.org/bugs/show_bug.cgi?id=73991 ): - store.setDefault(id, item.descriptor.isEnabled()); - item.enabled= store.getBoolean(id); - } - - fLRUFilterIdsStack.clear(); - String lruFilterIds= store.getString(TAG_LRU_FILTERS); - StringTokenizer tokenizer= new StringTokenizer(lruFilterIds, SEPARATOR); - while (tokenizer.hasMoreTokens()) { - String id= tokenizer.nextToken(); - if (fFilterItems.containsKey(id) && !fLRUFilterIdsStack.contains(id)) - fLRUFilterIdsStack.push(id); - } - } - - private void storeViewDefaults() { - // get default values for view - IPreferenceStore store= JavaScriptPlugin.getDefault().getPreferenceStore(); - - // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=22533 - store.setValue(getPreferenceKey(TAG_DUMMY_TO_TEST_EXISTENCE), "storedViewPreferences");//$NON-NLS-1$ - - store.setValue(getPreferenceKey(TAG_USER_DEFINED_PATTERNS_ENABLED), fUserDefinedPatternsEnabled); - store.setValue(getPreferenceKey(TAG_USER_DEFINED_PATTERNS), CustomFiltersDialog.convertToString(fUserDefinedPatterns ,SEPARATOR)); - - for (Iterator iterator= fFilterItems.values().iterator(); iterator.hasNext();) { - FilterItem item= (FilterItem) iterator.next(); - store.setValue(item.id, item.enabled); - } - - StringBuffer buf= new StringBuffer(fLRUFilterIdsStack.size() * 20); - Iterator iter= fLRUFilterIdsStack.iterator(); - while (iter.hasNext()) { - buf.append((String)iter.next()); - buf.append(SEPARATOR); - } - store.setValue(TAG_LRU_FILTERS, buf.toString()); - } - - private String getPreferenceKey(String tag) { - return "CustomFiltersActionGroup." + fTargetId + '.' + tag; //$NON-NLS-1$ - } - - // ---------- view instance persistency ---------- - - /** - * Saves the state of the custom filters in a memento. - * - * @param memento the memento into which the state is saved - */ - public void saveState(IMemento memento) { - IMemento customFilters= memento.createChild(TAG_CUSTOM_FILTERS); - customFilters.putString(TAG_USER_DEFINED_PATTERNS_ENABLED, Boolean.toString(fUserDefinedPatternsEnabled)); - saveUserDefinedPatterns(customFilters); - saveXmlDefinedFilters(customFilters); - saveLRUFilters(customFilters); - } - - private void saveXmlDefinedFilters(IMemento memento) { - IMemento xmlDefinedFilters= memento.createChild(TAG_XML_DEFINED_FILTERS); - - for (Iterator iterator= fFilterItems.values().iterator(); iterator.hasNext();) { - FilterItem item= (FilterItem) iterator.next(); - - IMemento child= xmlDefinedFilters.createChild(TAG_CHILD); - child.putString(TAG_FILTER_ID, item.id); - child.putString(TAG_IS_ENABLED, String.valueOf(item.enabled)); - } - } - /** - * Stores the last recently used filter Ids into - * the given memento - * - * @param memento the memento into which to store the LRU filter Ids - * - */ - private void saveLRUFilters(IMemento memento) { - if(fLRUFilterIdsStack != null && !fLRUFilterIdsStack.isEmpty()) { - IMemento lruFilters= memento.createChild(TAG_LRU_FILTERS); - Iterator iter= fLRUFilterIdsStack.iterator(); - while (iter.hasNext()) { - String id= (String)iter.next(); - IMemento child= lruFilters.createChild(TAG_CHILD); - child.putString(TAG_FILTER_ID, id); - } - } - } - - private void saveUserDefinedPatterns(IMemento memento) { - if(fUserDefinedPatterns != null && fUserDefinedPatterns.length > 0) { - IMemento userDefinedPatterns= memento.createChild(TAG_USER_DEFINED_PATTERNS); - for (int i= 0; i < fUserDefinedPatterns.length; i++) { - IMemento child= userDefinedPatterns.createChild(TAG_CHILD); - child.putString(TAG_PATTERN, fUserDefinedPatterns[i]); - } - } - } - - /** - * Restores the state of the filter actions from a memento. - * <p> - * Note: This method does not refresh the viewer. - * </p> - * - * @param memento the memento from which the state is restored - */ - public void restoreState(IMemento memento) { - if (memento == null) - return; - IMemento customFilters= memento.getChild(TAG_CUSTOM_FILTERS); - if (customFilters == null) - return; - String userDefinedPatternsEnabled= customFilters.getString(TAG_USER_DEFINED_PATTERNS_ENABLED); - if (userDefinedPatternsEnabled == null) - return; - - fUserDefinedPatternsEnabled= Boolean.valueOf(userDefinedPatternsEnabled).booleanValue(); - restoreUserDefinedPatterns(customFilters); - restoreXmlDefinedFilters(customFilters); - restoreLRUFilters(customFilters); - - updateViewerFilters(); - } - - private void restoreUserDefinedPatterns(IMemento memento) { - IMemento userDefinedPatterns= memento.getChild(TAG_USER_DEFINED_PATTERNS); - if(userDefinedPatterns != null) { - IMemento children[]= userDefinedPatterns.getChildren(TAG_CHILD); - String[] patterns= new String[children.length]; - for (int i = 0; i < children.length; i++) - patterns[i]= children[i].getString(TAG_PATTERN); - - setUserDefinedPatterns(patterns); - } else - setUserDefinedPatterns(new String[0]); - } - - private void restoreXmlDefinedFilters(IMemento memento) { - IMemento xmlDefinedFilters= memento.getChild(TAG_XML_DEFINED_FILTERS); - if(xmlDefinedFilters != null) { - IMemento[] children= xmlDefinedFilters.getChildren(TAG_CHILD); - for (int i= 0; i < children.length; i++) { - String id= children[i].getString(TAG_FILTER_ID); - Boolean isEnabled= Boolean.valueOf(children[i].getString(TAG_IS_ENABLED)); - FilterItem item= (FilterItem) fFilterItems.get(id); - if (item != null) { - item.enabled= isEnabled.booleanValue(); - } - } - } - } - - private void restoreLRUFilters(IMemento memento) { - IMemento lruFilters= memento.getChild(TAG_LRU_FILTERS); - fLRUFilterIdsStack.clear(); - if(lruFilters != null) { - IMemento[] children= lruFilters.getChildren(TAG_CHILD); - for (int i= 0; i < children.length; i++) { - String id= children[i].getString(TAG_FILTER_ID); - if (fFilterItems.containsKey(id) && !fLRUFilterIdsStack.contains(id)) - fLRUFilterIdsStack.push(id); - } - } - } - - // ---------- dialog related code ---------- - - private void openDialog() { - CustomFiltersDialog dialog= new CustomFiltersDialog( - fViewer.getControl().getShell(), - fTargetId, - areUserDefinedPatternsEnabled(), - fUserDefinedPatterns, - internalGetEnabledFilterIds()); - - if (dialog.open() == Window.OK) { - setEnabledFilterIds(dialog.getEnabledFilterIds()); - setUserDefinedPatternsEnabled(dialog.areUserDefinedPatternsEnabled()); - setUserDefinedPatterns(dialog.getUserDefinedPatterns()); - setRecentlyChangedFilters(dialog.getFilterDescriptorChangeHistory()); - - storeViewDefaults(); - - updateViewerFilters(); - } - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/DeclarationsSearchGroup.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/DeclarationsSearchGroup.java deleted file mode 100644 index b89edac0..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/DeclarationsSearchGroup.java +++ /dev/null @@ -1,207 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.util.Iterator; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.IWorkingSet; -import org.eclipse.ui.actions.ActionGroup; -import org.eclipse.ui.texteditor.ITextEditorActionConstants; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.search.SearchMessages; -import org.eclipse.wst.jsdt.internal.ui.search.SearchUtil; -import org.eclipse.wst.jsdt.ui.IContextMenuConstants; - -/** - * Action group that adds the search for declarations actions to a - * context menu and the global menu bar. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class DeclarationsSearchGroup extends ActionGroup { - - private static final String MENU_TEXT= SearchMessages.group_declarations; - - private IWorkbenchSite fSite; - private JavaEditor fEditor; - private IActionBars fActionBars; - - private String fGroupId; - - private FindDeclarationsAction fFindDeclarationsAction; - private FindDeclarationsInProjectAction fFindDeclarationsInProjectAction; - private FindDeclarationsInWorkingSetAction fFindDeclarationsInWorkingSetAction; - private FindDeclarationsInHierarchyAction fFindDeclarationsInHierarchyAction; - - /** - * Creates a new <code>DeclarationsSearchGroup</code>. The group requires - * that the selection provided by the site's selection provider is of type <code> - * IStructuredSelection</code>. - * - * @param site the workbench site that owns this action group - */ - public DeclarationsSearchGroup(IWorkbenchSite site) { - fSite= site; - fGroupId= IContextMenuConstants.GROUP_SEARCH; - - fFindDeclarationsAction= new FindDeclarationsAction(site); - fFindDeclarationsAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_DECLARATIONS_IN_WORKSPACE); - - fFindDeclarationsInProjectAction= new FindDeclarationsInProjectAction(site); - fFindDeclarationsInProjectAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_DECLARATIONS_IN_PROJECTS); - - fFindDeclarationsInHierarchyAction= new FindDeclarationsInHierarchyAction(site); - fFindDeclarationsInHierarchyAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_DECLARATIONS_IN_HIERARCHY); - - fFindDeclarationsInWorkingSetAction= new FindDeclarationsInWorkingSetAction(site); - fFindDeclarationsInWorkingSetAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_DECLARATIONS_IN_WORKING_SET); - - // register the actions as selection listeners - ISelectionProvider provider= fSite.getSelectionProvider(); - ISelection selection= provider.getSelection(); - registerAction(fFindDeclarationsAction, provider, selection); - registerAction(fFindDeclarationsInProjectAction, provider, selection); - registerAction(fFindDeclarationsInHierarchyAction, provider, selection); - registerAction(fFindDeclarationsInWorkingSetAction, provider, selection); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * - * @param editor the JavaScript editor - */ - public DeclarationsSearchGroup(JavaEditor editor) { - Assert.isNotNull(editor); - fEditor= editor; - fSite= fEditor.getSite(); - fGroupId= ITextEditorActionConstants.GROUP_FIND; - - fFindDeclarationsAction= new FindDeclarationsAction(fEditor); - fFindDeclarationsAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_DECLARATIONS_IN_WORKSPACE); - fEditor.setAction("SearchDeclarationsInWorkspace", fFindDeclarationsAction); //$NON-NLS-1$ - - fFindDeclarationsInProjectAction= new FindDeclarationsInProjectAction(fEditor); - fFindDeclarationsInProjectAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_DECLARATIONS_IN_PROJECTS); - fEditor.setAction("SearchDeclarationsInProjects", fFindDeclarationsInProjectAction); //$NON-NLS-1$ - - fFindDeclarationsInHierarchyAction= new FindDeclarationsInHierarchyAction(fEditor); - fFindDeclarationsInHierarchyAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_DECLARATIONS_IN_HIERARCHY); - fEditor.setAction("SearchDeclarationsInHierarchy", fFindDeclarationsInHierarchyAction); //$NON-NLS-1$ - - fFindDeclarationsInWorkingSetAction= new FindDeclarationsInWorkingSetAction(fEditor); - fFindDeclarationsInWorkingSetAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_DECLARATIONS_IN_WORKING_SET); - fEditor.setAction("SearchDeclarationsInWorkingSet", fFindDeclarationsInWorkingSetAction); //$NON-NLS-1$ - } - - private void registerAction(SelectionDispatchAction action, ISelectionProvider provider, ISelection selection) { - action.update(selection); - provider.addSelectionChangedListener(action); - } - - /* (non-Javadoc) - * Method declared on ActionGroup. - */ - public void fillActionBars(IActionBars actionBars) { - Assert.isNotNull(actionBars); - super.fillActionBars(actionBars); - fActionBars= actionBars; - updateGlobalActionHandlers(); - } - - private void addAction(IAction action, IMenuManager manager) { - if (action.isEnabled()) { - manager.add(action); - } - } - - private void addWorkingSetAction(IWorkingSet[] workingSets, IMenuManager manager) { - FindAction action; - if (fEditor != null) - action= new WorkingSetFindAction(fEditor, new FindDeclarationsInWorkingSetAction(fEditor, workingSets), SearchUtil.toString(workingSets)); - else - action= new WorkingSetFindAction(fSite, new FindDeclarationsInWorkingSetAction(fSite, workingSets), SearchUtil.toString(workingSets)); - action.update(getContext().getSelection()); - addAction(action, manager); - } - - - /* (non-Javadoc) - * Method declared on ActionGroup. - */ - public void fillContextMenu(IMenuManager manager) { - IMenuManager javaSearchMM= new MenuManager(MENU_TEXT, IContextMenuConstants.GROUP_SEARCH); - addAction(fFindDeclarationsAction, javaSearchMM); - addAction(fFindDeclarationsInProjectAction, javaSearchMM); - addAction(fFindDeclarationsInHierarchyAction, javaSearchMM); - - javaSearchMM.add(new Separator()); - - Iterator iter= SearchUtil.getLRUWorkingSets().sortedIterator(); - while (iter.hasNext()) { - addWorkingSetAction((IWorkingSet[]) iter.next(), javaSearchMM); - } - addAction(fFindDeclarationsInWorkingSetAction, javaSearchMM); - - if (!javaSearchMM.isEmpty()) - manager.appendToGroup(fGroupId, javaSearchMM); - } - - /* - * Method declared on ActionGroup. - */ - public void dispose() { - ISelectionProvider provider= fSite.getSelectionProvider(); - if (provider != null) { - disposeAction(fFindDeclarationsAction, provider); - disposeAction(fFindDeclarationsInProjectAction, provider); - disposeAction(fFindDeclarationsInHierarchyAction, provider); - disposeAction(fFindDeclarationsInWorkingSetAction, provider); - } - fFindDeclarationsAction= null; - fFindDeclarationsInProjectAction= null; - fFindDeclarationsInHierarchyAction= null; - fFindDeclarationsInWorkingSetAction= null; - updateGlobalActionHandlers(); - super.dispose(); - } - - private void updateGlobalActionHandlers() { - if (fActionBars != null) { - fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_DECLARATIONS_IN_WORKSPACE, fFindDeclarationsAction); - fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_DECLARATIONS_IN_PROJECT, fFindDeclarationsInProjectAction); - fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_DECLARATIONS_IN_HIERARCHY, fFindDeclarationsInHierarchyAction); - fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_DECLARATIONS_IN_WORKING_SET, fFindDeclarationsInWorkingSetAction); - } - } - - private void disposeAction(ISelectionChangedListener action, ISelectionProvider provider) { - if (action != null) - provider.removeSelectionChangedListener(action); - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ExternalizeStringsAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ExternalizeStringsAction.java deleted file mode 100644 index fd81231d..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ExternalizeStringsAction.java +++ /dev/null @@ -1,541 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.ArrayContentProvider; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IJavaScriptUnit; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.IJavaScriptProject; -import org.eclipse.wst.jsdt.core.IPackageFragment; -import org.eclipse.wst.jsdt.core.IPackageFragmentRoot; -import org.eclipse.wst.jsdt.core.IType; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.core.compiler.InvalidInputException; -import org.eclipse.wst.jsdt.internal.corext.refactoring.RefactoringAvailabilityTester; -import org.eclipse.wst.jsdt.internal.corext.refactoring.nls.NLSElement; -import org.eclipse.wst.jsdt.internal.corext.refactoring.nls.NLSLine; -import org.eclipse.wst.jsdt.internal.corext.refactoring.nls.NLSRefactoring; -import org.eclipse.wst.jsdt.internal.corext.refactoring.nls.NLSScanner; -import org.eclipse.wst.jsdt.internal.corext.refactoring.reorg.ReorgUtils; -import org.eclipse.wst.jsdt.internal.corext.util.JavaModelUtil; -import org.eclipse.wst.jsdt.internal.corext.util.Messages; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.CompilationUnitEditor; -import org.eclipse.wst.jsdt.internal.ui.refactoring.RefactoringSaveHelper; -import org.eclipse.wst.jsdt.internal.ui.refactoring.actions.ListDialog; -import org.eclipse.wst.jsdt.internal.ui.refactoring.actions.RefactoringStarter; -import org.eclipse.wst.jsdt.internal.ui.refactoring.nls.ExternalizeWizard; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; -import org.eclipse.wst.jsdt.ui.JavaScriptElementLabelProvider; - -/** - * Externalizes the strings of a compilation unit or find all strings - * in a package or project that are not externalized yet. Opens a wizard that - * gathers additional information to externalize the strings. - * <p> - * The action is applicable to structured selections containing elements - * of type <code>IJavaScriptUnit</code>, <code>IType</code>, <code>IJavaScriptProject</code>, - * <code>IPackageFragment</code>, and <code>IPackageFragmentRoot</code> - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class ExternalizeStringsAction extends SelectionDispatchAction { - - private CompilationUnitEditor fEditor; - - private NonNLSElement[] fElements; - - /** - * Creates a new <code>ExternalizeStringsAction</code>. The action requires - * that the selection provided by the site's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public ExternalizeStringsAction(IWorkbenchSite site) { - super(site); - setText(ActionMessages.ExternalizeStringsAction_label); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.EXTERNALIZE_STRINGS_ACTION); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the compilation unit editor - */ - public ExternalizeStringsAction(CompilationUnitEditor editor) { - this(editor.getEditorSite()); - fEditor= editor; - setEnabled(fEditor != null && SelectionConverter.canOperateOn(fEditor)); - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void selectionChanged(ITextSelection selection) { - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void selectionChanged(IStructuredSelection selection) { - try { - setEnabled(RefactoringAvailabilityTester.isExternalizeStringsAvailable(selection)); - } catch (JavaScriptModelException e) { - if (JavaModelUtil.isExceptionToBeLogged(e)) - JavaScriptPlugin.log(e); - setEnabled(false);//no UI - happens on selection changes - } - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void run(ITextSelection selection) { - IJavaScriptElement element= SelectionConverter.getInput(fEditor); - if (!(element instanceof IJavaScriptUnit)) - return; - run((IJavaScriptUnit)element); - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void run(IStructuredSelection selection) { - IJavaScriptUnit unit= getCompilationUnit(selection); - if (unit != null) {//run on cu - run(unit); - } else { - //run on multiple - try { - PlatformUI.getWorkbench().getProgressService().run(true, true, createRunnable(selection)); - } catch(InvocationTargetException e) { - ExceptionHandler.handle(e, getShell(), - ActionMessages.ExternalizeStringsAction_dialog_title, - ActionMessages.FindStringsToExternalizeAction_error_message); - return; - } catch(InterruptedException e) { - // OK - return; - } - showResults(); - } - } - - /** - * Note: this method is for internal use only. Clients should not call this method. - */ - public void run(final IJavaScriptUnit unit) { - if (!ActionUtil.isEditable(fEditor, getShell(), unit)) - return; - - BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() { - public void run() { - try { - if (unit != null && unit.exists()) { - NLSRefactoring refactoring= NLSRefactoring.create(unit); - if (refactoring != null) - new RefactoringStarter().activate(refactoring, new ExternalizeWizard(refactoring), getShell(), ActionMessages.ExternalizeStringsAction_dialog_title, RefactoringSaveHelper.SAVE_NON_JAVA_UPDATES); - } - } catch(JavaScriptModelException e) { - ExceptionHandler.handle(e, getShell(), ActionMessages.ExternalizeStringsAction_dialog_title, ActionMessages.ExternalizeStringsAction_dialog_message); - } - } - }); - } - - private static IJavaScriptUnit getCompilationUnit(IStructuredSelection selection) { - if (selection.isEmpty() || selection.size() != 1) - return null; - Object first= selection.getFirstElement(); - if (first instanceof IJavaScriptUnit) - return (IJavaScriptUnit) first; - if (first instanceof IType) - return ((IType) first).getJavaScriptUnit(); - return null; - } - - private IRunnableWithProgress createRunnable(final IStructuredSelection selection) { - return new IRunnableWithProgress() { - public void run(IProgressMonitor pm) throws InvocationTargetException { - try { - fElements= doRun(selection, pm); - } catch (CoreException e) { - throw new InvocationTargetException(e); - } - } - }; - } - - private NonNLSElement[] doRun(IStructuredSelection selection, IProgressMonitor pm) throws CoreException { - List elements= getSelectedElementList(selection); - if (elements == null || elements.isEmpty()) - return new NonNLSElement[0]; - - pm.beginTask(ActionMessages.FindStringsToExternalizeAction_find_strings, elements.size()); - - try{ - List result= new ArrayList(); - for (Iterator iter= elements.iterator(); iter.hasNext();) { - Object obj= iter.next(); - if (obj instanceof IJavaScriptElement) { - IJavaScriptElement element= (IJavaScriptElement) obj; - int elementType= element.getElementType(); - - if (elementType == IJavaScriptElement.PACKAGE_FRAGMENT) { - result.addAll(analyze((IPackageFragment) element, new SubProgressMonitor(pm, 1))); - } else if (elementType == IJavaScriptElement.PACKAGE_FRAGMENT_ROOT) { - IPackageFragmentRoot root= (IPackageFragmentRoot)element; - if (!root.isExternal() && !ReorgUtils.isClassFolder(root)) { - result.addAll(analyze((IPackageFragmentRoot) element, new SubProgressMonitor(pm, 1))); - } else { - pm.worked(1); - } - } else if (elementType == IJavaScriptElement.JAVASCRIPT_PROJECT) { - result.addAll(analyze((IJavaScriptProject) element, new SubProgressMonitor(pm, 1))); - } else if (elementType == IJavaScriptElement.JAVASCRIPT_UNIT) { - IJavaScriptUnit cu= (IJavaScriptUnit)element; - if (cu.exists()) { - NonNLSElement nlsElement= analyze(cu); - if (nlsElement != null) { - result.add(nlsElement); - } - } - pm.worked(1); - } else if (elementType == IJavaScriptElement.TYPE) { - IType type= (IType)element; - IJavaScriptUnit cu= type.getJavaScriptUnit(); - if (cu != null && cu.exists()) { - NonNLSElement nlsElement= analyze(cu); - if (nlsElement != null) { - result.add(nlsElement); - } - } - pm.worked(1); - } else { - pm.worked(1); - } - } else { - pm.worked(1); - } - } - return (NonNLSElement[]) result.toArray(new NonNLSElement[result.size()]); - } finally{ - pm.done(); - } - } - - private void showResults() { - if (noStrings()) - MessageDialog.openInformation(getShell(), ActionMessages.ExternalizeStringsAction_dialog_title, ActionMessages.FindStringsToExternalizeAction_noStrings); - else - new NonNLSListDialog(getShell(), fElements, countStrings()).open(); - } - - private boolean noStrings() { - if (fElements != null) { - for (int i= 0; i < fElements.length; i++) { - if (fElements[i].count != 0) - return false; - } - } - return true; - } - - /* - * returns List of Strings - */ - private List analyze(IPackageFragment pack, IProgressMonitor pm) throws CoreException { - try{ - if (pack == null) - return new ArrayList(0); - - IJavaScriptUnit[] cus= pack.getJavaScriptUnits(); - - pm.beginTask("", cus.length); //$NON-NLS-1$ - pm.setTaskName(pack.getElementName()); - - List l= new ArrayList(cus.length); - for (int i= 0; i < cus.length; i++){ - pm.subTask(cus[i].getElementName()); - NonNLSElement element= analyze(cus[i]); - if (element != null) - l.add(element); - pm.worked(1); - if (pm.isCanceled()) - throw new OperationCanceledException(); - } - return l; - } finally { - pm.done(); - } - } - - /* - * returns List of Strings - */ - private List analyze(IPackageFragmentRoot sourceFolder, IProgressMonitor pm) throws CoreException { - try{ - IJavaScriptElement[] children= sourceFolder.getChildren(); - pm.beginTask("", children.length); //$NON-NLS-1$ - pm.setTaskName(sourceFolder.getElementName()); - List result= new ArrayList(); - for (int i= 0; i < children.length; i++) { - IJavaScriptElement iJavaElement= children[i]; - if (iJavaElement.getElementType() == IJavaScriptElement.PACKAGE_FRAGMENT){ - IPackageFragment pack= (IPackageFragment)iJavaElement; - if (! pack.isReadOnly()) - result.addAll(analyze(pack, new SubProgressMonitor(pm, 1))); - else - pm.worked(1); - } else - pm.worked(1); - } - return result; - } finally{ - pm.done(); - } - } - - /* - * returns List of Strings - */ - private List analyze(IJavaScriptProject project, IProgressMonitor pm) throws CoreException { - try{ - IPackageFragment[] packs= project.getPackageFragments(); - pm.beginTask("", packs.length); //$NON-NLS-1$ - List result= new ArrayList(); - for (int i= 0; i < packs.length; i++) { - if (! packs[i].isReadOnly()) - result.addAll(analyze(packs[i], new SubProgressMonitor(pm, 1))); - else - pm.worked(1); - } - return result; - } finally{ - pm.done(); - } - } - - private int countStrings() { - int found= 0; - if (fElements != null) { - for (int i= 0; i < fElements.length; i++) - found+= fElements[i].count; - } - return found; - } - - private NonNLSElement analyze(IJavaScriptUnit cu) throws CoreException { - int count= countNonExternalizedStrings(cu); - if (count == 0) - return null; - else - return new NonNLSElement(cu, count); - } - - private int countNonExternalizedStrings(IJavaScriptUnit cu) throws CoreException { - try{ - NLSLine[] lines= NLSScanner.scan(cu); - int result= 0; - for (int i= 0; i < lines.length; i++) { - result += countNonExternalizedStrings(lines[i]); - } - return result; - } catch (InvalidInputException e) { - throw new CoreException(new Status(IStatus.ERROR, JavaScriptPlugin.getPluginId(), IStatus.ERROR, - Messages.format(ActionMessages.FindStringsToExternalizeAction_error_cannotBeParsed, cu.getElementName()), - e)); - } - } - - private int countNonExternalizedStrings(NLSLine line){ - int result= 0; - NLSElement[] elements= line.getElements(); - for (int i= 0; i < elements.length; i++){ - if (! elements[i].hasTag()) - result++; - } - return result; - } - - /** - * returns <code>List</code> of <code>IPackageFragments</code>, <code>IPackageFragmentRoots</code> or - * <code>IJavaProjects</code> (all entries are of the same kind) - */ - private static List getSelectedElementList(IStructuredSelection selection) { - if (selection == null) - return null; - - return selection.toList(); - } - - //-------private classes -------------- - - private static class NonNLSListDialog extends ListDialog { - - private static final int OPEN_BUTTON_ID= IDialogConstants.CLIENT_ID + 1; - - private Button fOpenButton; - - NonNLSListDialog(Shell parent, NonNLSElement[] input, int count) { - super(parent); - setInput(Arrays.asList(input)); - setTitle(ActionMessages.ExternalizeStringsAction_dialog_title); - setMessage(Messages.format(ActionMessages.FindStringsToExternalizeAction_non_externalized, new Object[] {new Integer(count)} )); - setContentProvider(new ArrayContentProvider()); - setLabelProvider(createLabelProvider()); - } - - public void create() { - setShellStyle(SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MIN); - super.create(); - } - - protected Point getInitialSize() { - return getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT, true); - } - - protected Control createDialogArea(Composite parent) { - Composite result= (Composite)super.createDialogArea(parent); - getTableViewer().addSelectionChangedListener(new ISelectionChangedListener(){ - public void selectionChanged(SelectionChangedEvent event){ - if (fOpenButton != null){ - fOpenButton.setEnabled(! getTableViewer().getSelection().isEmpty()); - } - } - }); - getTableViewer().getTable().addSelectionListener(new SelectionAdapter(){ - public void widgetDefaultSelected(SelectionEvent e) { - NonNLSElement element= (NonNLSElement)e.item.getData(); - openWizard(element.cu); - } - }); - getTableViewer().getTable().setFocus(); - applyDialogFont(result); - return result; - } - - protected void createButtonsForButtonBar(Composite parent) { - fOpenButton= createButton(parent, OPEN_BUTTON_ID, ActionMessages.FindStringsToExternalizeAction_button_label, true); - fOpenButton.setEnabled(false); - - //looks like a 'close' but it a 'cancel' - createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CLOSE_LABEL, false); - } - - protected void buttonPressed(int buttonId) { - if (buttonId != OPEN_BUTTON_ID){ - super.buttonPressed(buttonId); - return; - } - ISelection s= getTableViewer().getSelection(); - if (s instanceof IStructuredSelection){ - IStructuredSelection ss= (IStructuredSelection)s; - if (ss.getFirstElement() instanceof NonNLSElement) - openWizard(((NonNLSElement)ss.getFirstElement()).cu); - } - } - - private void openWizard(IJavaScriptUnit unit) { - try { - if (unit != null && unit.exists()) { - NLSRefactoring refactoring= NLSRefactoring.create(unit); - if (refactoring != null) - new RefactoringStarter().activate(refactoring, new ExternalizeWizard(refactoring), getShell(), ActionMessages.ExternalizeStringsAction_dialog_title, RefactoringSaveHelper.SAVE_NON_JAVA_UPDATES); - } - } catch (JavaScriptModelException e) { - ExceptionHandler.handle(e, - ActionMessages.ExternalizeStringsAction_dialog_title, - ActionMessages.FindStringsToExternalizeAction_error_message); - } - } - - private static LabelProvider createLabelProvider() { - return new JavaScriptElementLabelProvider(JavaScriptElementLabelProvider.SHOW_DEFAULT){ - public String getText(Object element) { - NonNLSElement nlsel= (NonNLSElement)element; - String elementName= nlsel.cu.getResource().getFullPath().toString(); - return Messages.format( - ActionMessages.FindStringsToExternalizeAction_foundStrings, - new Object[] {new Integer(nlsel.count), elementName} ); - } - public Image getImage(Object element) { - return super.getImage(((NonNLSElement)element).cu); - } - }; - } - - /* - * @see org.eclipse.jface.window.Window#configureShell(Shell) - */ - protected void configureShell(Shell newShell) { - super.configureShell(newShell); - PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IJavaHelpContextIds.NONNLS_DIALOG); - } - - - } - - private static class NonNLSElement{ - IJavaScriptUnit cu; - int count; - NonNLSElement(IJavaScriptUnit cu, int count){ - this.cu= cu; - this.count= count; - } - } - -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ExtractConstantAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ExtractConstantAction.java deleted file mode 100644 index dd1f8f6c..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ExtractConstantAction.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.internal.corext.refactoring.RefactoringAvailabilityTester; -import org.eclipse.wst.jsdt.internal.corext.refactoring.code.ExtractConstantRefactoring; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaTextSelection; -import org.eclipse.wst.jsdt.internal.ui.refactoring.ExtractConstantWizard; -import org.eclipse.wst.jsdt.internal.ui.refactoring.RefactoringMessages; -import org.eclipse.wst.jsdt.internal.ui.refactoring.RefactoringSaveHelper; -import org.eclipse.wst.jsdt.internal.ui.refactoring.actions.RefactoringStarter; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; - -/** - * Extracts an expression into a constant field and replaces all occurrences of - * the expression with the new constant. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class ExtractConstantAction extends SelectionDispatchAction { - - private final JavaEditor fEditor; - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public ExtractConstantAction(JavaEditor editor) { - super(editor.getEditorSite()); - setText(RefactoringMessages.ExtractConstantAction_label); - fEditor= editor; - setEnabled(SelectionConverter.getInputAsCompilationUnit(fEditor) != null); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.EXTRACT_CONSTANT_ACTION); - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction - */ - public void selectionChanged(ITextSelection selection) { - setEnabled((fEditor != null && SelectionConverter.getInputAsCompilationUnit(fEditor) != null)); - } - - /** - * Note: This method is for internal use only. Clients should not call this method. - */ - public void selectionChanged(JavaTextSelection selection) { - setEnabled(RefactoringAvailabilityTester.isExtractConstantAvailable(selection)); - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction - */ - public void run(ITextSelection selection) { - if (!ActionUtil.isEditable(fEditor)) - return; - try{ - final ExtractConstantRefactoring refactoring= new ExtractConstantRefactoring(SelectionConverter.getInputAsCompilationUnit(fEditor), selection.getOffset(), selection.getLength()); - new RefactoringStarter().activate(refactoring, new ExtractConstantWizard(refactoring), getShell(), RefactoringMessages.ExtractConstantAction_extract_constant, RefactoringSaveHelper.SAVE_NOTHING); - } catch (JavaScriptModelException e){ - ExceptionHandler.handle(e, RefactoringMessages.ExtractConstantAction_extract_constant, RefactoringMessages.NewTextRefactoringAction_exception); - } - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ExtractMethodAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ExtractMethodAction.java deleted file mode 100644 index ef26d148..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ExtractMethodAction.java +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.internal.corext.refactoring.RefactoringAvailabilityTester; -import org.eclipse.wst.jsdt.internal.corext.refactoring.code.ExtractMethodRefactoring; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaTextSelection; -import org.eclipse.wst.jsdt.internal.ui.refactoring.RefactoringMessages; -import org.eclipse.wst.jsdt.internal.ui.refactoring.RefactoringSaveHelper; -import org.eclipse.wst.jsdt.internal.ui.refactoring.actions.RefactoringStarter; -import org.eclipse.wst.jsdt.internal.ui.refactoring.code.ExtractMethodWizard; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; - -/** - * Extracts the code selected inside a compilation unit editor into a new method. - * Necessary arguments, exceptions and returns values are computed and an - * appropriate method signature is generated. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class ExtractMethodAction extends SelectionDispatchAction { - - private final JavaEditor fEditor; - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * - * @param editor the JavaScript editor - */ - public ExtractMethodAction(JavaEditor editor) { - super(editor.getEditorSite()); - setText(RefactoringMessages.ExtractMethodAction_label); - fEditor= editor; - setEnabled(SelectionConverter.getInputAsCompilationUnit(fEditor) != null); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.EXTRACT_METHOD_ACTION); - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction - */ - public void selectionChanged(ITextSelection selection) { - setEnabled(selection.getLength() == 0 ? false : fEditor != null && SelectionConverter.getInputAsCompilationUnit(fEditor) != null); - } - - /** - * Note: This method is for internal use only. Clients should not call this method. - */ - public void selectionChanged(JavaTextSelection selection) { - setEnabled(RefactoringAvailabilityTester.isExtractMethodAvailable(selection)); - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction - */ - public void run(ITextSelection selection) { - if (!ActionUtil.isEditable(fEditor)) - return; - try{ - final ExtractMethodRefactoring refactoring= new ExtractMethodRefactoring(SelectionConverter.getInputAsCompilationUnit(fEditor), selection.getOffset(), selection.getLength()); - new RefactoringStarter().activate(refactoring, new ExtractMethodWizard(refactoring), getShell(), RefactoringMessages.ExtractMethodAction_dialog_title, RefactoringSaveHelper.SAVE_NOTHING); - } catch (CoreException e){ - ExceptionHandler.handle(e, RefactoringMessages.ExtractMethodAction_dialog_title, RefactoringMessages.NewTextRefactoringAction_exception); - } - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ExtractTempAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ExtractTempAction.java deleted file mode 100644 index e52d06b2..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ExtractTempAction.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.internal.corext.refactoring.RefactoringAvailabilityTester; -import org.eclipse.wst.jsdt.internal.corext.refactoring.code.ExtractTempRefactoring; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaTextSelection; -import org.eclipse.wst.jsdt.internal.ui.refactoring.ExtractTempWizard; -import org.eclipse.wst.jsdt.internal.ui.refactoring.RefactoringMessages; -import org.eclipse.wst.jsdt.internal.ui.refactoring.RefactoringSaveHelper; -import org.eclipse.wst.jsdt.internal.ui.refactoring.actions.RefactoringStarter; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; - -/** - * Extracts an expression into a new local variable and replaces all occurrences of - * the expression with the local variable. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class ExtractTempAction extends SelectionDispatchAction { - - private final JavaEditor fEditor; - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public ExtractTempAction(JavaEditor editor) { - super(editor.getEditorSite()); - setText(RefactoringMessages.ExtractTempAction_label); - fEditor= editor; - setEnabled(SelectionConverter.getInputAsCompilationUnit(fEditor) != null); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.EXTRACT_TEMP_ACTION); - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction - */ - public void selectionChanged(ITextSelection selection) { - setEnabled(fEditor != null && SelectionConverter.getInputAsCompilationUnit(fEditor) != null); - } - - /** - * Note: This method is for internal use only. Clients should not call this method. - */ - public void selectionChanged(JavaTextSelection selection) { - setEnabled(RefactoringAvailabilityTester.isExtractTempAvailable(selection)); - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction - */ - public void run(ITextSelection selection) { - if (!ActionUtil.isEditable(fEditor)) - return; - try{ - final ExtractTempRefactoring refactoring= new ExtractTempRefactoring(SelectionConverter.getInputAsCompilationUnit(fEditor), selection.getOffset(), selection.getLength()); - new RefactoringStarter().activate(refactoring, new ExtractTempWizard(refactoring), getShell(), RefactoringMessages.ExtractTempAction_extract_temp, RefactoringSaveHelper.SAVE_NOTHING); - } catch (JavaScriptModelException e){ - ExceptionHandler.handle(e, RefactoringMessages.ExtractTempAction_extract_temp, RefactoringMessages.NewTextRefactoringAction_exception); - } - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindAction.java deleted file mode 100644 index b88c5fb6..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindAction.java +++ /dev/null @@ -1,323 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.lang.reflect.InvocationTargetException; - -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.window.Window; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.ElementListSelectionDialog; -import org.eclipse.ui.progress.IProgressService; -import org.eclipse.wst.jsdt.core.IClassFile; -import org.eclipse.wst.jsdt.core.IJavaScriptUnit; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.ILocalVariable; -import org.eclipse.wst.jsdt.core.IMember; -import org.eclipse.wst.jsdt.core.IPackageFragment; -import org.eclipse.wst.jsdt.core.IType; -import org.eclipse.wst.jsdt.core.JavaScriptCore; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.core.search.IJavaScriptSearchScope; -import org.eclipse.wst.jsdt.internal.corext.util.JavaModelUtil; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.search.JavaSearchQuery; -import org.eclipse.wst.jsdt.internal.ui.search.JavaSearchScopeFactory; -import org.eclipse.wst.jsdt.internal.ui.search.SearchMessages; -import org.eclipse.wst.jsdt.internal.ui.search.SearchUtil; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; -import org.eclipse.wst.jsdt.ui.JavaScriptElementLabelProvider; -import org.eclipse.wst.jsdt.ui.search.ElementQuerySpecification; -import org.eclipse.wst.jsdt.ui.search.QuerySpecification; - -/** - * Abstract class for JavaScript search actions. - * <p> - * Note: This class is for internal use only. Clients should not use this class. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public abstract class FindAction extends SelectionDispatchAction { - - // A dummy which can't be selected in the UI - private static final IJavaScriptElement RETURN_WITHOUT_BEEP= JavaScriptCore.create(JavaScriptPlugin.getWorkspace().getRoot()); - - private Class[] fValidTypes; - private JavaEditor fEditor; - - - FindAction(IWorkbenchSite site) { - super(site); - fValidTypes= getValidTypes(); - init(); - } - - FindAction(JavaEditor editor) { - this(editor.getEditorSite()); - fEditor= editor; - setEnabled(SelectionConverter.canOperateOn(fEditor)); - } - - /** - * Called once by the constructors to initialize label, tooltip, image and help support of the action. - * To be overridden by implementors of this action. - */ - abstract void init(); - - /** - * Called once by the constructors to get the list of the valid input types of the action. - * To be overridden by implementors of this action. - * @return the valid input types of the action - */ - abstract Class[] getValidTypes(); - - private boolean canOperateOn(IStructuredSelection sel) { - return sel != null && !sel.isEmpty() && canOperateOn(getJavaElement(sel, true)); - } - - boolean canOperateOn(IJavaScriptElement element) { - if (element == null || fValidTypes == null || fValidTypes.length == 0 || !ActionUtil.isOnBuildPath(element)) - return false; - - for (int i= 0; i < fValidTypes.length; i++) { - if (fValidTypes[i].isInstance(element)) { - if (element.getElementType() == IJavaScriptElement.PACKAGE_FRAGMENT) - return hasChildren((IPackageFragment)element); - else - return true; - } - } - return false; - } - - private boolean hasChildren(IPackageFragment packageFragment) { - try { - return packageFragment.hasChildren(); - } catch (JavaScriptModelException ex) { - return false; - } - } - - private IJavaScriptElement getTypeIfPossible(IJavaScriptElement o, boolean silent) { - switch (o.getElementType()) { - case IJavaScriptElement.JAVASCRIPT_UNIT: - if (silent) - return o; - else - return findType((IJavaScriptUnit)o, silent); - case IJavaScriptElement.CLASS_FILE: - return ((IClassFile)o).getType(); - default: - return o; - } - } - - IJavaScriptElement getJavaElement(IStructuredSelection selection, boolean silent) { - if (selection.size() == 1) { - Object firstElement= selection.getFirstElement(); - IJavaScriptElement elem= null; - if (firstElement instanceof IJavaScriptElement) - elem= (IJavaScriptElement) firstElement; - else if (firstElement instanceof IAdaptable) - elem= (IJavaScriptElement) ((IAdaptable) firstElement).getAdapter(IJavaScriptElement.class); - if (elem != null) { - return getTypeIfPossible(elem, silent); - } - - } - return null; - } - - private void showOperationUnavailableDialog() { - MessageDialog.openInformation(getShell(), SearchMessages.JavaElementAction_operationUnavailable_title, getOperationUnavailableMessage()); - } - - String getOperationUnavailableMessage() { - return SearchMessages.JavaElementAction_operationUnavailable_generic; - } - - private IJavaScriptElement findType(IJavaScriptUnit cu, boolean silent) { - IType[] types= null; - try { - types= cu.getAllTypes(); - } catch (JavaScriptModelException ex) { - if (JavaModelUtil.isExceptionToBeLogged(ex)) - ExceptionHandler.log(ex, SearchMessages.JavaElementAction_error_open_message); - if (silent) - return RETURN_WITHOUT_BEEP; - else - return null; - } - if (types.length == 1 || (silent && types.length > 0)) - return types[0]; - if (silent) - return RETURN_WITHOUT_BEEP; - if (types.length == 0) - return null; - String title= SearchMessages.JavaElementAction_typeSelectionDialog_title; - String message = SearchMessages.JavaElementAction_typeSelectionDialog_message; - int flags= (JavaScriptElementLabelProvider.SHOW_DEFAULT); - - ElementListSelectionDialog dialog= new ElementListSelectionDialog(getShell(), new JavaScriptElementLabelProvider(flags)); - dialog.setTitle(title); - dialog.setMessage(message); - dialog.setElements(types); - - if (dialog.open() == Window.OK) - return (IType)dialog.getFirstResult(); - else - return RETURN_WITHOUT_BEEP; - } - - /* - * Method declared on SelectionChangedAction. - */ - public void run(IStructuredSelection selection) { - IJavaScriptElement element= getJavaElement(selection, false); - if (element == null || !element.exists()) { - showOperationUnavailableDialog(); - return; - } - else if (element == RETURN_WITHOUT_BEEP) - return; - - run(element); - } - - /* - * Method declared on SelectionChangedAction. - */ - public void run(ITextSelection selection) { - if (!ActionUtil.isProcessable(fEditor)) - return; - try { - String title= SearchMessages.SearchElementSelectionDialog_title; - String message= SearchMessages.SearchElementSelectionDialog_message; - - IJavaScriptElement[] elements= SelectionConverter.codeResolveForked(fEditor, true); - if (elements.length > 0 && canOperateOn(elements[0])) { - IJavaScriptElement element= elements[0]; - if (elements.length > 1) - element= SelectionConverter.selectJavaElement(elements, getShell(), title, message); - if (element != null) - run(element); - } - else - showOperationUnavailableDialog(); - } catch (InvocationTargetException ex) { - String title= SearchMessages.Search_Error_search_title; - String message= SearchMessages.Search_Error_codeResolve; - ExceptionHandler.handle(ex, getShell(), title, message); - } catch (InterruptedException e) { - // ignore - } - } - - /* - * Method declared on SelectionChangedAction. - */ - public void selectionChanged(IStructuredSelection selection) { - setEnabled(canOperateOn(selection)); - } - - /* - * Method declared on SelectionChangedAction. - */ - public void selectionChanged(ITextSelection selection) { - } - - /** - * Executes this action for the given JavaScript element. - * @param element The JavaScript element to be found. - */ - public void run(IJavaScriptElement element) { - - if (!ActionUtil.isProcessable(getShell(), element)) - return; - - // will return true except for debugging purposes. - try { - performNewSearch(element); - } catch (JavaScriptModelException ex) { - ExceptionHandler.handle(ex, getShell(), SearchMessages.Search_Error_search_notsuccessful_title, SearchMessages.Search_Error_search_notsuccessful_message); - } catch (InterruptedException e) { - // cancelled - } - } - - private void performNewSearch(IJavaScriptElement element) throws JavaScriptModelException, InterruptedException { - JavaSearchQuery query= new JavaSearchQuery(createQuery(element)); - if (query.canRunInBackground()) { - /* - * This indirection with Object as parameter is needed to prevent the loading - * of the Search plug-in: the VM verifies the method call and hence loads the - * types used in the method signature, eventually triggering the loading of - * a plug-in (in this case ISearchQuery results in Search plug-in being loaded). - */ - SearchUtil.runQueryInBackground(query); - } else { - IProgressService progressService= PlatformUI.getWorkbench().getProgressService(); - /* - * This indirection with Object as parameter is needed to prevent the loading - * of the Search plug-in: the VM verifies the method call and hence loads the - * types used in the method signature, eventually triggering the loading of - * a plug-in (in this case it would be ISearchQuery). - */ - IStatus status= SearchUtil.runQueryInForeground(progressService, query); - if (status.matches(IStatus.ERROR | IStatus.INFO | IStatus.WARNING)) { - ErrorDialog.openError(getShell(), SearchMessages.Search_Error_search_title, SearchMessages.Search_Error_search_message, status); - } - } - } - - QuerySpecification createQuery(IJavaScriptElement element) throws JavaScriptModelException, InterruptedException { - JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance(); - IJavaScriptSearchScope scope= factory.createWorkspaceScope(true); - String description= factory.getWorkspaceScopeDescription(true); - return new ElementQuerySpecification(element, getLimitTo(), scope, description); - } - - abstract int getLimitTo(); - - IType getType(IJavaScriptElement element) { - if (element == null) - return null; - - IType type= null; - if (element.getElementType() == IJavaScriptElement.TYPE) - type= (IType)element; - else if (element instanceof IMember) - type= ((IMember)element).getDeclaringType(); - else if (element instanceof ILocalVariable) { - type= (IType)element.getAncestor(IJavaScriptElement.TYPE); - } - return type; - } - - JavaEditor getEditor() { - return fEditor; - } - -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindDeclarationsAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindDeclarationsAction.java deleted file mode 100644 index 606c85fa..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindDeclarationsAction.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IField; -import org.eclipse.wst.jsdt.core.IFunction; -import org.eclipse.wst.jsdt.core.IImportDeclaration; -import org.eclipse.wst.jsdt.core.IJavaScriptUnit; -import org.eclipse.wst.jsdt.core.ILocalVariable; -import org.eclipse.wst.jsdt.core.IPackageFragment; -import org.eclipse.wst.jsdt.core.IType; -import org.eclipse.wst.jsdt.core.search.IJavaScriptSearchConstants; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaPluginImages; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.search.SearchMessages; - -/** - * Finds declarations of the selected element in the workspace. - * The action is applicable to selections representing a JavaScript element. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class FindDeclarationsAction extends FindAction { - - /** - * Creates a new <code>FindDeclarationsAction</code>. The action requires - * that the selection provided by the site's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public FindDeclarationsAction(IWorkbenchSite site) { - super(site); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public FindDeclarationsAction(JavaEditor editor) { - super(editor); - } - - void init() { - setText(SearchMessages.Search_FindDeclarationAction_label); - setToolTipText(SearchMessages.Search_FindDeclarationAction_tooltip); - setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_DECL); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_DECLARATIONS_IN_WORKSPACE_ACTION); - } - - Class[] getValidTypes() { - return new Class[] { IField.class, IFunction.class, IType.class, IJavaScriptUnit.class, IImportDeclaration.class, IPackageFragment.class, ILocalVariable.class }; - } - - int getLimitTo() { - return IJavaScriptSearchConstants.DECLARATIONS | IJavaScriptSearchConstants.IGNORE_DECLARING_TYPE | IJavaScriptSearchConstants.IGNORE_RETURN_TYPE; - } - -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindDeclarationsInHierarchyAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindDeclarationsInHierarchyAction.java deleted file mode 100644 index 02fc9776..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindDeclarationsInHierarchyAction.java +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IField; -import org.eclipse.wst.jsdt.core.IFunction; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.ILocalVariable; -import org.eclipse.wst.jsdt.core.IType; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.core.search.IJavaScriptSearchScope; -import org.eclipse.wst.jsdt.core.search.SearchEngine; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaPluginImages; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.search.JavaSearchScopeFactory; -import org.eclipse.wst.jsdt.internal.ui.search.SearchMessages; -import org.eclipse.wst.jsdt.ui.search.ElementQuerySpecification; -import org.eclipse.wst.jsdt.ui.search.QuerySpecification; - -/** - * Finds declarations of the selected element in its hierarchy. - * The action is applicable to selections representing a JavaScript element. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class FindDeclarationsInHierarchyAction extends FindDeclarationsAction { - - /** - * Creates a new <code>FindDeclarationsInHierarchyAction</code>. The action - * requires that the selection provided by the site's selection provider is of type - * <code>IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public FindDeclarationsInHierarchyAction(IWorkbenchSite site) { - super(site); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public FindDeclarationsInHierarchyAction(JavaEditor editor) { - super(editor); - } - - Class[] getValidTypes() { - return new Class[] { IField.class, IFunction.class, ILocalVariable.class}; - } - - void init() { - setText(SearchMessages.Search_FindHierarchyDeclarationsAction_label); - setToolTipText(SearchMessages.Search_FindHierarchyDeclarationsAction_tooltip); - setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_DECL); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_DECLARATIONS_IN_HIERARCHY_ACTION); - } - - QuerySpecification createQuery(IJavaScriptElement element) throws JavaScriptModelException, InterruptedException { - JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance(); - - IType type= getType(element); - if (type == null) { - return super.createQuery(element); - } - IJavaScriptSearchScope scope= SearchEngine.createHierarchyScope(type); - String description= factory.getHierarchyScopeDescription(type); - return new ElementQuerySpecification(element, getLimitTo(), scope, description); - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindDeclarationsInProjectAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindDeclarationsInProjectAction.java deleted file mode 100644 index 2acb5fe2..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindDeclarationsInProjectAction.java +++ /dev/null @@ -1,85 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.core.search.IJavaScriptSearchScope; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaPluginImages; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.search.JavaSearchScopeFactory; -import org.eclipse.wst.jsdt.internal.ui.search.SearchMessages; -import org.eclipse.wst.jsdt.ui.search.ElementQuerySpecification; -import org.eclipse.wst.jsdt.ui.search.QuerySpecification; - -/** - * Finds declarations of the selected element in the enclosing project - * of the selected element. - * The action is applicable to selections representing a JavaScript element. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class FindDeclarationsInProjectAction extends FindDeclarationsAction { - - /** - * Creates a new <code>FindDeclarationsInProjectAction</code>. The action - * requires that the selection provided by the site's selection provider is of type - * <code>IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public FindDeclarationsInProjectAction(IWorkbenchSite site) { - super(site); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public FindDeclarationsInProjectAction(JavaEditor editor) { - super(editor); - } - - void init() { - setText(SearchMessages.Search_FindDeclarationsInProjectAction_label); - setToolTipText(SearchMessages.Search_FindDeclarationsInProjectAction_tooltip); - setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_DECL); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_DECLARATIONS_IN_PROJECT_ACTION); - } - - QuerySpecification createQuery(IJavaScriptElement element) throws JavaScriptModelException { - JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance(); - JavaEditor editor= getEditor(); - - IJavaScriptSearchScope scope; - String description; - boolean isInsideJRE= true; - if (editor != null) { - scope= factory.createJavaProjectSearchScope(editor.getEditorInput(), isInsideJRE); - description= factory.getProjectScopeDescription(editor.getEditorInput(), isInsideJRE); - } else { - scope= factory.createJavaProjectSearchScope(element.getJavaScriptProject(), isInsideJRE); - description= factory.getProjectScopeDescription(element.getJavaScriptProject(), isInsideJRE); - } - return new ElementQuerySpecification(element, getLimitTo(), scope, description); - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindDeclarationsInWorkingSetAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindDeclarationsInWorkingSetAction.java deleted file mode 100644 index 104336c7..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindDeclarationsInWorkingSetAction.java +++ /dev/null @@ -1,112 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.IWorkingSet; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.core.search.IJavaScriptSearchScope; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaPluginImages; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.search.JavaSearchScopeFactory; -import org.eclipse.wst.jsdt.internal.ui.search.SearchMessages; -import org.eclipse.wst.jsdt.internal.ui.search.SearchUtil; -import org.eclipse.wst.jsdt.ui.search.ElementQuerySpecification; -import org.eclipse.wst.jsdt.ui.search.QuerySpecification; - -/** - * Finds declarations of the selected element in working sets. - * The action is applicable to selections representing a JavaScript element. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class FindDeclarationsInWorkingSetAction extends FindDeclarationsAction { - - private IWorkingSet[] fWorkingSet; - - /** - * Creates a new <code>FindDeclarationsInWorkingSetAction</code>. The action - * requires that the selection provided by the site's selection provider is of type - * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. The user will be - * prompted to select the working sets. - * - * @param site the site providing context information for this action - */ - public FindDeclarationsInWorkingSetAction(IWorkbenchSite site) { - this(site, null); - } - - /** - * Creates a new <code>FindDeclarationsInWorkingSetAction</code>. The action - * requires that the selection provided by the site's selection provider is of type - * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - * @param workingSets the working sets to be used in the search - */ - public FindDeclarationsInWorkingSetAction(IWorkbenchSite site, IWorkingSet[] workingSets) { - super(site); - fWorkingSet= workingSets; - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public FindDeclarationsInWorkingSetAction(JavaEditor editor) { - this(editor, null); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * - * @param editor the JavaScript editor - * @param workingSets the working sets to be used in the search - */ - public FindDeclarationsInWorkingSetAction(JavaEditor editor, IWorkingSet[] workingSets) { - super(editor); - fWorkingSet= workingSets; - } - - void init() { - setText(SearchMessages.Search_FindDeclarationsInWorkingSetAction_label); - setToolTipText(SearchMessages.Search_FindDeclarationsInWorkingSetAction_tooltip); - setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_DECL); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_DECLARATIONS_IN_WORKING_SET_ACTION); - } - - QuerySpecification createQuery(IJavaScriptElement element) throws JavaScriptModelException, InterruptedException { - JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance(); - - IWorkingSet[] workingSets= fWorkingSet; - if (fWorkingSet == null) { - workingSets= factory.queryWorkingSets(); - if (workingSets == null) - return null; - } - SearchUtil.updateLRUWorkingSets(workingSets); - IJavaScriptSearchScope scope= factory.createJavaSearchScope(workingSets, true); - String description= factory.getWorkingSetScopeDescription(workingSets, true); - return new ElementQuerySpecification(element, getLimitTo(), scope, description); - } - -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindExceptionOccurrencesAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindExceptionOccurrencesAction.java deleted file mode 100644 index ef66248d..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindExceptionOccurrencesAction.java +++ /dev/null @@ -1,125 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.texteditor.IEditorStatusLine; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.IMember; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.IClassFileEditorInput; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.search.ExceptionOccurrencesFinder; -import org.eclipse.wst.jsdt.internal.ui.search.FindOccurrencesEngine; - -/** - * Action to find all originators of a exception (e.g. method invocations, - * class casts, ...) for a given exception. - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class FindExceptionOccurrencesAction extends SelectionDispatchAction { - - private JavaEditor fEditor; - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * - * @param editor the JavaScript editor - */ - public FindExceptionOccurrencesAction(JavaEditor editor) { - this(editor.getEditorSite()); - fEditor= editor; - setEnabled(getEditorInput(editor) != null); - } - - /** - * Creates a new <code>FindExceptionOccurrencesAction</code>. The action - * requires that the selection provided by the site's selection provider is of type - * <code>IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public FindExceptionOccurrencesAction(IWorkbenchSite site) { - super(site); - setText(ActionMessages.FindExceptionOccurrences_text); - setToolTipText(ActionMessages.FindExceptionOccurrences_toolTip); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_EXCEPTION_OCCURRENCES); - } - - //---- Text Selection ---------------------------------------------------------------------- - - /** - * {@inheritDoc} - */ - public void selectionChanged(ITextSelection selection) { - } - - /** - * {@inheritDoc} - * - * - */ - public void selectionChanged(IStructuredSelection selection) { - setEnabled(getMember(selection) != null); - } - - /* (non-JavaDoc) - * Method declared in SelectionDispatchAction. - */ - public final void run(ITextSelection ts) { - IJavaScriptElement input= getEditorInput(fEditor); - if (!ActionUtil.isProcessable(getShell(), input)) - return; - FindOccurrencesEngine engine= FindOccurrencesEngine.create(input, new ExceptionOccurrencesFinder()); - try { - String result= engine.run(ts.getOffset(), ts.getLength()); - if (result != null) - showMessage(getShell(), fEditor, result); - } catch (JavaScriptModelException e) { - JavaScriptPlugin.log(e); - } - } - - private static IJavaScriptElement getEditorInput(JavaEditor editor) { - IEditorInput input= editor.getEditorInput(); - if (input instanceof IClassFileEditorInput) - return ((IClassFileEditorInput)input).getClassFile(); - return JavaScriptPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(input); - } - - private static void showMessage(Shell shell, JavaEditor editor, String msg) { - IEditorStatusLine statusLine= (IEditorStatusLine) editor.getAdapter(IEditorStatusLine.class); - if (statusLine != null) - statusLine.setMessage(true, msg, null); - shell.getDisplay().beep(); - } - - private IMember getMember(IStructuredSelection selection) { - return null; - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindImplementOccurrencesAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindImplementOccurrencesAction.java deleted file mode 100644 index 11ad6055..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindImplementOccurrencesAction.java +++ /dev/null @@ -1,124 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.texteditor.IEditorStatusLine; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.IMember; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.IClassFileEditorInput; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.search.FindOccurrencesEngine; -import org.eclipse.wst.jsdt.internal.ui.search.ImplementOccurrencesFinder; - -/** - * Action to find all implement occurrences of an extended class or an implemented interface. - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class FindImplementOccurrencesAction extends SelectionDispatchAction { - - private JavaEditor fEditor; - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * - * @param editor the JavaScript editor - */ - public FindImplementOccurrencesAction(JavaEditor editor) { - this(editor.getEditorSite()); - fEditor= editor; - setEnabled(getEditorInput(editor) != null); - } - - /** - * Creates a new <code>FindImplementOccurrencesAction</code>. The action - * requires that the selection provided by the site's selection provider is of type - * <code>IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public FindImplementOccurrencesAction(IWorkbenchSite site) { - super(site); - setText(ActionMessages.FindImplementOccurrencesAction_text); - setToolTipText(ActionMessages.FindImplementOccurrencesAction_toolTip); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_IMPLEMENT_OCCURRENCES); - } - - //---- Text Selection ---------------------------------------------------------------------- - - /** - * {@inheritDoc} - */ - public void selectionChanged(ITextSelection selection) { - } - - /** - * {@inheritDoc} - * - * - */ - public void selectionChanged(IStructuredSelection selection) { - setEnabled(getMember(selection) != null); - } - - /* - * @see org.eclipse.wst.jsdt.ui.actions.SelectionDispatchAction#run(org.eclipse.jface.text.ITextSelection) - */ - public final void run(ITextSelection ts) { - IJavaScriptElement input= getEditorInput(fEditor); - if (!ActionUtil.isProcessable(getShell(), input)) - return; - FindOccurrencesEngine engine= FindOccurrencesEngine.create(input, new ImplementOccurrencesFinder()); - try { - String result= engine.run(ts.getOffset(), ts.getLength()); - if (result != null) - showMessage(getShell(), fEditor, result); - } catch (JavaScriptModelException e) { - JavaScriptPlugin.log(e); - } - } - - private static IJavaScriptElement getEditorInput(JavaEditor editor) { - IEditorInput input= editor.getEditorInput(); - if (input instanceof IClassFileEditorInput) - return ((IClassFileEditorInput)input).getClassFile(); - return JavaScriptPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(input); - } - - private static void showMessage(Shell shell, JavaEditor editor, String msg) { - IEditorStatusLine statusLine= (IEditorStatusLine) editor.getAdapter(IEditorStatusLine.class); - if (statusLine != null) - statusLine.setMessage(true, msg, null); - shell.getDisplay().beep(); - } - - private IMember getMember(IStructuredSelection selection) { - return null; - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindImplementorsAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindImplementorsAction.java deleted file mode 100644 index 95f747ad..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindImplementorsAction.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.IJavaScriptUnit; -import org.eclipse.wst.jsdt.core.IType; -import org.eclipse.wst.jsdt.core.search.IJavaScriptSearchConstants; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaPluginImages; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.search.SearchMessages; - -/** - * Finds implementors of the selected element in the workspace. - * The action is applicable to selections representing a JavaScript interface. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class FindImplementorsAction extends FindAction { - - /** - * Creates a new <code>FindImplementorsAction</code>. The action - * requires that the selection provided by the site's selection provider is of type - * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public FindImplementorsAction(IWorkbenchSite site) { - super(site); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public FindImplementorsAction(JavaEditor editor) { - super(editor); - } - - void init() { - setText(SearchMessages.Search_FindImplementorsAction_label); - setToolTipText(SearchMessages.Search_FindImplementorsAction_tooltip); - setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_DECL); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_IMPLEMENTORS_IN_WORKSPACE_ACTION); - } - - Class[] getValidTypes() { - return new Class[] { IJavaScriptUnit.class, IType.class}; - } - - boolean canOperateOn(IJavaScriptElement element) { - return false; - } - - int getLimitTo() { - return IJavaScriptSearchConstants.IMPLEMENTORS; - } - - String getOperationUnavailableMessage() { - return SearchMessages.JavaElementAction_operationUnavailable_interface; - } -} - diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindImplementorsInProjectAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindImplementorsInProjectAction.java deleted file mode 100644 index 1b5f1742..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindImplementorsInProjectAction.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.core.search.IJavaScriptSearchScope; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaPluginImages; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.search.JavaSearchScopeFactory; -import org.eclipse.wst.jsdt.internal.ui.search.SearchMessages; -import org.eclipse.wst.jsdt.ui.search.ElementQuerySpecification; -import org.eclipse.wst.jsdt.ui.search.QuerySpecification; - -/** - * Finds implementors of the selected element in the enclosing project. - * The action is applicable to selections representing a JavaScript interface. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class FindImplementorsInProjectAction extends FindImplementorsAction { - - /** - * Creates a new <code>FindImplementorsInProjectAction</code>. The action - * requires that the selection provided by the site's selection provider is of type - * <code>IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public FindImplementorsInProjectAction(IWorkbenchSite site) { - super(site); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public FindImplementorsInProjectAction(JavaEditor editor) { - super(editor); - } - - void init() { - setText(SearchMessages.Search_FindImplementorsInProjectAction_label); - setToolTipText(SearchMessages.Search_FindImplementorsInProjectAction_tooltip); - setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_DECL); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_IMPLEMENTORS_IN_PROJECT_ACTION); - } - - QuerySpecification createQuery(IJavaScriptElement element) throws JavaScriptModelException { - JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance(); - JavaEditor editor= getEditor(); - - IJavaScriptSearchScope scope; - String description; - boolean isInsideJRE= factory.isInsideJRE(element); - if (editor != null) { - scope= factory.createJavaProjectSearchScope(editor.getEditorInput(), isInsideJRE); - description= factory.getProjectScopeDescription(editor.getEditorInput(), isInsideJRE); - } else { - scope= factory.createJavaProjectSearchScope(element.getJavaScriptProject(), isInsideJRE); - description= factory.getProjectScopeDescription(element.getJavaScriptProject(), isInsideJRE); - } - return new ElementQuerySpecification(element, getLimitTo(), scope, description); - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindImplementorsInWorkingSetAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindImplementorsInWorkingSetAction.java deleted file mode 100644 index 307de421..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindImplementorsInWorkingSetAction.java +++ /dev/null @@ -1,112 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.IWorkingSet; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.core.search.IJavaScriptSearchScope; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaPluginImages; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.search.JavaSearchScopeFactory; -import org.eclipse.wst.jsdt.internal.ui.search.SearchMessages; -import org.eclipse.wst.jsdt.internal.ui.search.SearchUtil; -import org.eclipse.wst.jsdt.ui.search.ElementQuerySpecification; -import org.eclipse.wst.jsdt.ui.search.QuerySpecification; - -/** - * Finds implementors of the selected element in working sets. - * The action is applicable to selections representing a JavaScript interface. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class FindImplementorsInWorkingSetAction extends FindImplementorsAction { - - private IWorkingSet[] fWorkingSets; - - /** - * Creates a new <code>FindImplementorsInWorkingSetAction</code>. The action - * requires that the selection provided by the site's selection provider is of type - * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. The user will be - * prompted to select the working sets. - * - * @param site the site providing context information for this action - */ - public FindImplementorsInWorkingSetAction(IWorkbenchSite site) { - super(site); - } - - /** - * Creates a new <code>FindImplementorsInWorkingSetAction</code>. The action - * requires that the selection provided by the site's selection provider is of type - * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - * @param workingSets the working sets to be used in the search - */ - public FindImplementorsInWorkingSetAction(IWorkbenchSite site, IWorkingSet[] workingSets) { - this(site); - fWorkingSets= workingSets; - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public FindImplementorsInWorkingSetAction(JavaEditor editor) { - super(editor); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - * @param workingSets the working sets to be used in the search - */ - public FindImplementorsInWorkingSetAction(JavaEditor editor, IWorkingSet[] workingSets) { - this(editor); - fWorkingSets= workingSets; - } - - void init() { - setText(SearchMessages.Search_FindImplementorsInWorkingSetAction_label); - setToolTipText(SearchMessages.Search_FindImplementorsInWorkingSetAction_tooltip); - setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_DECL); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_IMPLEMENTORS_IN_WORKING_SET_ACTION); - } - - QuerySpecification createQuery(IJavaScriptElement element) throws JavaScriptModelException, InterruptedException { - JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance(); - - IWorkingSet[] workingSets= fWorkingSets; - if (fWorkingSets == null) { - workingSets= factory.queryWorkingSets(); - if (workingSets == null) - return super.createQuery(element); // workspace - } - SearchUtil.updateLRUWorkingSets(workingSets); - IJavaScriptSearchScope scope= factory.createJavaSearchScope(workingSets, true); - String description= factory.getWorkingSetScopeDescription(workingSets, true); - return new ElementQuerySpecification(element, getLimitTo(), scope, description); - } - -} - diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindOccurrencesInFileAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindOccurrencesInFileAction.java deleted file mode 100644 index c645bc2d..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindOccurrencesInFileAction.java +++ /dev/null @@ -1,219 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.jface.action.IStatusLineManager; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IEditorSite; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.IViewSite; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.part.IPageSite; -import org.eclipse.ui.part.Page; -import org.eclipse.ui.texteditor.IEditorStatusLine; -import org.eclipse.wst.jsdt.core.IClassFile; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.IMember; -import org.eclipse.wst.jsdt.core.ISourceRange; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.IClassFileEditorInput; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.search.FindOccurrencesEngine; -import org.eclipse.wst.jsdt.internal.ui.search.OccurrencesFinder; -import org.eclipse.wst.jsdt.internal.ui.search.SearchMessages; - -/** - * Action to find all occurrences of a compilation unit member (e.g. - * fields, methods, types, and local variables) in a file. - * <p> - * Action is applicable to selections containing elements of type - * <tt>IMember</tt>. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class FindOccurrencesInFileAction extends SelectionDispatchAction { - - private JavaEditor fEditor; - private IActionBars fActionBars; - - /** - * Creates a new <code>FindOccurrencesInFileAction</code>. The action requires - * that the selection provided by the view part's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param part the part providing context information for this action - */ - public FindOccurrencesInFileAction(IViewPart part) { - this(part.getSite()); - } - - /** - * Creates a new <code>FindOccurrencesInFileAction</code>. The action requires - * that the selection provided by the page's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param page the page providing context information for this action - */ - public FindOccurrencesInFileAction(Page page) { - this(page.getSite()); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public FindOccurrencesInFileAction(JavaEditor editor) { - this(editor.getEditorSite()); - fEditor= editor; - setEnabled(getEditorInput(editor) != null); - } - - /** - * Creates a new <code>FindOccurrencesInFileAction</code>. The action - * requires that the selection provided by the site's selection provider is of type - * <code>IStructuredSelection</code>. - * - * @param site the site providing context information for this action - * - */ - public FindOccurrencesInFileAction(IWorkbenchSite site) { - super(site); - - if (site instanceof IViewSite) - fActionBars= ((IViewSite)site).getActionBars(); - else if (site instanceof IEditorSite) - fActionBars= ((IEditorSite)site).getActionBars(); - else if (site instanceof IPageSite) - fActionBars= ((IPageSite)site).getActionBars(); - - setText(SearchMessages.Search_FindOccurrencesInFile_label); - setToolTipText(SearchMessages.Search_FindOccurrencesInFile_tooltip); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_OCCURRENCES_IN_FILE_ACTION); - } - - //---- Structured Selection ------------------------------------------------------------- - - /* (non-JavaDoc) - * Method declared in SelectionDispatchAction. - */ - public void selectionChanged(IStructuredSelection selection) { - setEnabled(getMember(selection) != null); - } - - /* (non-JavaDoc) - * Method declared in SelectionDispatchAction. - */ - private IMember getMember(IStructuredSelection selection) { - if (selection.size() != 1) - return null; - Object o= selection.getFirstElement(); - if (o instanceof IMember) { - IMember member= (IMember)o; - try { - if (member.getNameRange() == null) - return null; - } catch (JavaScriptModelException ex) { - return null; - } - - IClassFile file= member.getClassFile(); - if (file != null) { - try { - if (file.getSourceRange() != null) - return member; - } catch (JavaScriptModelException e) { - return null; - } - } - return member; - } - return null; - } - - public void run(IStructuredSelection selection) { - IMember member= getMember(selection); - if (!ActionUtil.isProcessable(getShell(), member)) - return; - FindOccurrencesEngine engine= FindOccurrencesEngine.create(member, new OccurrencesFinder()); - try { - ISourceRange range= member.getNameRange(); - String result= engine.run(range.getOffset(), range.getLength()); - if (result != null) - showMessage(getShell(), fActionBars, result); - } catch (JavaScriptModelException e) { - JavaScriptPlugin.log(e); - } - } - - private static void showMessage(Shell shell, IActionBars actionBars, String msg) { - if (actionBars != null) { - IStatusLineManager statusLine= actionBars.getStatusLineManager(); - if (statusLine != null) - statusLine.setMessage(msg); - } - shell.getDisplay().beep(); - } - - //---- Text Selection ---------------------------------------------------------------------- - - /* (non-JavaDoc) - * Method declared in SelectionDispatchAction. - */ - public void selectionChanged(ITextSelection selection) { - } - - /* (non-JavaDoc) - * Method declared in SelectionDispatchAction. - */ - public final void run(ITextSelection ts) { - IJavaScriptElement input= getEditorInput(fEditor); - if (!ActionUtil.isProcessable(getShell(), input)) - return; - FindOccurrencesEngine engine= FindOccurrencesEngine.create(input, new OccurrencesFinder()); - try { - String result= engine.run(ts.getOffset(), ts.getLength()); - if (result != null) - showMessage(getShell(), fEditor, result); - } catch (JavaScriptModelException e) { - JavaScriptPlugin.log(e); - } - } - - private static IJavaScriptElement getEditorInput(JavaEditor editor) { - IEditorInput input= editor.getEditorInput(); - if (input instanceof IClassFileEditorInput) - return ((IClassFileEditorInput)input).getClassFile(); - return JavaScriptPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(input); - } - - private static void showMessage(Shell shell, JavaEditor editor, String msg) { - IEditorStatusLine statusLine= (IEditorStatusLine) editor.getAdapter(IEditorStatusLine.class); - if (statusLine != null) - statusLine.setMessage(true, msg, null); - shell.getDisplay().beep(); - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindReadReferencesAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindReadReferencesAction.java deleted file mode 100644 index f477e5be..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindReadReferencesAction.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IField; -import org.eclipse.wst.jsdt.core.ILocalVariable; -import org.eclipse.wst.jsdt.core.search.IJavaScriptSearchConstants; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaPluginImages; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.search.SearchMessages; - -/** - * Finds field read accesses of the selected element in the workspace. - * The action is applicable to selections representing a JavaScript interface field. - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class FindReadReferencesAction extends FindReferencesAction { - - /** - * Creates a new <code>FindReadReferencesAction</code>. The action - * requires that the selection provided by the site's selection provider is of type - * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public FindReadReferencesAction(IWorkbenchSite site) { - super(site); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public FindReadReferencesAction(JavaEditor editor) { - super(editor); - } - - Class[] getValidTypes() { - return new Class[] { IField.class, ILocalVariable.class }; - } - - void init() { - setText(SearchMessages.Search_FindReadReferencesAction_label); - setToolTipText(SearchMessages.Search_FindReadReferencesAction_tooltip); - setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_REF); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_READ_REFERENCES_IN_WORKSPACE_ACTION); - } - - int getLimitTo() { - return IJavaScriptSearchConstants.READ_ACCESSES; - } - - String getOperationUnavailableMessage() { - return SearchMessages.JavaElementAction_operationUnavailable_field; - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindReadReferencesInHierarchyAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindReadReferencesInHierarchyAction.java deleted file mode 100644 index 47ec220e..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindReadReferencesInHierarchyAction.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IField; -import org.eclipse.wst.jsdt.core.ILocalVariable; -import org.eclipse.wst.jsdt.core.search.IJavaScriptSearchConstants; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaPluginImages; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.search.SearchMessages; - -/** - * Finds field read accesses of the selected element in its hierarchy. - * The action is applicable to selections representing a JavaScript field. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class FindReadReferencesInHierarchyAction extends FindReferencesInHierarchyAction { - - /** - * Creates a new <code>FindReadReferencesInHierarchyAction</code>. The action - * requires that the selection provided by the site's selection provider is of type - * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public FindReadReferencesInHierarchyAction(IWorkbenchSite site) { - super(site); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public FindReadReferencesInHierarchyAction(JavaEditor editor) { - super(editor); - } - - Class[] getValidTypes() { - return new Class[] { IField.class, ILocalVariable.class }; - } - - void init() { - setText(SearchMessages.Search_FindReadReferencesInHierarchyAction_label); - setToolTipText(SearchMessages.Search_FindReadReferencesInHierarchyAction_tooltip); - setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_REF); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_READ_REFERENCES_IN_HIERARCHY_ACTION); - } - - int getLimitTo() { - return IJavaScriptSearchConstants.READ_ACCESSES; - } - - String getOperationUnavailableMessage() { - return SearchMessages.JavaElementAction_operationUnavailable_field; - } -} - diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindReadReferencesInProjectAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindReadReferencesInProjectAction.java deleted file mode 100644 index 716d2e60..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindReadReferencesInProjectAction.java +++ /dev/null @@ -1,85 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.core.search.IJavaScriptSearchScope; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaPluginImages; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.search.JavaSearchScopeFactory; -import org.eclipse.wst.jsdt.internal.ui.search.SearchMessages; -import org.eclipse.wst.jsdt.ui.search.ElementQuerySpecification; -import org.eclipse.wst.jsdt.ui.search.QuerySpecification; - -/** - * Finds field read accesses of the selected element in the enclosing project. - * The action is applicable to selections representing a JavaScript field. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class FindReadReferencesInProjectAction extends FindReadReferencesAction { - - /** - * Creates a new <code>FindReadReferencesInProjectAction</code>. The action - * requires that the selection provided by the site's selection provider is of type - * <code>IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public FindReadReferencesInProjectAction(IWorkbenchSite site) { - super(site); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public FindReadReferencesInProjectAction(JavaEditor editor) { - super(editor); - } - - void init() { - setText(SearchMessages.Search_FindReadReferencesInProjectAction_label); - setToolTipText(SearchMessages.Search_FindReadReferencesInProjectAction_tooltip); - setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_REF); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_READ_REFERENCES_IN_PROJECT_ACTION); - } - - QuerySpecification createQuery(IJavaScriptElement element) throws JavaScriptModelException { - JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance(); - JavaEditor editor= getEditor(); - - IJavaScriptSearchScope scope; - String description; - boolean isInsideJRE= factory.isInsideJRE(element); - if (editor != null) { - scope= factory.createJavaProjectSearchScope(editor.getEditorInput(), isInsideJRE); - description= factory.getProjectScopeDescription(editor.getEditorInput(), isInsideJRE); - } else { - scope= factory.createJavaProjectSearchScope(element.getJavaScriptProject(), isInsideJRE); - description= factory.getProjectScopeDescription(element.getJavaScriptProject(), isInsideJRE); - } - return new ElementQuerySpecification(element, getLimitTo(), scope, description); - } - -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindReadReferencesInWorkingSetAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindReadReferencesInWorkingSetAction.java deleted file mode 100644 index 2e482daa..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindReadReferencesInWorkingSetAction.java +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.IWorkingSet; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IField; -import org.eclipse.wst.jsdt.core.ILocalVariable; -import org.eclipse.wst.jsdt.core.search.IJavaScriptSearchConstants; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaPluginImages; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.search.SearchMessages; - -/** - * Finds field read accesses of the selected element in working sets. - * The action is applicable to selections representing a JavaScript field. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class FindReadReferencesInWorkingSetAction extends FindReferencesInWorkingSetAction { - - /** - * Creates a new <code>FindReadReferencesInWorkingSetAction</code>. The action - * requires that the selection provided by the site's selection provider is of type - * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. The user will be - * prompted to select the working sets. - * - * @param site the site providing context information for this action - */ - public FindReadReferencesInWorkingSetAction(IWorkbenchSite site) { - super(site); - } - - /** - * Creates a new <code>FindReadReferencesInWorkingSetAction</code>. The action - * requires that the selection provided by the site's selection provider is of type - * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - * @param workingSets the working sets to be used in the search - */ - public FindReadReferencesInWorkingSetAction(IWorkbenchSite site, IWorkingSet[] workingSets) { - super(site, workingSets); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public FindReadReferencesInWorkingSetAction(JavaEditor editor) { - super(editor); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - * @param workingSets the working sets to be used in the search - */ - public FindReadReferencesInWorkingSetAction(JavaEditor editor, IWorkingSet[] workingSets) { - super(editor, workingSets); - } - - Class[] getValidTypes() { - return new Class[] { IField.class, ILocalVariable.class }; - } - - void init() { - setText(SearchMessages.Search_FindReadReferencesInWorkingSetAction_label); - setToolTipText(SearchMessages.Search_FindReadReferencesInWorkingSetAction_tooltip); - setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_REF); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_READ_REFERENCES_IN_WORKING_SET_ACTION); - } - - int getLimitTo() { - return IJavaScriptSearchConstants.READ_ACCESSES; - } - - String getOperationUnavailableMessage() { - return SearchMessages.JavaElementAction_operationUnavailable_field; - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindReferencesAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindReferencesAction.java deleted file mode 100644 index cdae0884..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindReferencesAction.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IField; -import org.eclipse.wst.jsdt.core.IFunction; -import org.eclipse.wst.jsdt.core.IImportDeclaration; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.IJavaScriptUnit; -import org.eclipse.wst.jsdt.core.ILocalVariable; -import org.eclipse.wst.jsdt.core.IPackageFragment; -import org.eclipse.wst.jsdt.core.IType; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.core.search.IJavaScriptSearchConstants; -import org.eclipse.wst.jsdt.core.search.IJavaScriptSearchScope; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaPluginImages; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.search.JavaSearchScopeFactory; -import org.eclipse.wst.jsdt.internal.ui.search.SearchMessages; -import org.eclipse.wst.jsdt.internal.ui.search.SearchUtil; -import org.eclipse.wst.jsdt.ui.search.ElementQuerySpecification; -import org.eclipse.wst.jsdt.ui.search.QuerySpecification; - -/** - * Finds references of the selected element in the workspace. - * The action is applicable to selections representing a JavaScript element. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class FindReferencesAction extends FindAction { - - /** - * Creates a new <code>FindReferencesAction</code>. The action - * requires that the selection provided by the site's selection provider is of type - * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public FindReferencesAction(IWorkbenchSite site) { - super(site); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public FindReferencesAction(JavaEditor editor) { - super(editor); - } - - Class[] getValidTypes() { - return new Class[] { IJavaScriptUnit.class, IType.class, IFunction.class, IField.class, IImportDeclaration.class, IPackageFragment.class, ILocalVariable.class }; - } - - void init() { - setText(SearchMessages.Search_FindReferencesAction_label); - setToolTipText(SearchMessages.Search_FindReferencesAction_tooltip); - setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_REF); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_REFERENCES_IN_WORKSPACE_ACTION); - } - - int getLimitTo() { - return IJavaScriptSearchConstants.REFERENCES; - } - - QuerySpecification createQuery(IJavaScriptElement element) throws JavaScriptModelException, InterruptedException { - JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance(); - boolean isInsideJRE= factory.isInsideJRE(element); - - IJavaScriptSearchScope scope= factory.createWorkspaceScope(isInsideJRE); - String description= factory.getWorkspaceScopeDescription(isInsideJRE); - return new ElementQuerySpecification(element, getLimitTo(), scope, description); - } - - public void run(IJavaScriptElement element) { - SearchUtil.warnIfBinaryConstant(element, getShell()); - super.run(element); - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindReferencesInHierarchyAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindReferencesInHierarchyAction.java deleted file mode 100644 index abb4285a..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindReferencesInHierarchyAction.java +++ /dev/null @@ -1,89 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IField; -import org.eclipse.wst.jsdt.core.IFunction; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.IJavaScriptUnit; -import org.eclipse.wst.jsdt.core.ILocalVariable; -import org.eclipse.wst.jsdt.core.IType; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.core.search.IJavaScriptSearchScope; -import org.eclipse.wst.jsdt.core.search.SearchEngine; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaPluginImages; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.search.JavaSearchScopeFactory; -import org.eclipse.wst.jsdt.internal.ui.search.SearchMessages; -import org.eclipse.wst.jsdt.ui.search.ElementQuerySpecification; -import org.eclipse.wst.jsdt.ui.search.QuerySpecification; - -/** - * Finds references of the selected element in its hierarchy. - * The action is applicable to selections representing a JavaScript element. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class FindReferencesInHierarchyAction extends FindReferencesAction { - - /** - * Creates a new <code>FindReferencesInHierarchyAction</code>. The action - * requires that the selection provided by the site's selection provider is of type - * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public FindReferencesInHierarchyAction(IWorkbenchSite site) { - super(site); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public FindReferencesInHierarchyAction(JavaEditor editor) { - super(editor); - } - - Class[] getValidTypes() { - return new Class[] { IJavaScriptUnit.class, IType.class, IFunction.class, IField.class, ILocalVariable.class }; - } - - void init() { - setText(SearchMessages.Search_FindHierarchyReferencesAction_label); - setToolTipText(SearchMessages.Search_FindHierarchyReferencesAction_tooltip); - setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_REF); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_REFERENCES_IN_HIERARCHY_ACTION); - } - - QuerySpecification createQuery(IJavaScriptElement element) throws JavaScriptModelException, InterruptedException { - IType type= getType(element); - if (type == null) { - return super.createQuery(element); - } - JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance(); - IJavaScriptSearchScope scope= SearchEngine.createHierarchyScope(type); - String description= factory.getHierarchyScopeDescription(type); - return new ElementQuerySpecification(element, getLimitTo(), scope, description); - } - -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindReferencesInProjectAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindReferencesInProjectAction.java deleted file mode 100644 index e046fdca..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindReferencesInProjectAction.java +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IField; -import org.eclipse.wst.jsdt.core.IFunction; -import org.eclipse.wst.jsdt.core.IImportDeclaration; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.IJavaScriptUnit; -import org.eclipse.wst.jsdt.core.ILocalVariable; -import org.eclipse.wst.jsdt.core.IPackageFragment; -import org.eclipse.wst.jsdt.core.IType; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.core.search.IJavaScriptSearchScope; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaPluginImages; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.search.JavaSearchScopeFactory; -import org.eclipse.wst.jsdt.internal.ui.search.SearchMessages; -import org.eclipse.wst.jsdt.ui.search.ElementQuerySpecification; -import org.eclipse.wst.jsdt.ui.search.QuerySpecification; - -/** - * Finds references to the selected element in the enclosing project - * of the selected element. - * The action is applicable to selections representing a JavaScript element. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class FindReferencesInProjectAction extends FindReferencesAction { - - /** - * Creates a new <code>FindReferencesInProjectAction</code>. The action - * requires that the selection provided by the site's selection provider is of type - * <code>IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public FindReferencesInProjectAction(IWorkbenchSite site) { - super(site); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public FindReferencesInProjectAction(JavaEditor editor) { - super(editor); - } - - Class[] getValidTypes() { - return new Class[] { IField.class, IFunction.class, IType.class, IJavaScriptUnit.class, IImportDeclaration.class, IPackageFragment.class, ILocalVariable.class }; - } - - void init() { - setText(SearchMessages.Search_FindReferencesInProjectAction_label); - setToolTipText(SearchMessages.Search_FindReferencesInProjectAction_tooltip); - setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_REF); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_REFERENCES_IN_PROJECT_ACTION); - } - - QuerySpecification createQuery(IJavaScriptElement element) throws JavaScriptModelException { - JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance(); - JavaEditor editor= getEditor(); - - IJavaScriptSearchScope scope; - String description; - boolean isInsideJRE= factory.isInsideJRE(element); - if (editor != null) { - scope= factory.createJavaProjectSearchScope(editor.getEditorInput(), isInsideJRE); - description= factory.getProjectScopeDescription(editor.getEditorInput(), isInsideJRE); - } else { - scope= factory.createJavaProjectSearchScope(element.getJavaScriptProject(), isInsideJRE); - description= factory.getProjectScopeDescription(element.getJavaScriptProject(), isInsideJRE); - } - return new ElementQuerySpecification(element, getLimitTo(), scope, description); - } - -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindReferencesInWorkingSetAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindReferencesInWorkingSetAction.java deleted file mode 100644 index 895db799..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindReferencesInWorkingSetAction.java +++ /dev/null @@ -1,111 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.IWorkingSet; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.core.search.IJavaScriptSearchScope; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaPluginImages; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.search.JavaSearchScopeFactory; -import org.eclipse.wst.jsdt.internal.ui.search.SearchMessages; -import org.eclipse.wst.jsdt.internal.ui.search.SearchUtil; -import org.eclipse.wst.jsdt.ui.search.ElementQuerySpecification; -import org.eclipse.wst.jsdt.ui.search.QuerySpecification; - - -/** - * Finds references of the selected element in working sets. - * The action is applicable to selections representing a JavaScript element. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class FindReferencesInWorkingSetAction extends FindReferencesAction { - - private IWorkingSet[] fWorkingSets; - - /** - * Creates a new <code>FindReferencesInWorkingSetAction</code>. The action - * requires that the selection provided by the site's selection provider is of type - * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. The user will - * be prompted to select the working sets. - * - * @param site the site providing context information for this action - */ - public FindReferencesInWorkingSetAction(IWorkbenchSite site) { - this(site, null); - } - - /** - * Creates a new <code>FindReferencesInWorkingSetAction</code>. The action - * requires that the selection provided by the site's selection provider is of type - * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - * @param workingSets the working sets to be used in the search - */ - public FindReferencesInWorkingSetAction(IWorkbenchSite site, IWorkingSet[] workingSets) { - super(site); - fWorkingSets= workingSets; - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public FindReferencesInWorkingSetAction(JavaEditor editor) { - this(editor, null); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - * @param workingSets the working sets to be used in the search - */ - public FindReferencesInWorkingSetAction(JavaEditor editor, IWorkingSet[] workingSets) { - super(editor); - fWorkingSets= workingSets; - } - - void init() { - setText(SearchMessages.Search_FindReferencesInWorkingSetAction_label); - setToolTipText(SearchMessages.Search_FindReferencesInWorkingSetAction_tooltip); - setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_REF); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_REFERENCES_IN_WORKING_SET_ACTION); - } - - QuerySpecification createQuery(IJavaScriptElement element) throws JavaScriptModelException, InterruptedException { - JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance(); - - IWorkingSet[] workingSets= fWorkingSets; - if (fWorkingSets == null) { - workingSets= factory.queryWorkingSets(); - if (workingSets == null) - return super.createQuery(element); // in workspace - } - SearchUtil.updateLRUWorkingSets(workingSets); - IJavaScriptSearchScope scope= factory.createJavaSearchScope(workingSets, true); - String description= factory.getWorkingSetScopeDescription(workingSets, true); - return new ElementQuerySpecification(element, getLimitTo(), scope, description); - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindWriteReferencesAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindWriteReferencesAction.java deleted file mode 100644 index ade523b4..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindWriteReferencesAction.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IField; -import org.eclipse.wst.jsdt.core.ILocalVariable; -import org.eclipse.wst.jsdt.core.search.IJavaScriptSearchConstants; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaPluginImages; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.search.SearchMessages; - -/** - * Finds field write accesses of the selected element in the workspace. - * The action is applicable to selections representing a JavaScript element. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class FindWriteReferencesAction extends FindReferencesAction { - - /** - * Creates a new <code>FindWriteReferencesAction</code>. The action - * requires that the selection provided by the site's selection provider is of type - * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public FindWriteReferencesAction(IWorkbenchSite site) { - super(site); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public FindWriteReferencesAction(JavaEditor editor) { - super(editor); - } - - Class[] getValidTypes() { - return new Class[] { IField.class, ILocalVariable.class }; - } - - void init() { - setText(SearchMessages.Search_FindWriteReferencesAction_label); - setToolTipText(SearchMessages.Search_FindWriteReferencesAction_tooltip); - setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_REF); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_WRITE_REFERENCES_IN_WORKSPACE_ACTION); - } - - int getLimitTo() { - return IJavaScriptSearchConstants.WRITE_ACCESSES; - } - - String getOperationUnavailableMessage() { - return SearchMessages.JavaElementAction_operationUnavailable_field; - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindWriteReferencesInHierarchyAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindWriteReferencesInHierarchyAction.java deleted file mode 100644 index b34f7908..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindWriteReferencesInHierarchyAction.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IField; -import org.eclipse.wst.jsdt.core.ILocalVariable; -import org.eclipse.wst.jsdt.core.search.IJavaScriptSearchConstants; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaPluginImages; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.search.SearchMessages; - -/** - * Finds field write accesses of the selected element in its hierarchy. - * The action is applicable to selections representing a JavaScript field. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class FindWriteReferencesInHierarchyAction extends FindReferencesInHierarchyAction { - - /** - * Creates a new <code>FindWriteReferencesInHierarchyAction</code>. The action - * requires that the selection provided by the site's selection provider is of type - * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public FindWriteReferencesInHierarchyAction(IWorkbenchSite site) { - super(site); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public FindWriteReferencesInHierarchyAction(JavaEditor editor) { - super(editor); - } - - Class[] getValidTypes() { - return new Class[] { IField.class, ILocalVariable.class }; - } - - void init() { - setText(SearchMessages.Search_FindWriteReferencesInHierarchyAction_label); - setToolTipText(SearchMessages.Search_FindWriteReferencesInHierarchyAction_tooltip); - setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_REF); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_WRITE_REFERENCES_IN_HIERARCHY_ACTION); - } - - int getLimitTo() { - return IJavaScriptSearchConstants.WRITE_ACCESSES; - } - - String getOperationUnavailableMessage() { - return SearchMessages.JavaElementAction_operationUnavailable_field; - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindWriteReferencesInProjectAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindWriteReferencesInProjectAction.java deleted file mode 100644 index 9c600c61..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindWriteReferencesInProjectAction.java +++ /dev/null @@ -1,85 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.core.search.IJavaScriptSearchScope; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaPluginImages; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.search.JavaSearchScopeFactory; -import org.eclipse.wst.jsdt.internal.ui.search.SearchMessages; -import org.eclipse.wst.jsdt.ui.search.ElementQuerySpecification; -import org.eclipse.wst.jsdt.ui.search.QuerySpecification; - -/** - * Finds field write accesses of the selected element in the enclosing project. - * The action is applicable to selections representing a JavaScript field. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class FindWriteReferencesInProjectAction extends FindWriteReferencesAction { - - /** - * Creates a new <code>FindWriteReferencesInProjectAction</code>. The action - * requires that the selection provided by the site's selection provider is of type - * <code>IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public FindWriteReferencesInProjectAction(IWorkbenchSite site) { - super(site); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public FindWriteReferencesInProjectAction(JavaEditor editor) { - super(editor); - } - - void init() { - setText(SearchMessages.Search_FindWriteReferencesInProjectAction_label); - setToolTipText(SearchMessages.Search_FindWriteReferencesInProjectAction_tooltip); - setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_REF); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_WRITE_REFERENCES_IN_PROJECT_ACTION); - } - - QuerySpecification createQuery(IJavaScriptElement element) throws JavaScriptModelException { - JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance(); - JavaEditor editor= getEditor(); - - IJavaScriptSearchScope scope; - String description; - boolean isInsideJRE= factory.isInsideJRE(element); - if (editor != null) { - scope= factory.createJavaProjectSearchScope(editor.getEditorInput(), isInsideJRE); - description= factory.getProjectScopeDescription(editor.getEditorInput(), isInsideJRE); - } else { - scope= factory.createJavaProjectSearchScope(element.getJavaScriptProject(), isInsideJRE); - description= factory.getProjectScopeDescription(element.getJavaScriptProject(), isInsideJRE); - } - return new ElementQuerySpecification(element, getLimitTo(), scope, description); - } - -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindWriteReferencesInWorkingSetAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindWriteReferencesInWorkingSetAction.java deleted file mode 100644 index 834e1fd4..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FindWriteReferencesInWorkingSetAction.java +++ /dev/null @@ -1,100 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.IWorkingSet; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IField; -import org.eclipse.wst.jsdt.core.ILocalVariable; -import org.eclipse.wst.jsdt.core.search.IJavaScriptSearchConstants; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaPluginImages; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.search.SearchMessages; - -/** - * Finds field write accesses of the selected element in working sets. - * The action is applicable to selections representing a JavaScript field. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class FindWriteReferencesInWorkingSetAction extends FindReferencesInWorkingSetAction { - - /** - * Creates a new <code>FindWriteReferencesInWorkingSetAction</code>. The action - * requires that the selection provided by the site's selection provider is of type - * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. The user will be - * prompted to select the working sets. - * - * @param site the site providing context information for this action - */ - public FindWriteReferencesInWorkingSetAction(IWorkbenchSite site) { - super(site); - } - - /** - * Creates a new <code>FindWriteReferencesInWorkingSetAction</code>. The action - * requires that the selection provided by the site's selection provider is of type - * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - * @param workingSets the working sets to be used in the search - */ - public FindWriteReferencesInWorkingSetAction(IWorkbenchSite site, IWorkingSet[] workingSets) { - super(site, workingSets); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public FindWriteReferencesInWorkingSetAction(JavaEditor editor) { - super(editor); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - * @param workingSets the working sets to be used in the search - */ - public FindWriteReferencesInWorkingSetAction(JavaEditor editor, IWorkingSet[] workingSets) { - super(editor, workingSets); - } - - Class[] getValidTypes() { - return new Class[] { IField.class, ILocalVariable.class }; - } - - void init() { - setText(SearchMessages.Search_FindWriteReferencesInWorkingSetAction_label); - setToolTipText(SearchMessages.Search_FindWriteReferencesInWorkingSetAction_tooltip); - setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_REF); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_WRITE_REFERENCES_IN_WORKING_SET_ACTION); - } - - int getLimitTo() { - return IJavaScriptSearchConstants.WRITE_ACCESSES; - } - - String getOperationUnavailableMessage() { - return SearchMessages.JavaElementAction_operationUnavailable_field; - } -} - diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FormatAllAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FormatAllAction.java deleted file mode 100644 index 7943b3e7..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/FormatAllAction.java +++ /dev/null @@ -1,430 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; - -import org.eclipse.core.filebuffers.FileBuffers; -import org.eclipse.core.filebuffers.ITextFileBuffer; -import org.eclipse.core.filebuffers.ITextFileBufferManager; -import org.eclipse.core.filebuffers.LocationKind; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.text.DocumentRewriteSession; -import org.eclipse.jface.text.DocumentRewriteSessionType; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IDocumentExtension; -import org.eclipse.jface.text.IDocumentExtension4; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.text.formatter.FormattingContextProperties; -import org.eclipse.jface.text.formatter.IFormattingContext; -import org.eclipse.jface.text.formatter.MultiPassContentFormatter; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.window.Window; -import org.eclipse.ui.IObjectActionDelegate; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IJavaScriptUnit; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.IJavaScriptProject; -import org.eclipse.wst.jsdt.core.IPackageFragment; -import org.eclipse.wst.jsdt.core.IPackageFragmentRoot; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.internal.corext.util.JavaModelUtil; -import org.eclipse.wst.jsdt.internal.corext.util.Messages; -import org.eclipse.wst.jsdt.internal.corext.util.Resources; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages; -import org.eclipse.wst.jsdt.internal.ui.actions.WorkbenchRunnableAdapter; -import org.eclipse.wst.jsdt.internal.ui.browsing.LogicalPackage; -import org.eclipse.wst.jsdt.internal.ui.dialogs.OptionalMessageDialog; -import org.eclipse.wst.jsdt.internal.ui.text.comment.CommentFormattingContext; -import org.eclipse.wst.jsdt.internal.ui.text.comment.CommentFormattingStrategy; -import org.eclipse.wst.jsdt.internal.ui.text.java.JavaFormattingStrategy; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; -import org.eclipse.wst.jsdt.ui.JavaScriptUI; -import org.eclipse.wst.jsdt.ui.text.IJavaScriptPartitions; - -/** - * Formats the code of the compilation units contained in the selection. - * <p> - * The action is applicable to selections containing elements of - * type <code>IJavaScriptUnit</code>, <code>IPackage - * </code>, <code>IPackageFragmentRoot/code> and - * <code>IJavaScriptProject</code>. - * </p> - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class FormatAllAction extends SelectionDispatchAction { - - private DocumentRewriteSession fRewriteSession; - - /* (non-Javadoc) - * Class implements IObjectActionDelegate - */ - public static class ObjectDelegate implements IObjectActionDelegate { - private FormatAllAction fAction; - public void setActivePart(IAction action, IWorkbenchPart targetPart) { - fAction= new FormatAllAction(targetPart.getSite()); - } - public void run(IAction action) { - fAction.run(); - } - public void selectionChanged(IAction action, ISelection selection) { - if (fAction == null) - action.setEnabled(false); - } - } - - /** - * Creates a new <code>FormatAllAction</code>. The action requires - * that the selection provided by the site's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public FormatAllAction(IWorkbenchSite site) { - super(site); - setText(ActionMessages.FormatAllAction_label); - setToolTipText(ActionMessages.FormatAllAction_tooltip); - setDescription(ActionMessages.FormatAllAction_description); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FORMAT_ALL); - } - - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void selectionChanged(ITextSelection selection) { - // do nothing - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void selectionChanged(IStructuredSelection selection) { - setEnabled(isEnabled(selection)); - } - - private IJavaScriptUnit[] getCompilationUnits(IStructuredSelection selection) { - HashSet result= new HashSet(); - Object[] selected= selection.toArray(); - for (int i= 0; i < selected.length; i++) { - try { - if (selected[i] instanceof IJavaScriptElement) { - IJavaScriptElement elem= (IJavaScriptElement) selected[i]; - if (elem.exists()) { - - switch (elem.getElementType()) { - case IJavaScriptElement.TYPE: - if (elem.getParent().getElementType() == IJavaScriptElement.JAVASCRIPT_UNIT) { - result.add(elem.getParent()); - } - break; - case IJavaScriptElement.JAVASCRIPT_UNIT: - result.add(elem); - break; - case IJavaScriptElement.PACKAGE_FRAGMENT: - collectCompilationUnits((IPackageFragment) elem, result); - break; - case IJavaScriptElement.PACKAGE_FRAGMENT_ROOT: - collectCompilationUnits((IPackageFragmentRoot) elem, result); - break; - case IJavaScriptElement.JAVASCRIPT_PROJECT: - IPackageFragmentRoot[] roots= ((IJavaScriptProject) elem).getPackageFragmentRoots(); - for (int k= 0; k < roots.length; k++) { - collectCompilationUnits(roots[k], result); - } - break; - } - } - } else if (selected[i] instanceof LogicalPackage) { - IPackageFragment[] packageFragments= ((LogicalPackage)selected[i]).getFragments(); - for (int k= 0; k < packageFragments.length; k++) { - IPackageFragment pack= packageFragments[k]; - if (pack.exists()) { - collectCompilationUnits(pack, result); - } - } - } - } catch (JavaScriptModelException e) { - JavaScriptPlugin.log(e); - } - } - return (IJavaScriptUnit[]) result.toArray(new IJavaScriptUnit[result.size()]); - } - - private void collectCompilationUnits(IPackageFragment pack, Collection result) throws JavaScriptModelException { - result.addAll(Arrays.asList(pack.getJavaScriptUnits())); - } - - private void collectCompilationUnits(IPackageFragmentRoot root, Collection result) throws JavaScriptModelException { - if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { - IJavaScriptElement[] children= root.getChildren(); - for (int i= 0; i < children.length; i++) { - collectCompilationUnits((IPackageFragment) children[i], result); - } - } - } - - private boolean isEnabled(IStructuredSelection selection) { - Object[] selected= selection.toArray(); - for (int i= 0; i < selected.length; i++) { - try { - if (selected[i] instanceof IJavaScriptElement) { - IJavaScriptElement elem= (IJavaScriptElement) selected[i]; - if (elem.exists()) { - switch (elem.getElementType()) { - case IJavaScriptElement.TYPE: - return elem.getParent().getElementType() == IJavaScriptElement.JAVASCRIPT_UNIT; // for browsing perspective - case IJavaScriptElement.JAVASCRIPT_UNIT: - return true; - case IJavaScriptElement.PACKAGE_FRAGMENT: - case IJavaScriptElement.PACKAGE_FRAGMENT_ROOT: - IPackageFragmentRoot root= (IPackageFragmentRoot) elem.getAncestor(IJavaScriptElement.PACKAGE_FRAGMENT_ROOT); - return (root.getKind() == IPackageFragmentRoot.K_SOURCE); - case IJavaScriptElement.JAVASCRIPT_PROJECT: - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=65638 - return true; - } - } - } else if (selected[i] instanceof LogicalPackage) { - return true; - } - } catch (JavaScriptModelException e) { - if (JavaModelUtil.isExceptionToBeLogged(e)) - JavaScriptPlugin.log(e); - } - } - return false; - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void run(ITextSelection selection) { - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void run(IStructuredSelection selection) { - IJavaScriptUnit[] cus= getCompilationUnits(selection); - if (cus.length == 0) { - MessageDialog.openInformation(getShell(), ActionMessages.FormatAllAction_EmptySelection_title, ActionMessages.FormatAllAction_EmptySelection_description); - return; - } - try { - if (cus.length == 1) { - JavaScriptUI.openInEditor(cus[0]); - } else { - int returnCode= OptionalMessageDialog.open("FormatAll", //$NON-NLS-1$ - getShell(), - ActionMessages.FormatAllAction_noundo_title, - null, - ActionMessages.FormatAllAction_noundo_message, - MessageDialog.WARNING, - new String[] {IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL}, - 0); - if (returnCode != OptionalMessageDialog.NOT_SHOWN && returnCode != Window.OK ) - return; - } - } catch (CoreException e) { - ExceptionHandler.handle(e, getShell(), ActionMessages.FormatAllAction_error_title, ActionMessages.FormatAllAction_error_message); - } - runOnMultiple(cus); - } - - private IResource[] getResources(IJavaScriptUnit[] cus) { - IResource[] res= new IResource[cus.length]; - for (int i= 0; i < res.length; i++) { - res[i]= cus[i].getResource(); - } - return res; - } - - /** - * Perform format all on the given compilation units. - * @param cus The compilation units to format. - */ - public void runOnMultiple(final IJavaScriptUnit[] cus) { - try { - final MultiStatus status= new MultiStatus(JavaScriptUI.ID_PLUGIN, IStatus.OK, ActionMessages.FormatAllAction_status_description, null); - - IStatus valEditStatus= Resources.makeCommittable(getResources(cus), getShell()); - if (valEditStatus.matches(IStatus.CANCEL)) { - return; - } - status.merge(valEditStatus); - if (!status.matches(IStatus.ERROR)) { - PlatformUI.getWorkbench().getProgressService().run(true, true, new WorkbenchRunnableAdapter(new IWorkspaceRunnable() { - public void run(IProgressMonitor monitor) { - doRunOnMultiple(cus, status, monitor); - } - })); // workspace lock - } - if (!status.isOK()) { - String title= ActionMessages.FormatAllAction_multi_status_title; - ErrorDialog.openError(getShell(), title, null, status); - } - } catch (InvocationTargetException e) { - ExceptionHandler.handle(e, getShell(), ActionMessages.FormatAllAction_error_title, ActionMessages.FormatAllAction_error_message); - } catch (InterruptedException e) { - // Canceled by user - } - } - - private static Map getFomatterSettings(IJavaScriptProject project) { - return new HashMap(project.getOptions(true)); - } - - private void doFormat(IDocument document, Map options) { - final IFormattingContext context = new CommentFormattingContext(); - try { - context.setProperty(FormattingContextProperties.CONTEXT_PREFERENCES, options); - context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.valueOf(true)); - - final MultiPassContentFormatter formatter= new MultiPassContentFormatter(IJavaScriptPartitions.JAVA_PARTITIONING, IDocument.DEFAULT_CONTENT_TYPE); - - formatter.setMasterStrategy(new JavaFormattingStrategy()); - formatter.setSlaveStrategy(new CommentFormattingStrategy(), IJavaScriptPartitions.JAVA_DOC); - formatter.setSlaveStrategy(new CommentFormattingStrategy(), IJavaScriptPartitions.JAVA_SINGLE_LINE_COMMENT); - formatter.setSlaveStrategy(new CommentFormattingStrategy(), IJavaScriptPartitions.JAVA_MULTI_LINE_COMMENT); - - try { - startSequentialRewriteMode(document); - formatter.format(document, context); - } finally { - stopSequentialRewriteMode(document); - } - } finally { - context.dispose(); - } - } - - private void startSequentialRewriteMode(IDocument document) { - if (document instanceof IDocumentExtension4) { - IDocumentExtension4 extension= (IDocumentExtension4) document; - fRewriteSession= extension.startRewriteSession(DocumentRewriteSessionType.SEQUENTIAL); - } else if (document instanceof IDocumentExtension) { - IDocumentExtension extension= (IDocumentExtension) document; - extension.startSequentialRewrite(false); - } - } - - private void stopSequentialRewriteMode(IDocument document) { - if (document instanceof IDocumentExtension4) { - IDocumentExtension4 extension= (IDocumentExtension4) document; - extension.stopRewriteSession(fRewriteSession); - } else if (document instanceof IDocumentExtension) { - IDocumentExtension extension= (IDocumentExtension)document; - extension.stopSequentialRewrite(); - } - } - - private void doRunOnMultiple(IJavaScriptUnit[] cus, MultiStatus status, IProgressMonitor monitor) throws OperationCanceledException { - if (monitor == null) { - monitor= new NullProgressMonitor(); - } - monitor.setTaskName(ActionMessages.FormatAllAction_operation_description); - - monitor.beginTask("", cus.length * 4); //$NON-NLS-1$ - try { - Map lastOptions= null; - IJavaScriptProject lastProject= null; - - for (int i= 0; i < cus.length; i++) { - IJavaScriptUnit cu= cus[i]; - IPath path= cu.getPath(); - if (lastProject == null || !lastProject.equals(cu.getJavaScriptProject())) { - lastProject= cu.getJavaScriptProject(); - lastOptions= getFomatterSettings(lastProject); - } - if (monitor.isCanceled()) { - throw new OperationCanceledException(); - } - if (cu.getResource().getResourceAttributes().isReadOnly()) { - String message= Messages.format(ActionMessages.FormatAllAction_read_only_skipped, path.toString()); - status.add(new Status(IStatus.WARNING, JavaScriptUI.ID_PLUGIN, IStatus.WARNING, message, null)); - continue; - } - - ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager(); - try { - try { - manager.connect(path, LocationKind.IFILE, new SubProgressMonitor(monitor, 1)); - - monitor.subTask(path.makeRelative().toString()); - ITextFileBuffer fileBuffer= manager.getTextFileBuffer(path, LocationKind.IFILE); - - formatCompilationUnit(fileBuffer, lastOptions); - - if (fileBuffer.isDirty() && !fileBuffer.isShared()) { - fileBuffer.commit(new SubProgressMonitor(monitor, 2), false); - } else { - monitor.worked(2); - } - } finally { - manager.disconnect(path, LocationKind.IFILE, new SubProgressMonitor(monitor, 1)); - } - } catch (CoreException e) { - String message= Messages.format(ActionMessages.FormatAllAction_problem_accessing, new String[] { path.toString(), e.getLocalizedMessage() }); - status.add(new Status(IStatus.WARNING, JavaScriptUI.ID_PLUGIN, IStatus.WARNING, message, e)); - } - } - } finally { - monitor.done(); - } - } - - private void formatCompilationUnit(final ITextFileBuffer fileBuffer, final Map options) { - if (fileBuffer.isShared()) { - getShell().getDisplay().syncExec(new Runnable() { - public void run() { - doFormat(fileBuffer.getDocument(), options); - } - }); - } else { - doFormat(fileBuffer.getDocument(), options); // run in context thread - } - } - -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/GenerateActionGroup.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/GenerateActionGroup.java deleted file mode 100644 index 05d098bd..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/GenerateActionGroup.java +++ /dev/null @@ -1,535 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.jface.commands.ActionHandler; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.actions.ActionGroup; -import org.eclipse.ui.actions.AddBookmarkAction; -import org.eclipse.ui.handlers.IHandlerActivation; -import org.eclipse.ui.handlers.IHandlerService; -import org.eclipse.ui.ide.IDEActionFactory; -import org.eclipse.ui.part.Page; -import org.eclipse.ui.texteditor.IUpdate; -import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds; -import org.eclipse.wst.jsdt.internal.ui.IUIConstants; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages; -import org.eclipse.wst.jsdt.internal.ui.actions.AddTaskAction; -import org.eclipse.wst.jsdt.internal.ui.actions.AllCleanUpsAction; -import org.eclipse.wst.jsdt.internal.ui.actions.FindBrokenNLSKeysAction; -import org.eclipse.wst.jsdt.internal.ui.actions.JDTQuickMenuAction; -import org.eclipse.wst.jsdt.internal.ui.actions.MultiSortMembersAction; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.CompilationUnitEditor; -import org.eclipse.wst.jsdt.ui.IContextMenuConstants; - -/** - * Action group that adds the source and generate actions to a part's context - * menu and installs handlers for the corresponding global menu actions. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class GenerateActionGroup extends ActionGroup { - - /** - * Pop-up menu: id of the source sub menu (value <code>org.eclipse.wst.jsdt.ui.source.menu</code>). - * - * - */ - public static final String MENU_ID= "org.eclipse.wst.jsdt.ui.source.menu"; //$NON-NLS-1$ - - /** - * Pop-up menu: id of the import group of the source sub menu (value - * <code>importGroup</code>). - * - * - */ - public static final String GROUP_IMPORT= "importGroup"; //$NON-NLS-1$ - - /** - * Pop-up menu: id of the generate group of the source sub menu (value - * <code>generateGroup</code>). - * - * - */ - public static final String GROUP_GENERATE= "generateGroup"; //$NON-NLS-1$ - - /** - * Pop-up menu: id of the code group of the source sub menu (value - * <code>codeGroup</code>). - * - * - */ - public static final String GROUP_CODE= "codeGroup"; //$NON-NLS-1$ - - /** - * Pop-up menu: id of the externalize group of the source sub menu (value - * <code>externalizeGroup</code>). - * - * TODO: Make API - */ - private static final String GROUP_EXTERNALIZE= "externalizeGroup"; //$NON-NLS-1$ - - /** - * Pop-up menu: id of the comment group of the source sub menu (value - * <code>commentGroup</code>). - * - * TODO: Make API - */ - private static final String GROUP_COMMENT= "commentGroup"; //$NON-NLS-1$ - - /** - * Pop-up menu: id of the edit group of the source sub menu (value - * <code>editGroup</code>). - * - * TODO: Make API - */ - private static final String GROUP_EDIT= "editGroup"; //$NON-NLS-1$ - - private CompilationUnitEditor fEditor; - private IWorkbenchSite fSite; - private String fGroupName= IContextMenuConstants.GROUP_REORGANIZE; - private List fRegisteredSelectionListeners; - -// private AddImportOnSelectionAction fAddImport; - private OverrideMethodsAction fOverrideMethods; -// private GenerateHashCodeEqualsAction fHashCodeEquals; - private AddGetterSetterAction fAddGetterSetter; - private AddDelegateMethodsAction fAddDelegateMethods; -// private AddUnimplementedConstructorsAction fAddUnimplementedConstructors; - private GenerateNewConstructorUsingFieldsAction fGenerateConstructorUsingFields; - private AddJavaDocStubAction fAddJavaDocStub; - private AddBookmarkAction fAddBookmark; - private AddTaskAction fAddTaskAction; - private ExternalizeStringsAction fExternalizeStrings; - private AllCleanUpsAction fCleanUp; - private FindBrokenNLSKeysAction fFindNLSProblems; - -// private OrganizeImportsAction fOrganizeImports; - private MultiSortMembersAction fSortMembers; - private FormatAllAction fFormatAll; - - private static final String QUICK_MENU_ID= "org.eclipse.wst.jsdt.ui.edit.text.java.source.quickMenu"; //$NON-NLS-1$ - - private class SourceQuickAccessAction extends JDTQuickMenuAction { - public SourceQuickAccessAction(CompilationUnitEditor editor) { - super(editor, QUICK_MENU_ID); - } - protected void fillMenu(IMenuManager menu) { - fillQuickMenu(menu); - } - } - - private JDTQuickMenuAction fQuickAccessAction; - private IHandlerActivation fQuickAccessHandlerActivation; - private IHandlerService fHandlerService; - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the compilation unit editor - * @param groupName the group name to add the action to - */ - public GenerateActionGroup(CompilationUnitEditor editor, String groupName) { - fSite= editor.getSite(); - fEditor= editor; - fGroupName= groupName; - -// fAddImport= new AddImportOnSelectionAction(editor); -// fAddImport.setActionDefinitionId(IJavaEditorActionDefinitionIds.ADD_IMPORT); -// fAddImport.update(); -// editor.setAction("AddImport", fAddImport); //$NON-NLS-1$ -// -// fOrganizeImports= new OrganizeImportsAction(editor); -// fOrganizeImports.setActionDefinitionId(IJavaEditorActionDefinitionIds.ORGANIZE_IMPORTS); -// editor.setAction("OrganizeImports", fOrganizeImports); //$NON-NLS-1$ - - fSortMembers= new MultiSortMembersAction(editor); - fSortMembers.setActionDefinitionId(IJavaEditorActionDefinitionIds.SORT_MEMBERS); - editor.setAction("SortMembers", fSortMembers); //$NON-NLS-1$ - -// IAction pastAction= editor.getAction(ITextEditorActionConstants.PASTE);//IWorkbenchActionDefinitionIds.PASTE); -// fCopyQualifiedNameAction= new CopyQualifiedNameAction(editor, null, pastAction); -// fCopyQualifiedNameAction.setActionDefinitionId(CopyQualifiedNameAction.JAVA_EDITOR_ACTION_DEFINITIONS_ID); -// editor.setAction("CopyQualifiedName", fCopyQualifiedNameAction); //$NON-NLS-1$ - - if (IUIConstants.SUPPORT_REFACTORING) { - fOverrideMethods= new OverrideMethodsAction(editor); - fOverrideMethods.setActionDefinitionId(IJavaEditorActionDefinitionIds.OVERRIDE_METHODS); - editor.setAction("OverrideMethods", fOverrideMethods); //$NON-NLS-1$ - - - fAddGetterSetter= new AddGetterSetterAction(editor); - fAddGetterSetter.setActionDefinitionId(IJavaEditorActionDefinitionIds.CREATE_GETTER_SETTER); - editor.setAction("AddGetterSetter", fAddGetterSetter); //$NON-NLS-1$ - - fAddDelegateMethods= new AddDelegateMethodsAction(editor); - fAddDelegateMethods.setActionDefinitionId(IJavaEditorActionDefinitionIds.CREATE_DELEGATE_METHODS); - editor.setAction("AddDelegateMethods", fAddDelegateMethods); //$NON-NLS-1$ - -// fAddUnimplementedConstructors= new AddUnimplementedConstructorsAction(editor); -// fAddUnimplementedConstructors.setActionDefinitionId(IJavaEditorActionDefinitionIds.ADD_UNIMPLEMENTED_CONTRUCTORS); -// editor.setAction("AddUnimplementedConstructors", fAddUnimplementedConstructors); //$NON-NLS-1$ - - fGenerateConstructorUsingFields= new GenerateNewConstructorUsingFieldsAction(editor); - fGenerateConstructorUsingFields.setActionDefinitionId(IJavaEditorActionDefinitionIds.GENERATE_CONSTRUCTOR_USING_FIELDS); - editor.setAction("GenerateConstructorUsingFields", fGenerateConstructorUsingFields); //$NON-NLS-1$ - } - -// fHashCodeEquals= new GenerateHashCodeEqualsAction(editor); -// fHashCodeEquals.setActionDefinitionId(IJavaEditorActionDefinitionIds.GENERATE_HASHCODE_EQUALS); -// editor.setAction("GenerateHashCodeEquals", fHashCodeEquals); //$NON-NLS-1$ - - fAddJavaDocStub= new AddJavaDocStubAction(editor); - fAddJavaDocStub.setActionDefinitionId(IJavaEditorActionDefinitionIds.ADD_JAVADOC_COMMENT); - editor.setAction("AddJavadocComment", fAddJavaDocStub); //$NON-NLS-1$ - - fCleanUp= new AllCleanUpsAction(editor); - fCleanUp.setActionDefinitionId(IJavaEditorActionDefinitionIds.CLEAN_UP); - editor.setAction("CleanUp", fCleanUp); //$NON-NLS-1$ - - if (IUIConstants.SUPPORT_REFACTORING) { - fExternalizeStrings= new ExternalizeStringsAction(editor); - fExternalizeStrings.setActionDefinitionId(IJavaEditorActionDefinitionIds.EXTERNALIZE_STRINGS); - editor.setAction("ExternalizeStrings", fExternalizeStrings); //$NON-NLS-1$ - } - - installQuickAccessAction(); - } - - /** - * Creates a new <code>GenerateActionGroup</code>. The group - * requires that the selection provided by the page's selection provider - * is of type <code>org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param page the page that owns this action group - */ - public GenerateActionGroup(Page page) { - this(page.getSite()); - } - - /** - * Creates a new <code>GenerateActionGroup</code>. The group - * requires that the selection provided by the part's selection provider - * is of type <code>org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param part the view part that owns this action group - */ - public GenerateActionGroup(IViewPart part) { - this(part.getSite()); - } - - private GenerateActionGroup(IWorkbenchSite site) { - fSite= site; - ISelectionProvider provider= fSite.getSelectionProvider(); - ISelection selection= provider.getSelection(); - - if (IUIConstants.SUPPORT_REFACTORING) { - fOverrideMethods = new OverrideMethodsAction(site); - fOverrideMethods - .setActionDefinitionId(IJavaEditorActionDefinitionIds.OVERRIDE_METHODS); - fAddGetterSetter = new AddGetterSetterAction(site); - fAddGetterSetter - .setActionDefinitionId(IJavaEditorActionDefinitionIds.CREATE_GETTER_SETTER); - fAddDelegateMethods = new AddDelegateMethodsAction(site); - fAddDelegateMethods - .setActionDefinitionId(IJavaEditorActionDefinitionIds.CREATE_DELEGATE_METHODS); - fGenerateConstructorUsingFields = new GenerateNewConstructorUsingFieldsAction( - site); - fGenerateConstructorUsingFields - .setActionDefinitionId(IJavaEditorActionDefinitionIds.GENERATE_CONSTRUCTOR_USING_FIELDS); - } - fAddJavaDocStub= new AddJavaDocStubAction(site); - fAddJavaDocStub.setActionDefinitionId(IJavaEditorActionDefinitionIds.ADD_JAVADOC_COMMENT); - - fAddBookmark= new AddBookmarkAction(site.getShell()); - fAddBookmark.setActionDefinitionId(IWorkbenchActionDefinitionIds.ADD_BOOKMARK); - - // context-menu only -> no action definition ids - - fAddTaskAction= new AddTaskAction(site); - fAddTaskAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.ADD_TASK); - - if (IUIConstants.SUPPORT_REFACTORING) { - fExternalizeStrings = new ExternalizeStringsAction(site); - fExternalizeStrings - .setActionDefinitionId(IJavaEditorActionDefinitionIds.EXTERNALIZE_STRINGS); - fFindNLSProblems = new FindBrokenNLSKeysAction(site); - fFindNLSProblems - .setActionDefinitionId(FindBrokenNLSKeysAction.FIND_BROKEN_NLS_KEYS_ACTION_ID); - } - fSortMembers= new MultiSortMembersAction(site); - fSortMembers.setActionDefinitionId(IJavaEditorActionDefinitionIds.SORT_MEMBERS); - - fFormatAll= new FormatAllAction(site); - fFormatAll.setActionDefinitionId(IJavaEditorActionDefinitionIds.FORMAT); - - fCleanUp= new AllCleanUpsAction(site); - fCleanUp.setActionDefinitionId(IJavaEditorActionDefinitionIds.CLEAN_UP); - - - fAddJavaDocStub.update(selection); - if (IUIConstants.SUPPORT_REFACTORING) { - fOverrideMethods.update(selection); - fAddGetterSetter.update(selection); - fAddDelegateMethods.update(selection); - // fAddUnimplementedConstructors.update(selection); - fGenerateConstructorUsingFields.update(selection); - // fHashCodeEquals.update(selection); - fExternalizeStrings.update(selection); - fFindNLSProblems.update(selection); - } - fCleanUp.update(selection); - fAddTaskAction.update(selection); -// fOrganizeImports.update(selection); - fSortMembers.update(selection); - fFormatAll.update(selection); - if (selection instanceof IStructuredSelection) { - IStructuredSelection ss= (IStructuredSelection)selection; - fAddBookmark.selectionChanged(ss); - } else { - fAddBookmark.setEnabled(false); - } - - if (IUIConstants.SUPPORT_REFACTORING) { - registerSelectionListener(provider, fOverrideMethods); - registerSelectionListener(provider, fAddGetterSetter); - registerSelectionListener(provider, fAddDelegateMethods); - // registerSelectionListener(provider, fAddUnimplementedConstructors); - registerSelectionListener(provider, fGenerateConstructorUsingFields); - registerSelectionListener(provider, fExternalizeStrings); - registerSelectionListener(provider, fFindNLSProblems); - } - // registerSelectionListener(provider, fHashCodeEquals); - registerSelectionListener(provider, fAddJavaDocStub); - registerSelectionListener(provider, fAddBookmark); -// registerSelectionListener(provider, fOrganizeImports); - registerSelectionListener(provider, fFormatAll); - registerSelectionListener(provider, fSortMembers); - registerSelectionListener(provider, fAddTaskAction); - registerSelectionListener(provider, fCleanUp); - - installQuickAccessAction(); - } - - private void installQuickAccessAction() { - fHandlerService= (IHandlerService)fSite.getService(IHandlerService.class); - if (fHandlerService != null) { - fQuickAccessAction= new SourceQuickAccessAction(fEditor); - fQuickAccessHandlerActivation= fHandlerService.activateHandler(fQuickAccessAction.getActionDefinitionId(), new ActionHandler(fQuickAccessAction)); - } - } - - private void registerSelectionListener(ISelectionProvider provider, ISelectionChangedListener listener) { - if (fRegisteredSelectionListeners == null) - fRegisteredSelectionListeners= new ArrayList(20); - provider.addSelectionChangedListener(listener); - fRegisteredSelectionListeners.add(listener); - } - - /* - * The state of the editor owning this action group has changed. - * This method does nothing if the group's owner isn't an - * editor. - */ - /** - * Note: This method is for internal use only. Clients should not call this method. - */ - public void editorStateChanged() { - Assert.isTrue(isEditorOwner()); - } - - /* (non-Javadoc) - * Method declared in ActionGroup - */ - public void fillActionBars(IActionBars actionBar) { - super.fillActionBars(actionBar); - setGlobalActionHandlers(actionBar); - } - - /* (non-Javadoc) - * Method declared in ActionGroup - */ - public void fillContextMenu(IMenuManager menu) { - super.fillContextMenu(menu); - String menuText= ActionMessages.SourceMenu_label; - if (fQuickAccessAction != null) { - menuText= fQuickAccessAction.addShortcut(menuText); - } - IMenuManager subMenu= new MenuManager(menuText, MENU_ID); - int added= 0; - if (isEditorOwner()) { - added= fillEditorSubMenu(subMenu); - } else { - added= fillViewSubMenu(subMenu); - } - if (added > 0) - menu.appendToGroup(fGroupName, subMenu); - } - - private void fillQuickMenu(IMenuManager menu) { - if (isEditorOwner()) { - fillEditorSubMenu(menu); - } else { - fillViewSubMenu(menu); - } - } - - private int fillEditorSubMenu(IMenuManager source) { - int added= 0; - source.add(new Separator(GROUP_COMMENT)); - added+= addEditorAction(source, "ToggleComment"); //$NON-NLS-1$ - added+= addEditorAction(source, "AddBlockComment"); //$NON-NLS-1$ - added+= addEditorAction(source, "RemoveBlockComment"); //$NON-NLS-1$ - added+= addAction(source, fAddJavaDocStub); - source.add(new Separator(GROUP_EDIT)); - added+= addEditorAction(source, "Indent"); //$NON-NLS-1$ - added+= addEditorAction(source, "Format"); //$NON-NLS-1$ - source.add(new Separator(GROUP_IMPORT)); -// added+= addAction(source, fAddImport); -// added+= addAction(source, fOrganizeImports); - added+= addAction(source, fSortMembers); - added+= addAction(source, fCleanUp); - - if (IUIConstants.SUPPORT_REFACTORING) { - source.add(new Separator(GROUP_GENERATE)); - added += addAction(source, fOverrideMethods); - added += addAction(source, fAddGetterSetter); - added += addAction(source, fAddDelegateMethods); - // added+= addAction(source, fHashCodeEquals); - added += addAction(source, fGenerateConstructorUsingFields); - } - // added+= addAction(source, fAddUnimplementedConstructors); - source.add(new Separator(GROUP_CODE)); - source.add(new Separator(GROUP_EXTERNALIZE)); - if (IUIConstants.SUPPORT_REFACTORING) - added+= addAction(source, fExternalizeStrings); - return added; - } - - private int fillViewSubMenu(IMenuManager source) { - int added= 0; - source.add(new Separator(GROUP_COMMENT)); - added+= addAction(source, fAddJavaDocStub); - source.add(new Separator(GROUP_EDIT)); - added+= addAction(source, fFormatAll); - source.add(new Separator(GROUP_IMPORT)); -// added+= addAction(source, fAddImport); -// added+= addAction(source, fOrganizeImports); - added+= addAction(source, fSortMembers); - added+= addAction(source, fCleanUp); - if (IUIConstants.SUPPORT_REFACTORING) { - source.add(new Separator(GROUP_GENERATE)); - added+= addAction(source, fOverrideMethods); - added+= addAction(source, fAddGetterSetter); - added+= addAction(source, fAddDelegateMethods); - // added+= addAction(source, fHashCodeEquals); - added+= addAction(source, fGenerateConstructorUsingFields); - // added+= addAction(source, fAddUnimplementedConstructors); - } - source.add(new Separator(GROUP_CODE)); - source.add(new Separator(GROUP_EXTERNALIZE)); - if (IUIConstants.SUPPORT_REFACTORING) { - added+= addAction(source, fExternalizeStrings); - added+= addAction(source, fFindNLSProblems); - } - return added; - } - - /* (non-Javadoc) - * Method declared in ActionGroup - */ - public void dispose() { - if (fRegisteredSelectionListeners != null) { - ISelectionProvider provider= fSite.getSelectionProvider(); - for (Iterator iter= fRegisteredSelectionListeners.iterator(); iter.hasNext();) { - ISelectionChangedListener listener= (ISelectionChangedListener) iter.next(); - provider.removeSelectionChangedListener(listener); - } - } - if (fQuickAccessHandlerActivation != null && fHandlerService != null) { - fHandlerService.deactivateHandler(fQuickAccessHandlerActivation); - } - fEditor= null; - fCleanUp.dispose(); - super.dispose(); - } - - private void setGlobalActionHandlers(IActionBars actionBar) { -// actionBar.setGlobalActionHandler(JdtActionConstants.ADD_IMPORT, fAddImport); - actionBar.setGlobalActionHandler(JdtActionConstants.OVERRIDE_METHODS, fOverrideMethods); - actionBar.setGlobalActionHandler(JdtActionConstants.GENERATE_GETTER_SETTER, fAddGetterSetter); - actionBar.setGlobalActionHandler(JdtActionConstants.GENERATE_DELEGATE_METHODS, fAddDelegateMethods); -// actionBar.setGlobalActionHandler(JdtActionConstants.ADD_CONSTRUCTOR_FROM_SUPERCLASS, fAddUnimplementedConstructors); - actionBar.setGlobalActionHandler(JdtActionConstants.GENERATE_CONSTRUCTOR_USING_FIELDS, fGenerateConstructorUsingFields); -// actionBar.setGlobalActionHandler(JdtActionConstants.GENERATE_HASHCODE_EQUALS, fHashCodeEquals); - actionBar.setGlobalActionHandler(JdtActionConstants.ADD_JAVA_DOC_COMMENT, fAddJavaDocStub); - actionBar.setGlobalActionHandler(JdtActionConstants.EXTERNALIZE_STRINGS, fExternalizeStrings); - actionBar.setGlobalActionHandler(JdtActionConstants.CLEAN_UP, fCleanUp); - actionBar.setGlobalActionHandler(FindBrokenNLSKeysAction.ACTION_HANDLER_ID, fFindNLSProblems); -// actionBar.setGlobalActionHandler(JdtActionConstants.ORGANIZE_IMPORTS, fOrganizeImports); - actionBar.setGlobalActionHandler(JdtActionConstants.SORT_MEMBERS, fSortMembers); - if (!isEditorOwner()) { - // editor provides its own implementation of these actions. - actionBar.setGlobalActionHandler(IDEActionFactory.BOOKMARK.getId(), fAddBookmark); - actionBar.setGlobalActionHandler(IDEActionFactory.ADD_TASK.getId(), fAddTaskAction); - actionBar.setGlobalActionHandler(JdtActionConstants.FORMAT, fFormatAll); - } - } - - private int addAction(IMenuManager menu, IAction action) { - if (action != null && action.isEnabled()) { - menu.add(action); - return 1; - } - return 0; - } - - private int addEditorAction(IMenuManager menu, String actionID) { - if (fEditor == null) - return 0; - IAction action= fEditor.getAction(actionID); - if (action == null) - return 0; - if (action instanceof IUpdate) - ((IUpdate)action).update(); - if (action.isEnabled()) { - menu.add(action); - return 1; - } - return 0; - } - - private boolean isEditorOwner() { - return fEditor != null; - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/GenerateNewConstructorUsingFieldsAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/GenerateNewConstructorUsingFieldsAction.java deleted file mode 100644 index 13c3e778..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/GenerateNewConstructorUsingFieldsAction.java +++ /dev/null @@ -1,387 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.operation.IRunnableContext; -import org.eclipse.jface.text.IRewriteTarget; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.window.Window; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.Flags; -import org.eclipse.wst.jsdt.core.IField; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.IJavaScriptUnit; -import org.eclipse.wst.jsdt.core.IType; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.core.dom.IFunctionBinding; -import org.eclipse.wst.jsdt.core.dom.ITypeBinding; -import org.eclipse.wst.jsdt.core.dom.IVariableBinding; -import org.eclipse.wst.jsdt.core.dom.JavaScriptUnit; -import org.eclipse.wst.jsdt.internal.corext.codemanipulation.AddCustomConstructorOperation; -import org.eclipse.wst.jsdt.internal.corext.codemanipulation.CodeGenerationSettings; -import org.eclipse.wst.jsdt.internal.corext.codemanipulation.StubUtility2; -import org.eclipse.wst.jsdt.internal.corext.dom.Bindings; -import org.eclipse.wst.jsdt.internal.corext.util.JavaModelUtil; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.GenerateConstructorUsingFieldsContentProvider; -import org.eclipse.wst.jsdt.internal.ui.actions.GenerateConstructorUsingFieldsSelectionDialog; -import org.eclipse.wst.jsdt.internal.ui.actions.GenerateConstructorUsingFieldsValidator; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.actions.WorkbenchRunnableAdapter; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.CompilationUnitEditor; -import org.eclipse.wst.jsdt.internal.ui.preferences.JavaPreferencesSettings; -import org.eclipse.wst.jsdt.internal.ui.util.BusyIndicatorRunnableContext; -import org.eclipse.wst.jsdt.internal.ui.util.ElementValidator; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; -import org.eclipse.wst.jsdt.internal.ui.viewsupport.BindingLabelProvider; -import org.eclipse.wst.jsdt.ui.JavaScriptUI; - -/** - * Creates constructors for a type based on existing fields. - * <p> - * Will open the parent compilation unit in a JavaScript editor. Opens a dialog with a list - * fields from which a constructor will be generated. User is able to check or uncheck - * items before constructors are generated. The result is unsaved, so the user can decide - * if the changes are acceptable. - * <p> - * The action is applicable to structured selections containing elements of type - * <code>IType</code>. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class GenerateNewConstructorUsingFieldsAction extends SelectionDispatchAction { - - private CompilationUnitEditor fEditor; - - /** - * Note: This constructor is for internal use only. Clients should not call this - * constructor. - * - * @param editor the compilation unit editor - */ - public GenerateNewConstructorUsingFieldsAction(CompilationUnitEditor editor) { - this(editor.getEditorSite()); - fEditor= editor; - setEnabled(checkEnabledEditor()); - } - - /** - * Creates a new <code>GenerateConstructorUsingFieldsAction</code>. The action requires - * that the selection provided by the site's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public GenerateNewConstructorUsingFieldsAction(IWorkbenchSite site) { - super(site); - setText(ActionMessages.GenerateConstructorUsingFieldsAction_label); - setDescription(ActionMessages.GenerateConstructorUsingFieldsAction_description); - setToolTipText(ActionMessages.GenerateConstructorUsingFieldsAction_tooltip); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.CREATE_NEW_CONSTRUCTOR_ACTION); - } - - private boolean canEnable(IStructuredSelection selection) throws JavaScriptModelException { - if (getSelectedFields(selection) != null) - return true; - - if ((selection.size() == 1) && (selection.getFirstElement() instanceof IType)) { - IType type= (IType) selection.getFirstElement(); - return type.getJavaScriptUnit() != null; - } - - if ((selection.size() == 1) && (selection.getFirstElement() instanceof IJavaScriptUnit)) - return true; - - return false; - } - - private boolean canRunOn(IField[] fields) throws JavaScriptModelException { - if (fields != null && fields.length > 0) { - return true; - } - return false; - } - - private boolean checkEnabledEditor() { - return fEditor != null && SelectionConverter.canOperateOn(fEditor); - } - - /* - * Returns fields in the selection or <code>null</code> if the selection is empty or - * not valid. - */ - private IField[] getSelectedFields(IStructuredSelection selection) { - List elements= selection.toList(); - if (elements.size() > 0) { - IField[] fields= new IField[elements.size()]; - IJavaScriptUnit unit= null; - for (int index= 0; index < elements.size(); index++) { - if (elements.get(index) instanceof IField) { - IField field= (IField) elements.get(index); - if (index == 0) { - // remember the CU of the first element - unit= field.getJavaScriptUnit(); - if (unit == null) { - return null; - } - } else if (!unit.equals(field.getJavaScriptUnit())) { - // all fields must be in the same CU - return null; - } - - final IType declaringType= field.getDeclaringType(); - if (declaringType==null) - return null; - - fields[index]= field; - } else { - return null; - } - } - return fields; - } - return null; - } - - private IType getSelectedType(IStructuredSelection selection) throws JavaScriptModelException { - Object[] elements= selection.toArray(); - if (elements.length == 1 && (elements[0] instanceof IType)) { - IType type= (IType) elements[0]; - if (type.getJavaScriptUnit() != null) { - return type; - } - } else if (elements[0] instanceof IJavaScriptUnit) { - IJavaScriptUnit unit= (IJavaScriptUnit) elements[0]; - IType type= unit.findPrimaryType(); - if (type != null) - return type; - } else if (elements[0] instanceof IField) { - return ((IField) elements[0]).getJavaScriptUnit().findPrimaryType(); - } - return null; - } - - /* - * (non-Javadoc) Method declared on SelectionDispatchAction - */ - public void run(IStructuredSelection selection) { - try { - IType selectionType= getSelectedType(selection); - if (selectionType == null) { - MessageDialog.openInformation(getShell(), ActionMessages.GenerateConstructorUsingFieldsAction_error_title, ActionMessages.GenerateConstructorUsingFieldsAction_not_applicable); - notifyResult(false); - return; - } - - 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 IJavaScriptUnit) { - run(((IJavaScriptUnit) firstElement).findPrimaryType(), new IField[0], false); - } - } catch (CoreException exception) { - ExceptionHandler.handle(exception, getShell(), ActionMessages.GenerateConstructorUsingFieldsAction_error_title, ActionMessages.GenerateConstructorUsingFieldsAction_error_actionfailed); - } - } - - /* - * (non-Javadoc) Method declared on SelectionDispatchAction - */ - public void run(ITextSelection selection) { - if (!ActionUtil.isProcessable(fEditor)) { - notifyResult(false); - return; - } - try { - IJavaScriptElement[] elements= SelectionConverter.codeResolveForked(fEditor, true); - if (elements.length == 1 && (elements[0] instanceof IField)) { - IField field= (IField) elements[0]; - run(field.getDeclaringType(), new IField[] { field}, false); - return; - } - IJavaScriptElement element= SelectionConverter.getElementAtOffset(fEditor); - if (element != null) { - IType type= (IType) element.getAncestor(IJavaScriptElement.TYPE); - if (type != null) { - if (type.getFields().length > 0) { - run(type, new IField[0], true); - } else { - MessageDialog.openInformation(getShell(), ActionMessages.GenerateConstructorUsingFieldsAction_error_title, ActionMessages.GenerateConstructorUsingFieldsAction_typeContainsNoFields_message); - } - return; - } - } - MessageDialog.openInformation(getShell(), ActionMessages.GenerateConstructorUsingFieldsAction_error_title, ActionMessages.GenerateConstructorUsingFieldsAction_not_applicable); - } catch (CoreException exception) { - ExceptionHandler.handle(exception, getShell(), ActionMessages.GenerateConstructorUsingFieldsAction_error_title, ActionMessages.GenerateConstructorUsingFieldsAction_error_actionfailed); - } catch (InvocationTargetException exception) { - ExceptionHandler.handle(exception, getShell(), ActionMessages.GenerateConstructorUsingFieldsAction_error_title, ActionMessages.GenerateConstructorUsingFieldsAction_error_actionfailed); - } catch (InterruptedException e) { - // cancelled - } - } - - // ---- Helpers ------------------------------------------------------------------- - - void run(IType type, IField[] selected, boolean activated) throws CoreException { - if (!ElementValidator.check(type, getShell(), ActionMessages.GenerateConstructorUsingFieldsAction_error_title, activated)) { - notifyResult(false); - return; - } - if (!ActionUtil.isEditable(fEditor, getShell(), type)) { - notifyResult(false); - return; - } - if (type.getJavaScriptUnit() == null) { - MessageDialog.openInformation(getShell(), ActionMessages.GenerateConstructorUsingFieldsAction_error_title, ActionMessages.GenerateNewConstructorUsingFieldsAction_error_not_a_source_file); - notifyResult(false); - return; - - } - - IField[] candidates= type.getFields(); - ArrayList fields= new ArrayList(); - for (int index= 0; index < candidates.length; index++) { - boolean isStatic= Flags.isStatic(candidates[index].getFlags()); - if (!isStatic) { - fields.add(candidates[index]); - } - } - if (fields.isEmpty()) { - MessageDialog.openInformation(getShell(), ActionMessages.GenerateConstructorUsingFieldsAction_error_title, ActionMessages.GenerateConstructorUsingFieldsAction_typeContainsNoFields_message); - notifyResult(false); - return; - } - final GenerateConstructorUsingFieldsContentProvider provider= new GenerateConstructorUsingFieldsContentProvider(type, fields, Arrays.asList(selected)); - IFunctionBinding[] bindings= null; - final ITypeBinding provided= provider.getType(); - if (provided.isAnonymous()) { - MessageDialog.openInformation(getShell(), ActionMessages.GenerateConstructorUsingFieldsAction_error_title, ActionMessages.GenerateConstructorUsingFieldsAction_error_anonymous_class); - notifyResult(false); - return; - } - - bindings= StubUtility2.getVisibleConstructors(provided, false, true); - if (bindings.length == 0) { - MessageDialog.openInformation(getShell(), ActionMessages.GenerateConstructorUsingFieldsAction_error_title, ActionMessages.GenerateConstructorUsingFieldsAction_error_nothing_found); - notifyResult(false); - return; - } - - GenerateConstructorUsingFieldsSelectionDialog dialog= new GenerateConstructorUsingFieldsSelectionDialog(getShell(), new BindingLabelProvider(), provider, fEditor, type, bindings); - dialog.setCommentString(ActionMessages.SourceActionDialog_createConstructorComment); - dialog.setTitle(ActionMessages.GenerateConstructorUsingFieldsAction_dialog_title); - dialog.setInitialSelections(provider.getInitiallySelectedElements()); - dialog.setContainerMode(true); - dialog.setSize(60, 18); - dialog.setInput(new Object()); - dialog.setMessage(ActionMessages.GenerateConstructorUsingFieldsAction_dialog_label); - dialog.setValidator(new GenerateConstructorUsingFieldsValidator(dialog, provided, fields.size())); - - final int dialogResult= dialog.open(); - if (dialogResult == Window.OK) { - Object[] elements= dialog.getResult(); - if (elements == null) { - notifyResult(false); - return; - } - ArrayList result= new ArrayList(elements.length); - for (int index= 0; index < elements.length; index++) { - if (elements[index] instanceof IVariableBinding) - result.add(elements[index]); - } - IVariableBinding[] variables= new IVariableBinding[result.size()]; - result.toArray(variables); - IEditorPart editor= JavaScriptUI.openInEditor(type.getJavaScriptUnit()); - CodeGenerationSettings settings= JavaPreferencesSettings.getCodeGenerationSettings(type.getJavaScriptProject()); - settings.createComments= dialog.getGenerateComment(); - IFunctionBinding constructor= dialog.getSuperConstructorChoice(); - IRewriteTarget target= editor != null ? (IRewriteTarget) editor.getAdapter(IRewriteTarget.class) : null; - if (target != null) - target.beginCompoundChange(); - try { - AddCustomConstructorOperation operation= new AddCustomConstructorOperation(type, dialog.getElementPosition(), provider.getCompilationUnit(), variables, constructor, settings, true, false); - operation.setVisibility(dialog.getVisibilityModifier()); - if (constructor.getParameterTypes().length == 0) - operation.setOmitSuper(dialog.isOmitSuper()); - IRunnableContext context= JavaScriptPlugin.getActiveWorkbenchWindow(); - if (context == null) - context= new BusyIndicatorRunnableContext(); - PlatformUI.getWorkbench().getProgressService().runInUI(context, new WorkbenchRunnableAdapter(operation, operation.getSchedulingRule()), operation.getSchedulingRule()); - } catch (InvocationTargetException exception) { - ExceptionHandler.handle(exception, getShell(), ActionMessages.GenerateConstructorUsingFieldsAction_error_title, ActionMessages.GenerateConstructorUsingFieldsAction_error_actionfailed); - } catch (InterruptedException exception) { - // Do nothing. Operation has been canceled by user. - } finally { - if (target != null) { - target.endCompoundChange(); - } - } - } - notifyResult(dialogResult == Window.OK); - } - - private IFunctionBinding getObjectConstructor(JavaScriptUnit compilationUnit) { - final ITypeBinding binding= compilationUnit.getAST().resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$ - return Bindings.findMethodInType(binding, "Object", new ITypeBinding[0]); //$NON-NLS-1$ - } - - /* - * (non-Javadoc) Method declared on SelectionDispatchAction - */ - public void selectionChanged(IStructuredSelection selection) { - try { - setEnabled(canEnable(selection)); - } catch (JavaScriptModelException e) { - // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253 - if (JavaModelUtil.isExceptionToBeLogged(e)) - JavaScriptPlugin.log(e); - setEnabled(false); - } - } - - // ---- JavaScript Editor -------------------------------------------------------------- - - /* - * (non-Javadoc) Method declared on SelectionDispatchAction - */ - public void selectionChanged(ITextSelection selection) { - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/IJavaEditorActionDefinitionIds.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/IJavaEditorActionDefinitionIds.java deleted file mode 100644 index 5b60dbab..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/IJavaEditorActionDefinitionIds.java +++ /dev/null @@ -1,635 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; - -/** - * Defines the definition IDs for the JavaScript editor actions. - * - * <p> - * This interface is not intended to be implemented or extended. - * </p>. - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public interface IJavaEditorActionDefinitionIds extends ITextEditorActionDefinitionIds { - - // edit - - /** - * Action definition ID of the edit -> smart typing action - * (value <code>"org.eclipse.wst.jsdt.smartTyping.toggle"</code>). - * - * - */ - public static final String TOGGLE_SMART_TYPING= "org.eclipse.wst.jsdt.smartTyping.toggle"; //$NON-NLS-1$ - - /** - * Action definition ID of the edit -> go to matching bracket action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.goto.matching.bracket"</code>). - * - * - */ - public static final String GOTO_MATCHING_BRACKET= "org.eclipse.wst.jsdt.ui.edit.text.java.goto.matching.bracket"; //$NON-NLS-1$ - - /** - * Action definition ID of the edit -> go to next member action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.goto.next.member"</code>). - * - * - */ - public static final String GOTO_NEXT_MEMBER= "org.eclipse.wst.jsdt.ui.edit.text.java.goto.next.member"; //$NON-NLS-1$ - - /** - * Action definition ID of the edit -> go to previous member action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.goto.previous.member"</code>). - * - * - */ - public static final String GOTO_PREVIOUS_MEMBER= "org.eclipse.wst.jsdt.ui.edit.text.java.goto.previous.member"; //$NON-NLS-1$ - - /** - * Action definition ID of the edit -> select enclosing action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.select.enclosing"</code>). - */ - public static final String SELECT_ENCLOSING= "org.eclipse.wst.jsdt.ui.edit.text.java.select.enclosing"; //$NON-NLS-1$ - - /** - * Action definition ID of the edit -> select next action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.select.next"</code>). - */ - public static final String SELECT_NEXT= "org.eclipse.wst.jsdt.ui.edit.text.java.select.next"; //$NON-NLS-1$ - - /** - * Action definition ID of the edit -> select previous action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.select.previous"</code>). - */ - public static final String SELECT_PREVIOUS= "org.eclipse.wst.jsdt.ui.edit.text.java.select.previous"; //$NON-NLS-1$ - - /** - * Action definition ID of the edit -> select restore last action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.select.last"</code>). - */ - public static final String SELECT_LAST= "org.eclipse.wst.jsdt.ui.edit.text.java.select.last"; //$NON-NLS-1$ - - - - /** - * Action definition ID of the edit -> content assist complete prefix action - * (value: <code>"org.eclipse.wst.jsdt.ui.edit.text.java.complete.prefix"</code>). - * - */ - public static final String CONTENT_ASSIST_COMPLETE_PREFIX= "org.eclipse.wst.jsdt.ui.edit.text.java.complete.prefix"; //$NON-NLS-1$ - - /** - * Action definition ID of the navigate -> Show Outline action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.show.outline"</code>). - * - * - */ - public static final String SHOW_OUTLINE= "org.eclipse.wst.jsdt.ui.edit.text.java.show.outline"; //$NON-NLS-1$ - - /** - * Action definition ID of the navigate -> Show Hierarchy action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.open.hierarchy"</code>). - * - * - */ - public static final String OPEN_HIERARCHY= "org.eclipse.wst.jsdt.ui.edit.text.java.open.hierarchy"; //$NON-NLS-1$ - - - /** - * Action definition ID of the Navigate -> Open Structure action - * (value <code>"org.eclipse.wst.jsdt.ui.navigate.java.open.structure"</code>). - * - * - */ - public static final String OPEN_STRUCTURE= "org.eclipse.wst.jsdt.ui.navigate.java.open.structure"; //$NON-NLS-1$ - - // source - - /** - * Action definition ID of the source -> comment action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.comment"</code>). - */ - public static final String COMMENT= "org.eclipse.wst.jsdt.ui.edit.text.java.comment"; //$NON-NLS-1$ - - /** - * Action definition ID of the source -> uncomment action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.uncomment"</code>). - */ - public static final String UNCOMMENT= "org.eclipse.wst.jsdt.ui.edit.text.java.uncomment"; //$NON-NLS-1$ - - /** - * Action definition ID of the source -> toggle comment action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.toggle.comment"</code>). - * - */ - public static final String TOGGLE_COMMENT= "org.eclipse.wst.jsdt.ui.edit.text.java.toggle.comment"; //$NON-NLS-1$ - - - /** - * Action definition ID of the source -> add block comment action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.add.block.comment"</code>). - * - */ - public static final String ADD_BLOCK_COMMENT= "org.eclipse.wst.jsdt.ui.edit.text.java.add.block.comment"; //$NON-NLS-1$ - - /** - * Action definition ID of the source -> remove block comment action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.remove.block.comment"</code>). - * - */ - public static final String REMOVE_BLOCK_COMMENT= "org.eclipse.wst.jsdt.ui.edit.text.java.remove.block.comment"; //$NON-NLS-1$ - - /** - * Action definition ID of the source -> indent action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.indent"</code>). - */ - public static final String INDENT= "org.eclipse.wst.jsdt.ui.edit.text.java.indent"; //$NON-NLS-1$ - - /** - * Action definition ID of the source -> format action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.format"</code>). - */ - public static final String FORMAT= "org.eclipse.wst.jsdt.ui.edit.text.java.format"; //$NON-NLS-1$ - - /** - * Action definition id of the JavaScript quick format action - * (value: <code>"org.eclipse.wst.jsdt.ui.edit.text.java.quick.format"</code>). - * - */ - public static final String QUICK_FORMAT= "org.eclipse.wst.jsdt.ui.edit.text.java.quick.format"; //$NON-NLS-1$ - - /** - * Action definition ID of the source -> add import action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.add.import"</code>). - */ - public static final String ADD_IMPORT= "org.eclipse.wst.jsdt.ui.edit.text.java.add.import"; //$NON-NLS-1$ - - /** - * Action definition ID of the source -> organize imports action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.organize.imports"</code>). - */ - public static final String ORGANIZE_IMPORTS= "org.eclipse.wst.jsdt.ui.edit.text.java.organize.imports"; //$NON-NLS-1$ - - /** - * Action definition ID of the source -> sort order action (value - * <code>"org.eclipse.wst.jsdt.ui.edit.text.java.sort.members"</code>). - * - */ - public static final String SORT_MEMBERS= "org.eclipse.wst.jsdt.ui.edit.text.java.sort.members"; //$NON-NLS-1$ - - /** - * Action definition ID of the source -> add javadoc comment action (value - * <code>"org.eclipse.wst.jsdt.ui.edit.text.java.add.javadoc.comment"</code>). - * - */ - public static final String ADD_JAVADOC_COMMENT= "org.eclipse.wst.jsdt.ui.edit.text.java.add.javadoc.comment"; //$NON-NLS-1$ - - /** - * Action definition ID of the source -> surround with try/catch action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.surround.with.try.catch"</code>). - */ - public static final String SURROUND_WITH_TRY_CATCH= "org.eclipse.wst.jsdt.ui.edit.text.java.surround.with.try.catch"; //$NON-NLS-1$ - - /** - * Action definition ID of the source -> override methods action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.override.methods"</code>). - */ - public static final String OVERRIDE_METHODS= "org.eclipse.wst.jsdt.ui.edit.text.java.override.methods"; //$NON-NLS-1$ - - /** - * Action definition ID of the source -> add unimplemented constructors action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.add.unimplemented.constructors"</code>). - */ - public static final String ADD_UNIMPLEMENTED_CONTRUCTORS= "org.eclipse.wst.jsdt.ui.edit.text.java.add.unimplemented.constructors"; //$NON-NLS-1$ - - /** - * Action definition ID of the source ->generate constructor using fields action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.generate.constructor.using.fields"</code>). - */ - public static final String GENERATE_CONSTRUCTOR_USING_FIELDS= "org.eclipse.wst.jsdt.ui.edit.text.java.generate.constructor.using.fields"; //$NON-NLS-1$ - - /** - * Action definition ID of the source ->generate hashcode() and equals() action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.generate.hashcode.equals"</code>). - * - */ - public static final String GENERATE_HASHCODE_EQUALS= "org.eclipse.wst.jsdt.ui.edit.text.java.generate.hashcode.equals"; //$NON-NLS-1$ - - /** - * Action definition ID of the source -> generate setter/getter action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.create.getter.setter"</code>). - */ - public static final String CREATE_GETTER_SETTER= "org.eclipse.wst.jsdt.ui.edit.text.java.create.getter.setter"; //$NON-NLS-1$ - - /** - * Action definition ID of the source -> generate delegates action (value - * <code>"org.eclipse.wst.jsdt.ui.edit.text.java.create.delegate.methods"</code>). - * - */ - public static final String CREATE_DELEGATE_METHODS= "org.eclipse.wst.jsdt.ui.edit.text.java.create.delegate.methods"; //$NON-NLS-1$ - - - /** - * Action definition ID of the source -> externalize strings action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.externalize.strings"</code>). - */ - public static final String EXTERNALIZE_STRINGS= "org.eclipse.wst.jsdt.ui.edit.text.java.externalize.strings"; //$NON-NLS-1$ - - /** - * Action definition ID of the refactor -> pull up action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.pull.up"</code>). - */ - public static final String PULL_UP= "org.eclipse.wst.jsdt.ui.edit.text.java.pull.up"; //$NON-NLS-1$ - - /** - * Action definition ID of the refactor -> push down action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.push.down"</code>). - * - * - */ - public static final String PUSH_DOWN= "org.eclipse.wst.jsdt.ui.edit.text.java.push.down"; //$NON-NLS-1$ - - /** - * Action definition ID of the refactor -> rename element action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.rename.element"</code>). - */ - public static final String RENAME_ELEMENT= "org.eclipse.wst.jsdt.ui.edit.text.java.rename.element"; //$NON-NLS-1$ - - /** - * Action definition ID of the refactor -> modify method parameters action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.modify.method.parameters"</code>). - */ - public static final String MODIFY_METHOD_PARAMETERS= "org.eclipse.wst.jsdt.ui.edit.text.java.modify.method.parameters"; //$NON-NLS-1$ - - /** - * Action definition ID of the refactor -> move element action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.move.element"</code>). - */ - public static final String MOVE_ELEMENT= "org.eclipse.wst.jsdt.ui.edit.text.java.move.element"; //$NON-NLS-1$ - - /** - * Action definition ID of the refactor -> extract local variable action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.extract.local.variable"</code>). - */ - public static final String EXTRACT_LOCAL_VARIABLE= "org.eclipse.wst.jsdt.ui.edit.text.java.extract.local.variable"; //$NON-NLS-1$ - - /** - * Action definition ID of the refactor -> extract constant action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.extract.constant"</code>). - * - * - */ - public static final String EXTRACT_CONSTANT= "org.eclipse.wst.jsdt.ui.edit.text.java.extract.constant"; //$NON-NLS-1$ - - /** - * Action definition ID of the refactor -> introduce parameter action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.introduce.parameter"</code>). - * - * - */ - public static final String INTRODUCE_PARAMETER= "org.eclipse.wst.jsdt.ui.edit.text.java.introduce.parameter"; //$NON-NLS-1$ - - /** - * Action definition ID of the refactor -> introduce factory action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.introduce.factory"</code>). - * - * - */ - public static final String INTRODUCE_FACTORY= "org.eclipse.wst.jsdt.ui.edit.text.java.introduce.factory"; //$NON-NLS-1$ - - /** - * Action definition ID of the refactor -> self encapsulate field action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.self.encapsulate.field"</code>). - */ - public static final String SELF_ENCAPSULATE_FIELD= "org.eclipse.wst.jsdt.ui.edit.text.java.self.encapsulate.field"; //$NON-NLS-1$ - - /** - * Action definition ID of the refactor -> extract method action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.extract.method"</code>). - */ - public static final String EXTRACT_METHOD= "org.eclipse.wst.jsdt.ui.edit.text.java.extract.method"; //$NON-NLS-1$ - - /** - * Action definition ID of the refactor -> inline action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.inline"</code>). - * - * - */ - public static final String INLINE= "org.eclipse.wst.jsdt.ui.edit.text.java.inline"; //$NON-NLS-1$ - - /** - * Action definition ID of the refactor -> replace invocations action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.replace.invocations"</code>). - * - * - */ - public static final String REPLACE_INVOCATIONS= "org.eclipse.wst.jsdt.ui.edit.text.java.replace.invocations"; //$NON-NLS-1$ - - /** - * Action definition ID of the refactor -> introduce indirection action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.create.indirection"</code>). - * - * - */ - public static final String INTRODUCE_INDIRECTION= "org.eclipse.wst.jsdt.ui.edit.text.java.introduce.indirection"; //$NON-NLS-1$ - - /** - * Action definition ID of the refactor -> extract interface action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.extract.interface"</code>). - * - * - */ - public static final String EXTRACT_INTERFACE= "org.eclipse.wst.jsdt.ui.edit.text.java.extract.interface"; //$NON-NLS-1$ - - /** - * Action definition ID of the refactor -> change type action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.change.type"</code>). - * - * - */ - public static final String CHANGE_TYPE= "org.eclipse.wst.jsdt.ui.edit.text.java.change.type"; //$NON-NLS-1$ - - /** - * Action definition ID of the refactor -> move inner type to top level action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.move.inner.to.top.level"</code>). - * - * - */ - public static final String MOVE_INNER_TO_TOP= "org.eclipse.wst.jsdt.ui.edit.text.java.move.inner.to.top.level"; //$NON-NLS-1$ - - /** - * Action definition ID of the refactor -> use supertype action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.use.supertype"</code>). - * - * - */ - public static final String USE_SUPERTYPE= "org.eclipse.wst.jsdt.ui.edit.text.java.use.supertype"; //$NON-NLS-1$ - - /** - * Action definition ID of the refactor -> infer generic type arguments action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.infer.type.arguments"</code>). - * - * - */ - public static final String INFER_TYPE_ARGUMENTS_ACTION= "org.eclipse.wst.jsdt.ui.edit.text.java.infer.type.arguments"; //$NON-NLS-1$ - - /** - * Action definition ID of the refactor -> promote local variable action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.promote.local.variable"</code>). - * - * - */ - public static final String PROMOTE_LOCAL_VARIABLE= "org.eclipse.wst.jsdt.ui.edit.text.java.promote.local.variable"; //$NON-NLS-1$ - - /** - * Action definition ID of the refactor -> convert anonymous to nested action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.convert.anonymous.to.nested"</code>). - * - * - */ - public static final String CONVERT_ANONYMOUS_TO_NESTED= "org.eclipse.wst.jsdt.ui.edit.text.java.convert.anonymous.to.nested"; //$NON-NLS-1$ - - // navigate - - /** - * Action definition ID of the navigate -> open action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.open.editor"</code>). - */ - public static final String OPEN_EDITOR= "org.eclipse.wst.jsdt.ui.edit.text.java.open.editor"; //$NON-NLS-1$ - - /** - * Action definition ID of the navigate -> open super implementation action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.open.super.implementation"</code>). - */ - public static final String OPEN_SUPER_IMPLEMENTATION= "org.eclipse.wst.jsdt.ui.edit.text.java.open.super.implementation"; //$NON-NLS-1$ - - /** - * Action definition ID of the navigate -> open external javadoc action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.open.external.javadoc"</code>). - */ - public static final String OPEN_EXTERNAL_JAVADOC= "org.eclipse.wst.jsdt.ui.edit.text.java.open.external.javadoc"; //$NON-NLS-1$ - - /** - * Action definition ID of the navigate -> open type hierarchy action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.org.eclipse.wst.jsdt.ui.edit.text.java.open.type.hierarchy"</code>). - */ - public static final String OPEN_TYPE_HIERARCHY= "org.eclipse.wst.jsdt.ui.edit.text.java.open.type.hierarchy"; //$NON-NLS-1$ - - /** - * Action definition ID of the navigate -> open call hierarchy action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.org.eclipse.wst.jsdt.ui.edit.text.java.open.call.hierarchy"</code>). - * - */ - public static final String OPEN_CALL_HIERARCHY= "org.eclipse.wst.jsdt.ui.edit.text.java.open.call.hierarchy"; //$NON-NLS-1$ - - /** - * Action definition ID of the navigate -> show in package explorer action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.show.in.package.view"</code>). - */ - public static final String SHOW_IN_PACKAGE_VIEW= "org.eclipse.wst.jsdt.ui.edit.text.java.show.in.package.view"; //$NON-NLS-1$ - - /** - * Action definition ID of the navigate -> show in navigator action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.show.in.navigator.view"</code>). - */ - public static final String SHOW_IN_NAVIGATOR_VIEW= "org.eclipse.wst.jsdt.ui.edit.text.java.show.in.navigator.view"; //$NON-NLS-1$ - - // search - - /** - * Action definition ID of the search -> references in workspace action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.search.references.in.workspace"</code>). - */ - public static final String SEARCH_REFERENCES_IN_WORKSPACE= "org.eclipse.wst.jsdt.ui.edit.text.java.search.references.in.workspace"; //$NON-NLS-1$ - - /** - * Action definition ID of the search -> references in project action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.search.references.in.project"</code>). - */ - public static final String SEARCH_REFERENCES_IN_PROJECT= "org.eclipse.wst.jsdt.ui.edit.text.java.search.references.in.project"; //$NON-NLS-1$ - - /** - * Action definition ID of the search -> references in hierarchy action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.search.references.in.hierarchy"</code>). - */ - public static final String SEARCH_REFERENCES_IN_HIERARCHY= "org.eclipse.wst.jsdt.ui.edit.text.java.search.references.in.hierarchy"; //$NON-NLS-1$ - - /** - * Action definition ID of the search -> references in working set action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.search.references.in.working.set"</code>). - */ - public static final String SEARCH_REFERENCES_IN_WORKING_SET= "org.eclipse.wst.jsdt.ui.edit.text.java.search.references.in.working.set"; //$NON-NLS-1$ - - /** - * Action definition ID of the search -> read access in workspace action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.search.read.access.in.workspace"</code>). - */ - public static final String SEARCH_READ_ACCESS_IN_WORKSPACE= "org.eclipse.wst.jsdt.ui.edit.text.java.search.read.access.in.workspace"; //$NON-NLS-1$ - - /** - * Action definition ID of the search -> read access in project action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.search.read.access.in.project"</code>). - */ - public static final String SEARCH_READ_ACCESS_IN_PROJECT= "org.eclipse.wst.jsdt.ui.edit.text.java.search.read.access.in.project"; //$NON-NLS-1$ - - /** - * Action definition ID of the search -> read access in hierarchy action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.search.read.access.in.hierarchy"</code>). - */ - public static final String SEARCH_READ_ACCESS_IN_HIERARCHY= "org.eclipse.wst.jsdt.ui.edit.text.java.search.read.access.in.hierarchy"; //$NON-NLS-1$ - - /** - * Action definition ID of the search -> read access in working set action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.search.read.access.in.working.set"</code>). - */ - public static final String SEARCH_READ_ACCESS_IN_WORKING_SET= "org.eclipse.wst.jsdt.ui.edit.text.java.search.read.access.in.working.set"; //$NON-NLS-1$ - - /** - * Action definition ID of the search -> write access in workspace action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.search.write.access.in.workspace"</code>). - */ - public static final String SEARCH_WRITE_ACCESS_IN_WORKSPACE= "org.eclipse.wst.jsdt.ui.edit.text.java.search.write.access.in.workspace"; //$NON-NLS-1$ - - /** - * Action definition ID of the search -> write access in project action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.search.write.access.in.project"</code>). - */ - public static final String SEARCH_WRITE_ACCESS_IN_PROJECT= "org.eclipse.wst.jsdt.ui.edit.text.java.search.write.access.in.project"; //$NON-NLS-1$ - - /** - * Action definition ID of the search -> write access in hierarchy action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.search.write.access.in.hierarchy"</code>). - */ - public static final String SEARCH_WRITE_ACCESS_IN_HIERARCHY= "org.eclipse.wst.jsdt.ui.edit.text.java.search.write.access.in.hierarchy"; //$NON-NLS-1$ - - /** - * Action definition ID of the search -> write access in working set action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.search.write.access.in.working.set"</code>). - */ - public static final String SEARCH_WRITE_ACCESS_IN_WORKING_SET= "org.eclipse.wst.jsdt.ui.edit.text.java.search.write.access.in.working.set"; //$NON-NLS-1$ - - /** - * Action definition ID of the search -> declarations in workspace action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.search.declarations.in.workspace"</code>). - */ - public static final String SEARCH_DECLARATIONS_IN_WORKSPACE= "org.eclipse.wst.jsdt.ui.edit.text.java.search.declarations.in.workspace"; //$NON-NLS-1$ - /** - * Action definition ID of the search -> declarations in project action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.search.declarations.in.project"</code>). - */ - public static final String SEARCH_DECLARATIONS_IN_PROJECTS= "org.eclipse.wst.jsdt.ui.edit.text.java.search.declarations.in.project"; //$NON-NLS-1$ - /** - * Action definition ID of the search -> declarations in hierarchy action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.search.declarations.in.hierarchy"</code>). - */ - public static final String SEARCH_DECLARATIONS_IN_HIERARCHY= "org.eclipse.wst.jsdt.ui.edit.text.java.search.declarations.in.hierarchy"; //$NON-NLS-1$ - /** - * Action definition ID of the search -> declarations in working set action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.search.declarations.in.working.set"</code>). - */ - public static final String SEARCH_DECLARATIONS_IN_WORKING_SET= "org.eclipse.wst.jsdt.ui.edit.text.java.search.declarations.in.working.set"; //$NON-NLS-1$ - /** - * Action definition ID of the search -> implementors in workspace action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.search.implementors.in.workspace"</code>). - */ - public static final String SEARCH_IMPLEMENTORS_IN_WORKSPACE= "org.eclipse.wst.jsdt.ui.edit.text.java.search.implementors.in.workspace"; //$NON-NLS-1$ - /** - * Action definition ID of the search -> implementors in working set action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.search.implementors.in.working.set"</code>). - */ - public static final String SEARCH_IMPLEMENTORS_IN_WORKING_SET= "org.eclipse.wst.jsdt.ui.edit.text.java.search.implementors.in.working.set"; //$NON-NLS-1$ - - /** - * Action definition ID of the search -> implementors in project action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.search.implementors.in.project"</code>). - * - */ - public static final String SEARCH_IMPLEMENTORS_IN_PROJECT= "org.eclipse.wst.jsdt.ui.edit.text.java.search.implementors.in.project"; //$NON-NLS-1$ - - /** - * Action definition ID of the search -> occurrences in file quick menu action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.search.occurrences.in.file.quickMenu"</code>). - * - */ - public static final String SEARCH_OCCURRENCES_IN_FILE_QUICK_MENU= "org.eclipse.wst.jsdt.ui.edit.text.java.search.occurrences.in.file.quickMenu"; //$NON-NLS-1$ - - /** - * Action definition ID of the search -> occurrences in file > elements action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.search.occurrences.in.file"</code>). - * - */ - public static final String SEARCH_OCCURRENCES_IN_FILE= "org.eclipse.wst.jsdt.ui.edit.text.java.search.occurrences.in.file"; //$NON-NLS-1$ - - /** - * Action definition ID of the search -> occurrences in file > exceptions action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.search.exception.occurrences"</code>). - * - */ - public static final String SEARCH_EXCEPTION_OCCURRENCES_IN_FILE= "org.eclipse.wst.jsdt.ui.edit.text.java.search.exception.occurrences"; //$NON-NLS-1$ - - /** - * Action definition ID of the search -> occurrences in file > implements action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.search.implement.occurrences"</code>). - * - */ - public static final String SEARCH_IMPLEMENT_OCCURRENCES_IN_FILE= "org.eclipse.wst.jsdt.ui.edit.text.java.search.implement.occurrences"; //$NON-NLS-1$ - - // miscellaneous - - /** - * Action definition ID of the toggle text hover tool bar button action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.toggle.text.hover"</code>). - */ - public static final String TOGGLE_TEXT_HOVER= "org.eclipse.wst.jsdt.ui.edit.text.java.toggle.text.hover"; //$NON-NLS-1$ - - /** - * Action definition ID of the remove occurrence annotations action - * (value <code>"org.eclipse.wst.jsdt.ui.edit.text.remove.occurrence.annotations"</code>). - * - */ - public static final String REMOVE_OCCURRENCE_ANNOTATIONS= "org.eclipse.wst.jsdt.ui.edit.text.remove.occurrence.annotations"; //$NON-NLS-1$ - - /** - * Action definition id of toggle mark occurrences action - * (value: <code>"org.eclipse.wst.jsdt.ui.edit.text.java.toggleMarkOccurrences"</code>). - * - */ - public static final String TOGGLE_MARK_OCCURRENCES= "org.eclipse.wst.jsdt.ui.edit.text.java.toggleMarkOccurrences"; //$NON-NLS-1$ - - /** - * Action definition id of the collapse members action - * (value: <code>"org.eclipse.wst.jsdt.ui.edit.text.java.folding.collapseMembers"</code>). - * - */ - public static final String FOLDING_COLLAPSE_MEMBERS= "org.eclipse.wst.jsdt.ui.edit.text.java.folding.collapseMembers"; //$NON-NLS-1$ - - /** - * Action definition id of the collapse comments action - * (value: <code>"org.eclipse.wst.jsdt.ui.edit.text.java.folding.collapseComments"</code>). - * - */ - public static final String FOLDING_COLLAPSE_COMMENTS= "org.eclipse.wst.jsdt.ui.edit.text.java.folding.collapseComments"; //$NON-NLS-1$ - - /** - * Action definition id of the code clean up action - * (value: <code>"org.eclipse.wst.jsdt.ui.edit.text.java.clean.up"</code>). - * - */ - public static final String CLEAN_UP= "org.eclipse.wst.jsdt.ui.edit.text.java.clean.up"; //$NON-NLS-1$ -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ImplementorsSearchGroup.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ImplementorsSearchGroup.java deleted file mode 100644 index 5a09fb77..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ImplementorsSearchGroup.java +++ /dev/null @@ -1,195 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.util.Iterator; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.IWorkingSet; -import org.eclipse.ui.actions.ActionGroup; -import org.eclipse.ui.texteditor.ITextEditorActionConstants; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.search.SearchMessages; -import org.eclipse.wst.jsdt.internal.ui.search.SearchUtil; -import org.eclipse.wst.jsdt.ui.IContextMenuConstants; - -/** - * Action group that adds the search for implementors actions to a - * context menu and the global menu bar. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class ImplementorsSearchGroup extends ActionGroup { - - private static final String MENU_TEXT= SearchMessages.group_implementors; - - private IWorkbenchSite fSite; - private JavaEditor fEditor; - private IActionBars fActionBars; - - private String fGroupId; - - private FindImplementorsAction fFindImplementorsAction; - private FindImplementorsInProjectAction fFindImplementorsInProjectAction; - private FindImplementorsInWorkingSetAction fFindImplementorsInWorkingSetAction; - - /** - * Creates a new <code>ImplementorsSearchGroup</code>. The group - * requires that the selection provided by the site's selection provider - * is of type <code>org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the view part that owns this action group - */ - public ImplementorsSearchGroup(IWorkbenchSite site) { - fSite= site; - fGroupId= IContextMenuConstants.GROUP_SEARCH; - - fFindImplementorsAction= new FindImplementorsAction(site); - fFindImplementorsAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_IMPLEMENTORS_IN_WORKSPACE); - - fFindImplementorsInProjectAction= new FindImplementorsInProjectAction(site); - fFindImplementorsInProjectAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_IMPLEMENTORS_IN_PROJECT); - - fFindImplementorsInWorkingSetAction= new FindImplementorsInWorkingSetAction(site); - fFindImplementorsInWorkingSetAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_IMPLEMENTORS_IN_WORKING_SET); - - // register the actions as selection listeners - ISelectionProvider provider= fSite.getSelectionProvider(); - ISelection selection= provider.getSelection(); - registerAction(fFindImplementorsAction, provider, selection); - registerAction(fFindImplementorsInProjectAction, provider, selection); - registerAction(fFindImplementorsInWorkingSetAction, provider, selection); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public ImplementorsSearchGroup(JavaEditor editor) { - fEditor= editor; - fSite= fEditor.getSite(); - fGroupId= ITextEditorActionConstants.GROUP_FIND; - - fFindImplementorsAction= new FindImplementorsAction(fEditor); - fFindImplementorsAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_IMPLEMENTORS_IN_WORKSPACE); - fEditor.setAction("SearchImplementorsInWorkspace", fFindImplementorsAction); //$NON-NLS-1$ - - fFindImplementorsInProjectAction= new FindImplementorsInProjectAction(fEditor); - fFindImplementorsInProjectAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_IMPLEMENTORS_IN_PROJECT); - fEditor.setAction("SearchImplementorsInProject", fFindImplementorsInProjectAction); //$NON-NLS-1$ - - fFindImplementorsInWorkingSetAction= new FindImplementorsInWorkingSetAction(fEditor); - fFindImplementorsInWorkingSetAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_IMPLEMENTORS_IN_WORKING_SET); - fEditor.setAction("SearchImplementorsInWorkingSet", fFindImplementorsInWorkingSetAction); //$NON-NLS-1$ - } - - private void registerAction(SelectionDispatchAction action, ISelectionProvider provider, ISelection selection){ - action.update(selection); - provider.addSelectionChangedListener(action); - } - - private void addAction(IAction action, IMenuManager manager) { - if (action.isEnabled()) { - manager.add(action); - } - } - - private void addWorkingSetAction(IWorkingSet[] workingSets, IMenuManager manager) { - FindAction action; - if (fEditor != null) - action= new WorkingSetFindAction(fEditor, new FindImplementorsInWorkingSetAction(fEditor, workingSets), SearchUtil.toString(workingSets)); - else - action= new WorkingSetFindAction(fSite, new FindImplementorsInWorkingSetAction(fSite, workingSets), SearchUtil.toString(workingSets)); - action.update(getContext().getSelection()); - addAction(action, manager); - } - - - /* (non-Javadoc) - * Method declared on ActionGroup. - */ - public void fillContextMenu(IMenuManager manager) { - MenuManager javaSearchMM= new MenuManager(MENU_TEXT, IContextMenuConstants.GROUP_SEARCH); - addAction(fFindImplementorsAction, javaSearchMM); - addAction(fFindImplementorsInProjectAction, javaSearchMM); - - javaSearchMM.add(new Separator()); - - Iterator iter= SearchUtil.getLRUWorkingSets().sortedIterator(); - while (iter.hasNext()) { - addWorkingSetAction((IWorkingSet[]) iter.next(), javaSearchMM); - } - addAction(fFindImplementorsInWorkingSetAction, javaSearchMM); - - if (!javaSearchMM.isEmpty()) - manager.appendToGroup(fGroupId, javaSearchMM); - } - - - /* - * Method declared on ActionGroup. - */ - public void fillActionBars(IActionBars actionBars) { - Assert.isNotNull(actionBars); - super.fillActionBars(actionBars); - fActionBars= actionBars; - updateGlobalActionHandlers(); - } - - /* - * Method declared on ActionGroup. - */ - public void dispose() { - ISelectionProvider provider= fSite.getSelectionProvider(); - if (provider != null) { - disposeAction(fFindImplementorsAction, provider); - disposeAction(fFindImplementorsInProjectAction, provider); - disposeAction(fFindImplementorsInWorkingSetAction, provider); - } - super.dispose(); - fFindImplementorsAction= null; - fFindImplementorsInProjectAction= null; - fFindImplementorsInWorkingSetAction= null; - updateGlobalActionHandlers(); - } - - private void updateGlobalActionHandlers() { - if (fActionBars != null) { - fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_IMPLEMENTORS_IN_WORKSPACE, fFindImplementorsAction); - fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_IMPLEMENTORS_IN_PROJECT, fFindImplementorsInProjectAction); - fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_IMPLEMENTORS_IN_WORKING_SET, fFindImplementorsInWorkingSetAction); - } - } - - private void disposeAction(ISelectionChangedListener action, ISelectionProvider provider) { - if (action != null) - provider.removeSelectionChangedListener(action); - } -} - - diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ImportActionGroup.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ImportActionGroup.java deleted file mode 100644 index 22bfb841..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ImportActionGroup.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.actions.ActionGroup; -import org.eclipse.ui.actions.ExportResourcesAction; -import org.eclipse.ui.actions.ImportResourcesAction; -import org.eclipse.wst.jsdt.ui.IContextMenuConstants; - -/** - * Action group to add the Import and Export action to a view part's - * context menu. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class ImportActionGroup extends ActionGroup { - - private static final String GROUP_IMPORT= "group.import"; //$NON-NLS-1$ - - private ImportResourcesAction fImportAction; - private ExportResourcesAction fExportAction; - - /** - * Creates a new <code>ImportActionGroup</code>. The group - * requires that the selection provided by the part's selection provider - * is of type <code>org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param part the view part that owns this action group - */ - public ImportActionGroup(IViewPart part) { - IWorkbenchWindow workbenchWindow = part.getSite().getWorkbenchWindow(); - fImportAction= new ImportResourcesAction(workbenchWindow); - fExportAction= new ExportResourcesAction(workbenchWindow); - } - - /* (non-Javadoc) - * Method declared in ActionGroup - */ - public void fillContextMenu(IMenuManager menu) { - menu.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, new Separator(GROUP_IMPORT)); - menu.appendToGroup(GROUP_IMPORT, fImportAction); - menu.appendToGroup(GROUP_IMPORT, fExportAction); - super.fillContextMenu(menu); - } - - /** - * {@inheritDoc} - */ - public void dispose() { - fImportAction.dispose(); - fExportAction.dispose(); - super.dispose(); - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/InlineAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/InlineAction.java deleted file mode 100644 index 075f407e..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/InlineAction.java +++ /dev/null @@ -1,135 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IJavaScriptUnit; -import org.eclipse.wst.jsdt.core.ITypeRoot; -import org.eclipse.wst.jsdt.core.dom.JavaScriptUnit; -import org.eclipse.wst.jsdt.internal.corext.refactoring.util.RefactoringASTParser; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.refactoring.RefactoringMessages; -import org.eclipse.wst.jsdt.internal.ui.refactoring.actions.InlineConstantAction; -import org.eclipse.wst.jsdt.internal.ui.refactoring.actions.InlineMethodAction; - -/** - * Inlines a method, local variable or a static final field. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class InlineAction extends SelectionDispatchAction { - - private JavaEditor fEditor; - private final InlineTempAction fInlineTemp; - private final InlineMethodAction fInlineMethod; - private final InlineConstantAction fInlineConstant; - - /** - * Creates a new <code>InlineAction</code>. The action requires - * that the selection provided by the site's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public InlineAction(IWorkbenchSite site) { - super(site); - setText(RefactoringMessages.InlineAction_Inline); - fInlineTemp = new InlineTempAction(site); - fInlineConstant = new InlineConstantAction(site); - fInlineMethod = new InlineMethodAction(site); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.INLINE_ACTION); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the compilation unit editor - */ - public InlineAction(JavaEditor editor) { - //don't want to call 'this' here - it'd create useless action objects - super(editor.getEditorSite()); - setText(RefactoringMessages.InlineAction_Inline); - fEditor= editor; - fInlineTemp = new InlineTempAction(editor); - fInlineConstant = new InlineConstantAction(editor); - fInlineMethod = new InlineMethodAction(editor); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.INLINE_ACTION); - setEnabled(SelectionConverter.getInputAsCompilationUnit(fEditor) != null); - } - - /* - * @see org.eclipse.wst.jsdt.ui.actions.SelectionDispatchAction#selectionChanged(org.eclipse.jface.viewers.ISelection) - */ - public void selectionChanged(ISelection selection) { - fInlineConstant.update(selection); - fInlineMethod.update(selection); - fInlineTemp.update(selection); - setEnabled((fInlineTemp.isEnabled() || fInlineConstant.isEnabled() || fInlineMethod.isEnabled())); - } - - /* - * @see org.eclipse.wst.jsdt.ui.actions.SelectionDispatchAction#run(org.eclipse.jface.text.ITextSelection) - */ - public void run(ITextSelection selection) { - if (!ActionUtil.isEditable(fEditor)) - return; - - ITypeRoot typeRoot= SelectionConverter.getInputAsTypeRoot(fEditor); - if (typeRoot == null) - return; - - JavaScriptUnit node= RefactoringASTParser.parseWithASTProvider(typeRoot, true, null); - - if (typeRoot instanceof IJavaScriptUnit) { - IJavaScriptUnit cu= (IJavaScriptUnit) typeRoot; - if (fInlineTemp.isEnabled() && fInlineTemp.tryInlineTemp(cu, node, selection, getShell())) - return; - - if (fInlineConstant.isEnabled() && fInlineConstant.tryInlineConstant(cu, node, selection, getShell())) - return; - } - //InlineMethod is last (also tries enclosing element): - if (fInlineMethod.isEnabled() && fInlineMethod.tryInlineMethod(typeRoot, node, selection, getShell())) - return; - - MessageDialog.openInformation(getShell(), RefactoringMessages.InlineAction_dialog_title, RefactoringMessages.InlineAction_select); - } - - /* - * @see org.eclipse.wst.jsdt.ui.actions.SelectionDispatchAction#run(org.eclipse.jface.viewers.IStructuredSelection) - */ - public void run(IStructuredSelection selection) { - if (fInlineConstant.isEnabled()) - fInlineConstant.run(selection); - else if (fInlineMethod.isEnabled()) - fInlineMethod.run(selection); - else - //inline temp will never be enabled on IStructuredSelection - //don't bother running it - Assert.isTrue(! fInlineTemp.isEnabled()); - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/InlineTempAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/InlineTempAction.java deleted file mode 100644 index 0f2084c1..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/InlineTempAction.java +++ /dev/null @@ -1,125 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IJavaScriptUnit; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.core.dom.JavaScriptUnit; -import org.eclipse.wst.jsdt.internal.corext.refactoring.RefactoringAvailabilityTester; -import org.eclipse.wst.jsdt.internal.corext.refactoring.RefactoringExecutionStarter; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaTextSelection; -import org.eclipse.wst.jsdt.internal.ui.refactoring.RefactoringMessages; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; - -/** - * Inlines the value of a local variable at all places where a read reference - * is used. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class InlineTempAction extends SelectionDispatchAction { - - private JavaEditor fEditor; - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * - * @param editor the JavaScript editor - */ - public InlineTempAction(JavaEditor editor) { - this(editor.getEditorSite()); - fEditor= editor; - setEnabled(SelectionConverter.canOperateOn(fEditor)); - } - - /* package */ InlineTempAction(IWorkbenchSite site) { - super(site); - setText(RefactoringMessages.InlineTempAction_label); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.INLINE_ACTION); - } - - //---- text selection ---------------------------------------------------------- - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction - */ - public void selectionChanged(ITextSelection selection) { - setEnabled(true); - } - - /** - * Note: This method is for internal use only. Clients should not call this method. - * @param selection - */ - public void selectionChanged(JavaTextSelection selection) { - try { - setEnabled(RefactoringAvailabilityTester.isInlineTempAvailable(selection)); - } catch (JavaScriptModelException e) { - setEnabled(false); - } - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction - */ - public void run(ITextSelection selection) { - try{ - IJavaScriptUnit input= SelectionConverter.getInputAsCompilationUnit(fEditor); - if (!ActionUtil.isEditable(fEditor)) - return; - RefactoringExecutionStarter.startInlineTempRefactoring(input, null, selection, getShell()); - } catch (JavaScriptModelException e){ - ExceptionHandler.handle(e, RefactoringMessages.InlineTempAction_inline_temp, RefactoringMessages.NewTextRefactoringAction_exception); - } - } - - /* - * @see org.eclipse.wst.jsdt.ui.actions.SelectionDispatchAction#run(org.eclipse.jface.viewers.IStructuredSelection) - */ - public void run(IStructuredSelection selection) { - //do nothing - } - - /* - * @see org.eclipse.wst.jsdt.ui.actions.SelectionDispatchAction#selectionChanged(org.eclipse.jface.viewers.IStructuredSelection) - */ - public void selectionChanged(IStructuredSelection selection) { - setEnabled(false); - } - - /* package */ boolean tryInlineTemp(IJavaScriptUnit unit, JavaScriptUnit node, ITextSelection selection, Shell shell) { - try { - if (RefactoringExecutionStarter.startInlineTempRefactoring(unit, node, selection, shell)) { - return true; - } - } catch (JavaScriptModelException exception) { - ExceptionHandler.handle(exception, RefactoringMessages.InlineTempAction_inline_temp, RefactoringMessages.NewTextRefactoringAction_exception); - } - return false; - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/IntroduceFactoryAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/IntroduceFactoryAction.java deleted file mode 100644 index bab6b02f..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/IntroduceFactoryAction.java +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.text.TextSelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IFunction; -import org.eclipse.wst.jsdt.core.ISourceRange; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.internal.corext.refactoring.RefactoringAvailabilityTester; -import org.eclipse.wst.jsdt.internal.corext.refactoring.RefactoringExecutionStarter; -import org.eclipse.wst.jsdt.internal.corext.util.JavaModelUtil; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaTextSelection; -import org.eclipse.wst.jsdt.internal.ui.refactoring.RefactoringMessages; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; - -/** - * Action that encapsulates the a constructor call with a factory - * method. - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class IntroduceFactoryAction extends SelectionDispatchAction { - - private JavaEditor fEditor; - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public IntroduceFactoryAction(JavaEditor editor) { - this(editor.getEditorSite()); - fEditor= editor; - setEnabled(SelectionConverter.getInputAsCompilationUnit(fEditor) != null); - } - - /** - * Creates a new <code>IntroduceFactoryAction</code>. The action requires - * that the selection provided by the site's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public IntroduceFactoryAction(IWorkbenchSite site) { - super(site); - setText(RefactoringMessages.IntroduceFactoryAction_label); - setToolTipText(RefactoringMessages.IntroduceFactoryAction_tooltipText); - setDescription(RefactoringMessages.IntroduceFactoryAction_description); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.INTRODUCE_FACTORY_ACTION); - } - - //---- structured selection -------------------------------------------------- - - /* - * @see SelectionDispatchAction#selectionChanged(IStructuredSelection) - */ - public void selectionChanged(IStructuredSelection selection) { - try { - setEnabled(RefactoringAvailabilityTester.isIntroduceFactoryAvailable(selection)); - } catch (JavaScriptModelException e) { - if (JavaModelUtil.isExceptionToBeLogged(e)) - JavaScriptPlugin.log(e); - setEnabled(false);//no UI here - happens on selection changes - } - } - - /* - * @see SelectionDispatchAction#run(IStructuredSelection) - */ - 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.isIntroduceFactoryAvailable(selection)) { - IFunction method= (IFunction) selection.getFirstElement(); - if (!ActionUtil.isEditable(getShell(), method)) - return; - ISourceRange range= method.getNameRange(); - RefactoringExecutionStarter.startIntroduceFactoryRefactoring(method.getJavaScriptUnit(), new TextSelection(range.getOffset(), range.getLength()), getShell()); - } - } catch (CoreException e) { - ExceptionHandler.handle(e, RefactoringMessages.IntroduceFactoryAction_dialog_title, RefactoringMessages.IntroduceFactoryAction_exception); - } - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction - */ - public void selectionChanged(ITextSelection selection) { - setEnabled(fEditor != null && SelectionConverter.getInputAsCompilationUnit(fEditor) != null); - } - - /** - * Note: This method is for internal use only. Clients should not call this method. - */ - public void selectionChanged(JavaTextSelection selection) { - try { - setEnabled(RefactoringAvailabilityTester.isIntroduceFactoryAvailable(selection)); - } catch (JavaScriptModelException e) { - setEnabled(false); - } - } - - public void run(ITextSelection selection) { - if (!ActionUtil.isEditable(fEditor)) - return; - try { - RefactoringExecutionStarter.startIntroduceFactoryRefactoring(SelectionConverter.getInputAsCompilationUnit(fEditor), selection, getShell()); - } catch (CoreException e) { - ExceptionHandler.handle(e, RefactoringMessages.IntroduceFactoryAction_dialog_title, RefactoringMessages.IntroduceFactoryAction_exception); - } - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/IntroduceIndirectionAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/IntroduceIndirectionAction.java deleted file mode 100644 index 68e4e079..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/IntroduceIndirectionAction.java +++ /dev/null @@ -1,154 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IClassFile; -import org.eclipse.wst.jsdt.core.IJavaScriptUnit; -import org.eclipse.wst.jsdt.core.IFunction; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.internal.corext.refactoring.RefactoringAvailabilityTester; -import org.eclipse.wst.jsdt.internal.corext.refactoring.RefactoringExecutionStarter; -import org.eclipse.wst.jsdt.internal.corext.util.JavaModelUtil; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaTextSelection; -import org.eclipse.wst.jsdt.internal.ui.refactoring.RefactoringMessages; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; - -/** - * Action that introduces an indirection for a certain method. This action may be invoked - * on source or binary methods or method invocations with or without attached source. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class IntroduceIndirectionAction extends SelectionDispatchAction { - - private JavaEditor fEditor; - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the compilation unit editor - */ - public IntroduceIndirectionAction(JavaEditor editor) { - this(editor.getEditorSite()); - fEditor= editor; - setEnabled(true); - } - - /** - * Creates a new <code>IntroduceIndirectionAction</code>. - * - * @param site the site providing context information for this action - */ - public IntroduceIndirectionAction(IWorkbenchSite site) { - super(site); - setText(RefactoringMessages.IntroduceIndirectionAction_title); - setToolTipText(RefactoringMessages.IntroduceIndirectionAction_tooltip); - setDescription(RefactoringMessages.IntroduceIndirectionAction_description); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.INTRODUCE_INDIRECTION_ACTION); - } - - //---- structured selection -------------------------------------------------- - - /* - * @see SelectionDispatchAction#selectionChanged(IStructuredSelection) - */ - public void selectionChanged(IStructuredSelection selection) { - try { - setEnabled(RefactoringAvailabilityTester.isIntroduceIndirectionAvailable(selection)); - } catch (JavaScriptModelException e) { - if (JavaModelUtil.isExceptionToBeLogged(e)) - JavaScriptPlugin.log(e); - } - } - - /* - * @see SelectionDispatchAction#selectionChanged(ITextSelection) - */ - public void selectionChanged(ITextSelection selection) { - setEnabled(true); - } - - /** - * Note: This method is for internal use only. Clients should not call this method. - */ - public void selectionChanged(JavaTextSelection selection) { - try { - setEnabled(RefactoringAvailabilityTester.isIntroduceIndirectionAvailable(selection)); - } catch (JavaScriptModelException e) { - setEnabled(false); - } - } - - /* - * @see SelectionDispatchAction#run(IStructuredSelection) - */ - public void run(IStructuredSelection selection) { - try { - Assert.isTrue(RefactoringAvailabilityTester.isIntroduceIndirectionAvailable(selection)); - Object first= selection.getFirstElement(); - Assert.isTrue(first instanceof IFunction); - run((IFunction) first); - } catch (CoreException e) { - ExceptionHandler.handle(e, RefactoringMessages.IntroduceIndirectionAction_dialog_title, RefactoringMessages.IntroduceIndirectionAction_unknown_exception); - } - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction - */ - public void run(ITextSelection selection) { - try { - Object editorInput= SelectionConverter.getInput(fEditor); - if (editorInput instanceof IJavaScriptUnit) - run(selection.getOffset(), selection.getLength(), (IJavaScriptUnit) editorInput); - else if (editorInput instanceof IClassFile) - run(selection.getOffset(), selection.getLength(), (IClassFile) editorInput); - } catch (JavaScriptModelException e) { - ExceptionHandler.handle(e, getShell(), RefactoringMessages.IntroduceIndirectionAction_dialog_title, RefactoringMessages.IntroduceIndirectionAction_unknown_exception); - } - } - - private void run(int offset, int length, IJavaScriptUnit unit) throws JavaScriptModelException { - if (!ActionUtil.isEditable(fEditor, getShell(), unit)) - return; - RefactoringExecutionStarter.startIntroduceIndirectionRefactoring(unit, offset, length, getShell()); - } - - private void run(int offset, int length, IClassFile file) throws JavaScriptModelException { - if (!ActionUtil.isEditable(fEditor, getShell(), file)) - return; - RefactoringExecutionStarter.startIntroduceIndirectionRefactoring(file, offset, length, getShell()); - } - - private void run(IFunction method) throws JavaScriptModelException { - if (!ActionUtil.isEditable(fEditor, getShell(), method)) - return; - RefactoringExecutionStarter.startIntroduceIndirectionRefactoring(method, getShell()); - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/IntroduceParameterAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/IntroduceParameterAction.java deleted file mode 100644 index 29c500c4..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/IntroduceParameterAction.java +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IJavaScriptUnit; -import org.eclipse.wst.jsdt.internal.corext.refactoring.RefactoringAvailabilityTester; -import org.eclipse.wst.jsdt.internal.corext.refactoring.RefactoringExecutionStarter; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaTextSelection; -import org.eclipse.wst.jsdt.internal.ui.refactoring.RefactoringMessages; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; - -/** - * Introduces a new method parameter from a selected expression. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class IntroduceParameterAction extends SelectionDispatchAction { - - private final JavaEditor fEditor; - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public IntroduceParameterAction(JavaEditor editor) { - super(editor.getEditorSite()); - setText(RefactoringMessages.IntroduceParameterAction_label); - fEditor= editor; - setEnabled(SelectionConverter.getInputAsCompilationUnit(fEditor) != null); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.INTRODUCE_PARAMETER_ACTION); - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction - */ - public void selectionChanged(ITextSelection selection) { - setEnabled((fEditor != null && SelectionConverter.getInputAsCompilationUnit(fEditor) != null)); - } - - /** - * Note: This method is for internal use only. Clients should not call this method. - */ - public void selectionChanged(JavaTextSelection selection) { - setEnabled(RefactoringAvailabilityTester.isIntroduceParameterAvailable(selection)); - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction - */ - public void run(ITextSelection selection) { - if (!ActionUtil.isEditable(fEditor)) - return; - try{ - IJavaScriptUnit unit= SelectionConverter.getInputAsCompilationUnit(fEditor); - RefactoringExecutionStarter.startIntroduceParameter(unit, selection.getOffset(), selection.getLength(), getShell()); - } catch (CoreException e){ - ExceptionHandler.handle(e, RefactoringMessages.IntroduceParameterAction_dialog_title, RefactoringMessages.NewTextRefactoringAction_exception); - } - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/JavaSearchActionGroup.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/JavaSearchActionGroup.java deleted file mode 100644 index 3eb32021..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/JavaSearchActionGroup.java +++ /dev/null @@ -1,183 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.action.GroupMarker; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.actions.ActionContext; -import org.eclipse.ui.actions.ActionGroup; -import org.eclipse.ui.part.Page; -import org.eclipse.ui.texteditor.ITextEditorActionConstants; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.search.SearchMessages; -import org.eclipse.wst.jsdt.ui.PreferenceConstants; - -/** - * Action group that adds the JavaScript search actions to a context menu and - * the global menu bar. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class JavaSearchActionGroup extends ActionGroup { - - private JavaEditor fEditor; - - private ReferencesSearchGroup fReferencesGroup; - private ReadReferencesSearchGroup fReadAccessGroup; - private WriteReferencesSearchGroup fWriteAccessGroup; - private DeclarationsSearchGroup fDeclarationsGroup; -// private ImplementorsSearchGroup fImplementorsGroup; - private OccurrencesSearchGroup fOccurrencesGroup; - - - /** - * Creates a new <code>JavaSearchActionGroup</code>. The group - * requires that the selection provided by the part's selection provider - * is of type <code>org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param part the view part that owns this action group - */ - public JavaSearchActionGroup(IViewPart part) { - this(part.getViewSite()); - } - - /** - * Creates a new <code>JavaSearchActionGroup</code>. The group - * requires that the selection provided by the page's selection provider - * is of type <code>org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param page the page that owns this action group - */ - public JavaSearchActionGroup(Page page) { - this(page.getSite()); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public JavaSearchActionGroup(JavaEditor editor) { - Assert.isNotNull(editor); - fEditor= editor; - - fReferencesGroup= new ReferencesSearchGroup(fEditor); - fReadAccessGroup= new ReadReferencesSearchGroup(fEditor); - fWriteAccessGroup= new WriteReferencesSearchGroup(fEditor); - fDeclarationsGroup= new DeclarationsSearchGroup(fEditor); -// fImplementorsGroup= new ImplementorsSearchGroup(fEditor); - fOccurrencesGroup= new OccurrencesSearchGroup(fEditor); - } - - private JavaSearchActionGroup(IWorkbenchSite site) { - fReferencesGroup= new ReferencesSearchGroup(site); - fReadAccessGroup= new ReadReferencesSearchGroup(site); - fWriteAccessGroup= new WriteReferencesSearchGroup(site); - fDeclarationsGroup= new DeclarationsSearchGroup(site); -// fImplementorsGroup= new ImplementorsSearchGroup(site); - fOccurrencesGroup= new OccurrencesSearchGroup(site); - } - - /* - * Method declared on ActionGroup. - */ - public void setContext(ActionContext context) { - fReferencesGroup.setContext(context); - fDeclarationsGroup.setContext(context); -// fImplementorsGroup.setContext(context); - fReadAccessGroup.setContext(context); - fWriteAccessGroup.setContext(context); - fOccurrencesGroup.setContext(context); - } - - /* - * Method declared on ActionGroup. - */ - public void fillActionBars(IActionBars actionBar) { - super.fillActionBars(actionBar); - fReferencesGroup.fillActionBars(actionBar); - fDeclarationsGroup.fillActionBars(actionBar); -// fImplementorsGroup.fillActionBars(actionBar); - fReadAccessGroup.fillActionBars(actionBar); - fWriteAccessGroup.fillActionBars(actionBar); - fOccurrencesGroup.fillActionBars(actionBar); - } - - /* - * Method declared on ActionGroup. - */ - public void fillContextMenu(IMenuManager menu) { - super.fillContextMenu(menu); - - if(PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.SEARCH_USE_REDUCED_MENU)) { - fReferencesGroup.fillContextMenu(menu); - fDeclarationsGroup.fillContextMenu(menu); - - if (fEditor == null) { -// fImplementorsGroup.fillContextMenu(menu); - fReadAccessGroup.fillContextMenu(menu); - fWriteAccessGroup.fillContextMenu(menu); - } - } else { - IMenuManager target= menu; - IMenuManager searchSubMenu= null; - if (fEditor != null) { - String groupName= SearchMessages.group_search; - searchSubMenu= new MenuManager(groupName, ITextEditorActionConstants.GROUP_FIND); - searchSubMenu.add(new GroupMarker(ITextEditorActionConstants.GROUP_FIND)); - target= searchSubMenu; - } - - fReferencesGroup.fillContextMenu(target); - fDeclarationsGroup.fillContextMenu(target); -// fImplementorsGroup.fillContextMenu(target); - fReadAccessGroup.fillContextMenu(target); - fWriteAccessGroup.fillContextMenu(target); - - if (searchSubMenu != null) { - fOccurrencesGroup.fillContextMenu(target); - searchSubMenu.add(new Separator()); - } - - // no other way to find out if we have added items. - if (searchSubMenu != null && searchSubMenu.getItems().length > 2) { - menu.appendToGroup(ITextEditorActionConstants.GROUP_FIND, searchSubMenu); - } - } - } - - /* - * Method declared on ActionGroup. - */ - public void dispose() { - fReferencesGroup.dispose(); - fDeclarationsGroup.dispose(); -// fImplementorsGroup.dispose(); - fReadAccessGroup.dispose(); - fWriteAccessGroup.dispose(); - fOccurrencesGroup.dispose(); - - super.dispose(); - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/JdtActionConstants.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/JdtActionConstants.java deleted file mode 100644 index 7792deda..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/JdtActionConstants.java +++ /dev/null @@ -1,565 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - - -/** - * Action ids for standard actions, for groups in the menu bar, and - * for actions in context menus of JDT views. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class JdtActionConstants { - - // Navigate menu - - /** - * Navigate menu: name of standard Goto Type global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.GoToType"</code>). - */ - public static final String GOTO_TYPE= "org.eclipse.wst.jsdt.ui.actions.GoToType"; //$NON-NLS-1$ - - /** - * Navigate menu: name of standard Goto Package global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.GoToPackage"</code>). - */ - public static final String GOTO_PACKAGE= "org.eclipse.wst.jsdt.ui.actions.GoToPackage"; //$NON-NLS-1$ - - /** - * Navigate menu: name of standard Open global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.Open"</code>). - */ - public static final String OPEN= "org.eclipse.wst.jsdt.ui.actions.Open"; //$NON-NLS-1$ - - /** - * Navigate menu: name of standard Open Super Implementation global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.OpenSuperImplementation"</code>). - */ - public static final String OPEN_SUPER_IMPLEMENTATION= "org.eclipse.wst.jsdt.ui.actions.OpenSuperImplementation"; //$NON-NLS-1$ - - /** - * Navigate menu: name of standard Open Type Hierarchy global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.OpenTypeHierarchy"</code>). - */ - public static final String OPEN_TYPE_HIERARCHY= "org.eclipse.wst.jsdt.ui.actions.OpenTypeHierarchy"; //$NON-NLS-1$ - - /** - * Navigate menu: name of standard Open Call Hierarchy global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.OpenCallHierarchy"</code>). - * - */ - public static final String OPEN_CALL_HIERARCHY= "org.eclipse.wst.jsdt.ui.actions.OpenCallHierarchy"; //$NON-NLS-1$ - - /** - * Navigate menu: name of standard Open External Javadoc global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.OpenExternalJavaDoc"</code>). - */ - public static final String OPEN_EXTERNAL_JAVA_DOC= "org.eclipse.wst.jsdt.ui.actions.OpenExternalJavaDoc"; //$NON-NLS-1$ - - /** - * Navigate menu: name of standard Show in Packages View global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.ShowInPackagesView"</code>). - */ - public static final String SHOW_IN_PACKAGE_VIEW= "org.eclipse.wst.jsdt.ui.actions.ShowInPackagesView"; //$NON-NLS-1$ - - /** - * Navigate menu: name of standard Show in Navigator View global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.ShowInNaviagtorView"</code>). - */ - public static final String SHOW_IN_NAVIGATOR_VIEW= "org.eclipse.wst.jsdt.ui.actions.ShowInNaviagtorView"; //$NON-NLS-1$ - - // Edit menu - - /** - * Edit menu: name of standard Code Assist global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.ContentAssist"</code>). - */ - public static final String CONTENT_ASSIST= "org.eclipse.wst.jsdt.ui.actions.ContentAssist"; //$NON-NLS-1$ - - // Source menu - - /** - * Source menu: name of standard Comment global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.Comment"</code>). - */ - public static final String COMMENT= "org.eclipse.wst.jsdt.ui.actions.Comment"; //$NON-NLS-1$ - - /** - * Source menu: name of standard Uncomment global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.Uncomment"</code>). - */ - public static final String UNCOMMENT= "org.eclipse.wst.jsdt.ui.actions.Uncomment"; //$NON-NLS-1$ - - /** - * Source menu: name of standard ToggleComment global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.ToggleComment"</code>). - * - */ - public static final String TOGGLE_COMMENT= "org.eclipse.wst.jsdt.ui.actions.ToggleComment"; //$NON-NLS-1$ - - /** - * Source menu: name of standard Block Comment global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.AddBlockComment"</code>). - * - * - */ - public static final String ADD_BLOCK_COMMENT= "org.eclipse.wst.jsdt.ui.actions.AddBlockComment"; //$NON-NLS-1$ - - /** - * Source menu: name of standard Block Uncomment global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.RemoveBlockComment"</code>). - * - * - */ - public static final String REMOVE_BLOCK_COMMENT= "org.eclipse.wst.jsdt.ui.actions.RemoveBlockComment"; //$NON-NLS-1$ - - /** - * Source menu: name of standard Indent global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.Indent"</code>). - * - * - */ - public static final String INDENT= "org.eclipse.wst.jsdt.ui.actions.Indent"; //$NON-NLS-1$ - - /** - * Source menu: name of standard Shift Right action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.ShiftRight"</code>). - */ - public static final String SHIFT_RIGHT= "org.eclipse.wst.jsdt.ui.actions.ShiftRight"; //$NON-NLS-1$ - - /** - * Source menu: name of standard Shift Left global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.ShiftLeft"</code>). - */ - public static final String SHIFT_LEFT= "org.eclipse.wst.jsdt.ui.actions.ShiftLeft"; //$NON-NLS-1$ - - /** - * Source menu: name of standard Format global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.Format"</code>). - */ - public static final String FORMAT= "org.eclipse.wst.jsdt.ui.actions.Format"; //$NON-NLS-1$ - - /** - * Source menu: name of standard Format Element global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.FormatElement"</code>). - * - */ - public static final String FORMAT_ELEMENT= "org.eclipse.wst.jsdt.ui.actions.FormatElement"; //$NON-NLS-1$ - - /** - * Source menu: name of standard Add Import global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.AddImport"</code>). - */ - public static final String ADD_IMPORT= "org.eclipse.wst.jsdt.ui.actions.AddImport"; //$NON-NLS-1$ - - /** - * Source menu: name of standard Organize Imports global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.OrganizeImports"</code>). - */ - public static final String ORGANIZE_IMPORTS= "org.eclipse.wst.jsdt.ui.actions.OrganizeImports"; //$NON-NLS-1$ - - /** - * Source menu: name of standard Sort Members global action (value - * <code>"org.eclipse.wst.jsdt.ui.actions.SortMembers"</code>). - * - */ - public static final String SORT_MEMBERS= "org.eclipse.wst.jsdt.ui.actions.SortMembers"; //$NON-NLS-1$ - - /** - * Source menu: name of standard Surround with try/catch block global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.SurroundWithTryCatch"</code>). - */ - public static final String SURROUND_WITH_TRY_CATCH= "org.eclipse.wst.jsdt.ui.actions.SurroundWithTryCatch"; //$NON-NLS-1$ - - /** - * Source menu: name of standard Override Methods global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.OverrideMethods"</code>). - */ - public static final String OVERRIDE_METHODS= "org.eclipse.wst.jsdt.ui.actions.OverrideMethods"; //$NON-NLS-1$ - - /** - * Source menu: name of standard Generate Getter and Setter global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.GenerateGetterSetter"</code>). - */ - public static final String GENERATE_GETTER_SETTER= "org.eclipse.wst.jsdt.ui.actions.GenerateGetterSetter"; //$NON-NLS-1$ - - /** - * Source menu: name of standard delegate methods global action (value - * <code>"org.eclipse.wst.jsdt.ui.actions.GenerateDelegateMethods"</code>). - * - */ - public static final String GENERATE_DELEGATE_METHODS= "org.eclipse.wst.jsdt.ui.actions.GenerateDelegateMethods"; //$NON-NLS-1$ - - /** - * Source menu: name of standard Add Constructor From Superclass global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.AddConstructorFromSuperclass"</code>). - */ - public static final String ADD_CONSTRUCTOR_FROM_SUPERCLASS= "org.eclipse.wst.jsdt.ui.actions.AddConstructorFromSuperclass"; //$NON-NLS-1$ - - /** - * Source menu: name of standard Generate Constructor using Fields global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.GenerateConstructorUsingFields"</code>). - */ - public static final String GENERATE_CONSTRUCTOR_USING_FIELDS= "org.eclipse.wst.jsdt.ui.actions.GenerateConstructorUsingFields"; //$NON-NLS-1$ - - /** - * Source menu: name of standard Generate hashCode() and equals() global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.GenerateHashCodeEquals"</code>). - * - */ - public static final String GENERATE_HASHCODE_EQUALS= "org.eclipse.wst.jsdt.ui.actions.GenerateHashCodeEquals"; //$NON-NLS-1$ - - /** - * Source menu: name of standard Add Javadoc Comment global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.AddJavaDocComment"</code>). - */ - public static final String ADD_JAVA_DOC_COMMENT= "org.eclipse.wst.jsdt.ui.actions.AddJavaDocComment"; //$NON-NLS-1$ - - /** - * Source menu: name of standard Externalize Strings global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.ExternalizeStrings"</code>). - */ - public static final String EXTERNALIZE_STRINGS= "org.eclipse.wst.jsdt.ui.actions.ExternalizeStrings"; //$NON-NLS-1$ - - /** - * Source menu: name of standard Convert Line Delimiters To Windows global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.ConvertLineDelimitersToWindows"</code>). - */ - public static final String CONVERT_LINE_DELIMITERS_TO_WINDOWS= "org.eclipse.wst.jsdt.ui.actions.ConvertLineDelimitersToWindows"; //$NON-NLS-1$ - - /** - * Source menu: name of standard Convert Line Delimiters To UNIX global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.ConvertLineDelimitersToUNIX"</code>). - */ - public static final String CONVERT_LINE_DELIMITERS_TO_UNIX= "org.eclipse.wst.jsdt.ui.actions.ConvertLineDelimitersToUNIX"; //$NON-NLS-1$ - - /** - * Source menu: name of standardConvert Line Delimiters To Mac global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.ConvertLineDelimitersToMac"</code>). - */ - public static final String CONVERT_LINE_DELIMITERS_TO_MAC= "org.eclipse.wst.jsdt.ui.actions.ConvertLineDelimitersToMac"; //$NON-NLS-1$ - - /** - * Source menu: name of standard Clean up global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.CleanUp"</code>). - * - * - */ - public static final String CLEAN_UP= "org.eclipse.wst.jsdt.ui.actions.CleanUp"; //$NON-NLS-1$ - - // Refactor menu - - /** - * Refactor menu: name of standard Self Encapsulate Field global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.SelfEncapsulateField"</code>). - */ - public static final String SELF_ENCAPSULATE_FIELD= "org.eclipse.wst.jsdt.ui.actions.SelfEncapsulateField"; //$NON-NLS-1$ - - /** - * Refactor menu: name of standard Modify Parameters global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.ModifyParameters"</code>). - */ - public static final String MODIFY_PARAMETERS= "org.eclipse.wst.jsdt.ui.actions.ModifyParameters"; //$NON-NLS-1$ - - /** - * Refactor menu: name of standard Pull Up global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.PullUp"</code>). - */ - public static final String PULL_UP= "org.eclipse.wst.jsdt.ui.actions.PullUp"; //$NON-NLS-1$ - - /** - * Refactor menu: name of standard Push Down global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.PushDown"</code>). - * - * - */ - public static final String PUSH_DOWN= "org.eclipse.wst.jsdt.ui.actions.PushDown"; //$NON-NLS-1$ - - /** - * Refactor menu: name of standard Move Element global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.Move"</code>). - */ - public static final String MOVE= "org.eclipse.wst.jsdt.ui.actions.Move"; //$NON-NLS-1$ - - /** - * Refactor menu: name of standard Rename Element global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.Rename"</code>). - */ - public static final String RENAME= "org.eclipse.wst.jsdt.ui.actions.Rename"; //$NON-NLS-1$ - - /** - * Refactor menu: name of standard Extract Temp global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.ExtractTemp"</code>). - */ - public static final String EXTRACT_TEMP= "org.eclipse.wst.jsdt.ui.actions.ExtractTemp"; //$NON-NLS-1$ - - /** - * Refactor menu: name of standard Extract Constant global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.ExtractConstant"</code>). - * - * - */ - public static final String EXTRACT_CONSTANT= "org.eclipse.wst.jsdt.ui.actions.ExtractConstant"; //$NON-NLS-1$ - - /** - * Refactor menu: name of standard Introduce Parameter global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.IntroduceParameter"</code>). - * - * - */ - public static final String INTRODUCE_PARAMETER= "org.eclipse.wst.jsdt.ui.actions.IntroduceParameter"; //$NON-NLS-1$ - - /** - * Refactor menu: name of standard Introduce Factory global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.IntroduceFactory"</code>). - * - * - */ - public static final String INTRODUCE_FACTORY= "org.eclipse.wst.jsdt.ui.actions.IntroduceFactory"; //$NON-NLS-1$ - - /** - * Refactor menu: name of standard Extract Method global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.ExtractMethod"</code>). - */ - public static final String EXTRACT_METHOD= "org.eclipse.wst.jsdt.ui.actions.ExtractMethod"; //$NON-NLS-1$ - - /** - * Refactor menu: name of standard Replace Invocations global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.ReplaceInvocations"</code>). - * - * - */ - public static final String REPLACE_INVOCATIONS="org.eclipse.wst.jsdt.ui.actions.ReplaceInvocations"; //$NON-NLS-1$ - - /** - * Refactor menu: name of standard Introduce Indirection global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.IntroduceIndirection"</code>). - * - * - */ - public static final String INTRODUCE_INDIRECTION= "org.eclipse.wst.jsdt.ui.actions.IntroduceIndirection"; //$NON-NLS-1$ - - /** - * Refactor menu: name of standard Inline global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.Inline"</code>). - * - * - */ - public static final String INLINE= "org.eclipse.wst.jsdt.ui.actions.Inline"; //$NON-NLS-1$ - - /** - * Refactor menu: name of standard Extract Interface global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.ExtractInterface"</code>). - * - * - */ - public static final String EXTRACT_INTERFACE= "org.eclipse.wst.jsdt.ui.actions.ExtractInterface"; //$NON-NLS-1$ - - /** - * Refactor menu: name of standard Generalize Declared Type global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.ChangeType"</code>). - * - * - */ - public static final String CHANGE_TYPE= "org.eclipse.wst.jsdt.ui.actions.ChangeType"; //$NON-NLS-1$ - - /** - * Refactor menu: name of standard global action to convert a nested type to a top level type - * (value <code>"org.eclipse.wst.jsdt.ui.actions.MoveInnerToTop"</code>). - * - * - */ - public static final String CONVERT_NESTED_TO_TOP= "org.eclipse.wst.jsdt.ui.actions.ConvertNestedToTop"; //$NON-NLS-1$ - - /** - * Refactor menu: name of standard Use Supertype global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.UseSupertype"</code>). - * - * - */ - public static final String USE_SUPERTYPE= "org.eclipse.wst.jsdt.ui.actions.UseSupertype"; //$NON-NLS-1$ - - /** - * Refactor menu: name of standard Infer Generic Type Arguments global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.InferTypeArguments"</code>). - * - * - */ - public static final String INFER_TYPE_ARGUMENTS= "org.eclipse.wst.jsdt.ui.actions.InferTypeArguments"; //$NON-NLS-1$ - - /** - * Refactor menu: name of standard global action to convert a local - * variable to a field (value <code>"org.eclipse.wst.jsdt.ui.actions.ConvertLocalToField"</code>). - * - * - */ - public static final String CONVERT_LOCAL_TO_FIELD= "org.eclipse.wst.jsdt.ui.actions.ConvertLocalToField"; //$NON-NLS-1$ - - /** - * Refactor menu: name of standard Covert Anonymous to Nested global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.ConvertAnonymousToNested"</code>). - * - * - */ - public static final String CONVERT_ANONYMOUS_TO_NESTED= "org.eclipse.wst.jsdt.ui.actions.ConvertAnonymousToNested"; //$NON-NLS-1$ - - // Search Menu - - /** - * Search menu: name of standard Find References in Workspace global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.ReferencesInWorkspace"</code>). - */ - public static final String FIND_REFERENCES_IN_WORKSPACE= "org.eclipse.wst.jsdt.ui.actions.ReferencesInWorkspace"; //$NON-NLS-1$ - - /** - * Search menu: name of standard Find References in Project global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.ReferencesInProject"</code>). - */ - public static final String FIND_REFERENCES_IN_PROJECT= "org.eclipse.wst.jsdt.ui.actions.ReferencesInProject"; //$NON-NLS-1$ - - /** - * Search menu: name of standard Find References in Hierarchy global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.ReferencesInHierarchy"</code>). - */ - public static final String FIND_REFERENCES_IN_HIERARCHY= "org.eclipse.wst.jsdt.ui.actions.ReferencesInHierarchy"; //$NON-NLS-1$ - - /** - * Search menu: name of standard Find References in Working Set global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.ReferencesInWorkingSet"</code>). - */ - public static final String FIND_REFERENCES_IN_WORKING_SET= "org.eclipse.wst.jsdt.ui.actions.ReferencesInWorkingSet"; //$NON-NLS-1$ - - - - /** - * Search menu: name of standard Find Declarations in Workspace global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.DeclarationsInWorkspace"</code>). - */ - public static final String FIND_DECLARATIONS_IN_WORKSPACE= "org.eclipse.wst.jsdt.ui.actions.DeclarationsInWorkspace"; //$NON-NLS-1$ - - /** - * Search menu: name of standard Find Declarations in Project global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.DeclarationsInProject"</code>). - */ - public static final String FIND_DECLARATIONS_IN_PROJECT= "org.eclipse.wst.jsdt.ui.actions.DeclarationsInProject"; //$NON-NLS-1$ - - /** - * Search menu: name of standard Find Declarations in Hierarchy global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.DeclarationsInHierarchy"</code>). - */ - public static final String FIND_DECLARATIONS_IN_HIERARCHY= "org.eclipse.wst.jsdt.ui.actions.DeclarationsInHierarchy"; //$NON-NLS-1$ - - /** - * Search menu: name of standard Find Declarations in Working Set global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.DeclarationsInWorkingSet"</code>). - */ - public static final String FIND_DECLARATIONS_IN_WORKING_SET= "org.eclipse.wst.jsdt.ui.actions.DeclarationsInWorkingSet"; //$NON-NLS-1$ - - /** - * Search menu: name of standard Find Implementors in Workspace global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.ImplementorsInWorkspace"</code>). - */ - public static final String FIND_IMPLEMENTORS_IN_WORKSPACE= "org.eclipse.wst.jsdt.ui.actions.ImplementorsInWorkspace"; //$NON-NLS-1$ - - /** - * Search menu: name of standard Find Implementors in Project global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.ImplementorsInProject"</code>). - */ - public static final String FIND_IMPLEMENTORS_IN_PROJECT= "org.eclipse.wst.jsdt.ui.actions.ImplementorsInProject"; //$NON-NLS-1$ - - /** - * Search menu: name of standard Find Implementors in Working Set global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.ImplementorsInWorkingSet"</code>). - */ - public static final String FIND_IMPLEMENTORS_IN_WORKING_SET= "org.eclipse.wst.jsdt.ui.actions.ImplementorsInWorkingSet"; //$NON-NLS-1$ - - /** - * Search menu: name of standard Find Read Access in Workspace global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.ReadAccessInWorkspace"</code>). - */ - public static final String FIND_READ_ACCESS_IN_WORKSPACE= "org.eclipse.wst.jsdt.ui.actions.ReadAccessInWorkspace"; //$NON-NLS-1$ - - /** - * Search menu: name of standard Find Read Access in Project global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.ReadAccessInProject"</code>). - */ - public static final String FIND_READ_ACCESS_IN_PROJECT= "org.eclipse.wst.jsdt.ui.actions.ReadAccessInProject"; //$NON-NLS-1$ - - /** - * Search menu: name of standard Find Read Access in Hierarchy global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.ReadAccessInHierarchy"</code>). - */ - public static final String FIND_READ_ACCESS_IN_HIERARCHY= "org.eclipse.wst.jsdt.ui.actions.ReadAccessInHierarchy"; //$NON-NLS-1$ - - /** - * Search menu: name of standard Find Read Access in Working Set global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.ReadAccessInWorkingSet"</code>). - */ - public static final String FIND_READ_ACCESS_IN_WORKING_SET= "org.eclipse.wst.jsdt.ui.actions.ReadAccessInWorkingSet"; //$NON-NLS-1$ - - /** - * Search menu: name of standard Find Write Access in Workspace global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.WriteAccessInWorkspace"</code>). - */ - public static final String FIND_WRITE_ACCESS_IN_WORKSPACE= "org.eclipse.wst.jsdt.ui.actions.WriteAccessInWorkspace"; //$NON-NLS-1$ - - /** - * Search menu: name of standard Find Write Access in Project global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.WriteAccessInProject"</code>). - */ - public static final String FIND_WRITE_ACCESS_IN_PROJECT= "org.eclipse.wst.jsdt.ui.actions.WriteAccessInProject"; //$NON-NLS-1$ - - /** - * Search menu: name of standard Find Read Access in Hierarchy global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.WriteAccessInHierarchy"</code>). - */ - public static final String FIND_WRITE_ACCESS_IN_HIERARCHY= "org.eclipse.wst.jsdt.ui.actions.WriteAccessInHierarchy"; //$NON-NLS-1$ - - /** - * Search menu: name of standard Find Read Access in Working Set global action - * (value <code>"org.eclipse.wst.jsdt.ui.actions.WriteAccessInWorkingSet"</code>). - */ - public static final String FIND_WRITE_ACCESS_IN_WORKING_SET= "org.eclipse.wst.jsdt.ui.actions.WriteAccessInWorkingSet"; //$NON-NLS-1$ - - /** - * Search menu: name of standard Occurrences in File global action (value - * <code>"org.eclipse.wst.jsdt.ui.actions.OccurrencesInFile"</code>). - * - * - */ - public static final String FIND_OCCURRENCES_IN_FILE= "org.eclipse.wst.jsdt.ui.actions.OccurrencesInFile"; //$NON-NLS-1$ - - /** - * Search menu: name of standard Find exception occurrences global action (value - * <code>"org.eclipse.wst.jsdt.ui.actions.ExceptionOccurrences"</code>). - * - * - */ - public static final String FIND_EXCEPTION_OCCURRENCES= "org.eclipse.wst.jsdt.ui.actions.ExceptionOccurrences"; //$NON-NLS-1$ - - /** - * Search menu: name of standard Find implement occurrences global action (value - * <code>"org.eclipse.wst.jsdt.ui.actions.ImplementOccurrences"</code>). - * - * - */ - public static final String FIND_IMPLEMENT_OCCURRENCES= "org.eclipse.wst.jsdt.ui.actions.ImplementOccurrences"; //$NON-NLS-1$ - - -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/MemberFilterActionGroup.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/MemberFilterActionGroup.java deleted file mode 100644 index 02326beb..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/MemberFilterActionGroup.java +++ /dev/null @@ -1,346 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.util.ArrayList; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.viewers.StructuredViewer; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IMemento; -import org.eclipse.ui.actions.ActionGroup; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.JavaPluginImages; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages; -import org.eclipse.wst.jsdt.internal.ui.viewsupport.MemberFilter; -import org.eclipse.wst.jsdt.internal.ui.viewsupport.MemberFilterAction; -import org.eclipse.wst.jsdt.ui.PreferenceConstants; - -/** - * Action Group that contributes filter buttons for a view parts showing - * methods and fields. Contributed filters are: hide fields, hide static - * members hide non-public members and hide local types. - * <p> - * The action group installs a filter on a structured viewer. The filter is connected - * to the actions installed in the view part's toolbar menu and is updated when the - * state of the buttons changes. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class MemberFilterActionGroup extends ActionGroup { - - public static final int FILTER_NONPUBLIC= MemberFilter.FILTER_NONPUBLIC; - public static final int FILTER_STATIC= MemberFilter.FILTER_STATIC; - public static final int FILTER_FIELDS= MemberFilter.FILTER_FIELDS; - - /** */ - public static final int FILTER_LOCALTYPES= MemberFilter.FILTER_LOCALTYPES; - /** */ - public static final int ALL_FILTERS= FILTER_NONPUBLIC | FILTER_FIELDS | FILTER_STATIC | FILTER_LOCALTYPES; - - private static final String TAG_HIDEFIELDS= "hidefields"; //$NON-NLS-1$ - private static final String TAG_HIDESTATIC= "hidestatic"; //$NON-NLS-1$ - private static final String TAG_HIDENONPUBLIC= "hidenonpublic"; //$NON-NLS-1$ - private static final String TAG_HIDELOCALTYPES= "hidelocaltypes"; //$NON-NLS-1$ - - private MemberFilterAction[] fFilterActions; - private MemberFilter fFilter; - - private StructuredViewer fViewer; - private String fViewerId; - private boolean fInViewMenu; - - - /** - * Creates a new <code>MemberFilterActionGroup</code>. - * - * @param viewer the viewer to be filtered - * @param viewerId a unique id of the viewer. Used as a key to to store - * the last used filter settings in the preference store - */ - public MemberFilterActionGroup(StructuredViewer viewer, String viewerId) { - this(viewer, viewerId, false); - } - - /** - * Creates a new <code>MemberFilterActionGroup</code>. - * - * @param viewer the viewer to be filtered - * @param viewerId a unique id of the viewer. Used as a key to to store - * the last used filter settings in the preference store - * @param inViewMenu if <code>true</code> the actions are added to the view - * menu. If <code>false</code> they are added to the toolbar. - * - * - */ - public MemberFilterActionGroup(StructuredViewer viewer, String viewerId, boolean inViewMenu) { - this(viewer, viewerId, inViewMenu, ALL_FILTERS); - } - - /** - * Creates a new <code>MemberFilterActionGroup</code>. - * - * @param viewer the viewer to be filtered - * @param viewerId a unique id of the viewer. Used as a key to to store - * the last used filter settings in the preference store - * @param inViewMenu if <code>true</code> the actions are added to the view - * menu. If <code>false</code> they are added to the toolbar. - * @param availableFilters Specifies which filter action should be contained. <code>FILTER_NONPUBLIC</code>, - * <code>FILTER_STATIC</code>, <code>FILTER_FIELDS</code> and <code>FILTER_LOCALTYPES</code> - * or a combination of these constants are possible values. Use <code>ALL_FILTERS</code> to select all available filters. - * - * - */ - public MemberFilterActionGroup(StructuredViewer viewer, String viewerId, boolean inViewMenu, int availableFilters) { - - fViewer= viewer; - fViewerId= viewerId; - fInViewMenu= inViewMenu; - - IPreferenceStore store= PreferenceConstants.getPreferenceStore(); - fFilter= new MemberFilter(); - - String title, helpContext; - ArrayList actions= new ArrayList(4); - - // fields - int filterProperty= FILTER_FIELDS; - if (isSet(filterProperty, availableFilters)) { - boolean filterEnabled= store.getBoolean(getPreferenceKey(filterProperty)); - if (filterEnabled) { - fFilter.addFilter(filterProperty); - } - title= ActionMessages.MemberFilterActionGroup_hide_fields_label; - helpContext= IJavaHelpContextIds.FILTER_FIELDS_ACTION; - MemberFilterAction hideFields= new MemberFilterAction(this, title, filterProperty, helpContext, filterEnabled); - hideFields.setDescription(ActionMessages.MemberFilterActionGroup_hide_fields_description); - hideFields.setToolTipText(ActionMessages.MemberFilterActionGroup_hide_fields_tooltip); - JavaPluginImages.setLocalImageDescriptors(hideFields, "fields_co.gif"); //$NON-NLS-1$ - actions.add(hideFields); - } - - // static - filterProperty= FILTER_STATIC; - if (isSet(filterProperty, availableFilters)) { - boolean filterEnabled= store.getBoolean(getPreferenceKey(filterProperty)); - if (filterEnabled) { - fFilter.addFilter(filterProperty); - } - title= ActionMessages.MemberFilterActionGroup_hide_static_label; - helpContext= IJavaHelpContextIds.FILTER_STATIC_ACTION; - MemberFilterAction hideStatic= new MemberFilterAction(this, title, FILTER_STATIC, helpContext, filterEnabled); - hideStatic.setDescription(ActionMessages.MemberFilterActionGroup_hide_static_description); - hideStatic.setToolTipText(ActionMessages.MemberFilterActionGroup_hide_static_tooltip); - JavaPluginImages.setLocalImageDescriptors(hideStatic, "static_co.gif"); //$NON-NLS-1$ - actions.add(hideStatic); - } - - // non-public - filterProperty= FILTER_NONPUBLIC; - if (isSet(filterProperty, availableFilters)) { - boolean filterEnabled= store.getBoolean(getPreferenceKey(filterProperty)); - if (filterEnabled) { - fFilter.addFilter(filterProperty); - } - title= ActionMessages.MemberFilterActionGroup_hide_nonpublic_label; - helpContext= IJavaHelpContextIds.FILTER_PUBLIC_ACTION; - MemberFilterAction hideNonPublic= new MemberFilterAction(this, title, filterProperty, helpContext, filterEnabled); - hideNonPublic.setDescription(ActionMessages.MemberFilterActionGroup_hide_nonpublic_description); - hideNonPublic.setToolTipText(ActionMessages.MemberFilterActionGroup_hide_nonpublic_tooltip); - JavaPluginImages.setLocalImageDescriptors(hideNonPublic, "public_co.gif"); //$NON-NLS-1$ - actions.add(hideNonPublic); - } - - // local types - filterProperty= FILTER_LOCALTYPES; - if (isSet(filterProperty, availableFilters)) { - boolean filterEnabled= store.getBoolean(getPreferenceKey(filterProperty)); - if (filterEnabled) { - fFilter.addFilter(filterProperty); - } - title= ActionMessages.MemberFilterActionGroup_hide_localtypes_label; - helpContext= IJavaHelpContextIds.FILTER_LOCALTYPES_ACTION; - MemberFilterAction hideLocalTypes= new MemberFilterAction(this, title, filterProperty, helpContext, filterEnabled); - hideLocalTypes.setDescription(ActionMessages.MemberFilterActionGroup_hide_localtypes_description); - hideLocalTypes.setToolTipText(ActionMessages.MemberFilterActionGroup_hide_localtypes_tooltip); - JavaPluginImages.setLocalImageDescriptors(hideLocalTypes, "localtypes_co.gif"); //$NON-NLS-1$ - actions.add(hideLocalTypes); - } - - // order corresponds to order in toolbar - fFilterActions= (MemberFilterAction[]) actions.toArray(new MemberFilterAction[actions.size()]); - - fViewer.addFilter(fFilter); - } - - private String getPreferenceKey(int filterProperty) { - return "MemberFilterActionGroup." + fViewerId + '.' + String.valueOf(filterProperty); //$NON-NLS-1$ - } - - /** - * Sets the member filters. - * - * @param filterProperty the filter to be manipulated. Valid values are <code>FILTER_FIELDS</code>, - * <code>FILTER_PUBLIC</code> <code>FILTER_PRIVATE</code> and <code>FILTER_LOCALTYPES_ACTION</code> - * as defined by this action group - * @param set if <code>true</code> the given filter is installed. If <code>false</code> the - * given filter is removed - * . - */ - public void setMemberFilter(int filterProperty, boolean set) { - setMemberFilters(new int[] {filterProperty}, new boolean[] {set}, true); - } - - private void setMemberFilters(int[] propertyKeys, boolean[] propertyValues, boolean refresh) { - if (propertyKeys.length == 0) - return; - Assert.isTrue(propertyKeys.length == propertyValues.length); - - for (int i= 0; i < propertyKeys.length; i++) { - int filterProperty= propertyKeys[i]; - boolean set= propertyValues[i]; - - IPreferenceStore store= JavaScriptPlugin.getDefault().getPreferenceStore(); - boolean found= false; - for (int j= 0; j < fFilterActions.length; j++) { - int currProperty= fFilterActions[j].getFilterProperty(); - if (currProperty == filterProperty) { - fFilterActions[j].setChecked(set); - found= true; - store.setValue(getPreferenceKey(filterProperty), set); - } - } - if (found) { - if (set) { - fFilter.addFilter(filterProperty); - } else { - fFilter.removeFilter(filterProperty); - } - } - } - if (refresh) { - fViewer.getControl().setRedraw(false); - BusyIndicator.showWhile(fViewer.getControl().getDisplay(), new Runnable() { - public void run() { - fViewer.refresh(); - } - }); - fViewer.getControl().setRedraw(true); - } - } - - private boolean isSet(int flag, int set) { - return (flag & set) != 0; - } - - /** - * Returns <code>true</code> if the given filter is installed. - * - * @param filterProperty the filter to be tested. Valid values are <code>FILTER_FIELDS</code>, - * <code>FILTER_PUBLIC</code>, <code>FILTER_PRIVATE</code> and <code>FILTER_LOCALTYPES</code> as defined by this action - * group - */ - public boolean hasMemberFilter(int filterProperty) { - return fFilter.hasFilter(filterProperty); - } - - /** - * Saves the state of the filter actions in a memento. - * - * @param memento the memento to which the state is saved - */ - public void saveState(IMemento memento) { - memento.putString(TAG_HIDEFIELDS, String.valueOf(hasMemberFilter(FILTER_FIELDS))); - memento.putString(TAG_HIDESTATIC, String.valueOf(hasMemberFilter(FILTER_STATIC))); - memento.putString(TAG_HIDENONPUBLIC, String.valueOf(hasMemberFilter(FILTER_NONPUBLIC))); - memento.putString(TAG_HIDELOCALTYPES, String.valueOf(hasMemberFilter(FILTER_LOCALTYPES))); - } - - /** - * Restores the state of the filter actions from a memento. - * <p> - * Note: This method does not refresh the viewer. - * </p> - * @param memento the memento from which the state is restored - */ - public void restoreState(IMemento memento) { - setMemberFilters( - new int[] {FILTER_FIELDS, FILTER_STATIC, FILTER_NONPUBLIC, FILTER_LOCALTYPES}, - new boolean[] { - Boolean.valueOf(memento.getString(TAG_HIDEFIELDS)).booleanValue(), - Boolean.valueOf(memento.getString(TAG_HIDESTATIC)).booleanValue(), - Boolean.valueOf(memento.getString(TAG_HIDENONPUBLIC)).booleanValue(), - Boolean.valueOf(memento.getString(TAG_HIDELOCALTYPES)).booleanValue() - }, false); - } - - /* (non-Javadoc) - * @see ActionGroup#fillActionBars(IActionBars) - */ - public void fillActionBars(IActionBars actionBars) { - contributeToToolBar(actionBars.getToolBarManager()); - } - - /** - * Adds the filter actions to the given tool bar - * - * @param tbm the tool bar to which the actions are added - */ - public void contributeToToolBar(IToolBarManager tbm) { - if (fInViewMenu) - return; - for (int i= 0; i < fFilterActions.length; i++) { - tbm.add(fFilterActions[i]); - } - } - - /** - * Adds the filter actions to the given menu manager. - * - * @param menu the menu manager to which the actions are added - * - */ - public void contributeToViewMenu(IMenuManager menu) { - if (!fInViewMenu) - return; - final String filters= "filters"; //$NON-NLS-1$ - if (menu.find(filters) != null) { - for (int i= 0; i < fFilterActions.length; i++) { - menu.prependToGroup(filters, fFilterActions[i]); - } - } else { - for (int i= 0; i < fFilterActions.length; i++) { - menu.add(fFilterActions[i]); - } - } - } - - /* (non-Javadoc) - * @see ActionGroup#dispose() - */ - public void dispose() { - super.dispose(); - } - -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ModifyParametersAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ModifyParametersAction.java deleted file mode 100644 index 691084fa..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ModifyParametersAction.java +++ /dev/null @@ -1,167 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.IFunction; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.internal.corext.refactoring.RefactoringAvailabilityTester; -import org.eclipse.wst.jsdt.internal.corext.refactoring.RefactoringExecutionStarter; -import org.eclipse.wst.jsdt.internal.corext.util.JavaModelUtil; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaTextSelection; -import org.eclipse.wst.jsdt.internal.ui.refactoring.RefactoringMessages; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; - -/** - * Action to start the modify parameters refactoring. The refactoring supports - * swapping and renaming of arguments. - * <p> - * This action is applicable to selections containing a method with one or - * more arguments. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class ModifyParametersAction extends SelectionDispatchAction { - - private JavaEditor fEditor; - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public ModifyParametersAction(JavaEditor editor) { - this(editor.getEditorSite()); - fEditor= editor; - setEnabled(SelectionConverter.canOperateOn(fEditor)); - } - - /** - * Creates a new <code>ModifyParametersAction</code>. The action requires - * that the selection provided by the site's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public ModifyParametersAction(IWorkbenchSite site) { - super(site); - setText(RefactoringMessages.RefactoringGroup_modify_Parameters_label); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.MODIFY_PARAMETERS_ACTION); - } - - /* - * @see SelectionDispatchAction#selectionChanged(IStructuredSelection) - */ - public void selectionChanged(IStructuredSelection selection) { - try { - setEnabled(RefactoringAvailabilityTester.isChangeSignatureAvailable(selection)); - } catch (JavaScriptModelException e) { - // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253 - if (JavaModelUtil.isExceptionToBeLogged(e)) - JavaScriptPlugin.log(e); - setEnabled(false);//no UI here - happens on selection changes - } - } - - /* - * @see SelectionDispatchAction#selectionChanged(ITextSelection) - */ - public void selectionChanged(ITextSelection selection) { - setEnabled(true); - } - - /** - * Note: This method is for internal use only. Clients should not call this method. - */ - public void selectionChanged(JavaTextSelection selection) { - try { - setEnabled(RefactoringAvailabilityTester.isChangeSignatureAvailable(selection)); - } catch (JavaScriptModelException e) { - setEnabled(false); - } - } - - /* - * @see SelectionDispatchAction#run(IStructuredSelection) - */ - 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.isChangeSignatureAvailable(selection)) { - IFunction method= getSingleSelectedMethod(selection); - if (! ActionUtil.isEditable(getShell(), method)) - return; - RefactoringExecutionStarter.startChangeSignatureRefactoring(method, this, getShell()); - } - } catch (JavaScriptModelException e) { - ExceptionHandler.handle(e, RefactoringMessages.OpenRefactoringWizardAction_refactoring, RefactoringMessages.OpenRefactoringWizardAction_exception); - } - } - - /* - * @see SelectionDispatchAction#run(ITextSelection) - */ - public void run(ITextSelection selection) { - try { - if (! ActionUtil.isEditable(fEditor)) - return; - IFunction method= getSingleSelectedMethod(selection); - if (RefactoringAvailabilityTester.isChangeSignatureAvailable(method)){ - RefactoringExecutionStarter.startChangeSignatureRefactoring(method, this, getShell()); - } else { - MessageDialog.openInformation(getShell(), RefactoringMessages.OpenRefactoringWizardAction_unavailable, RefactoringMessages.ModifyParametersAction_unavailable); - } - } catch (JavaScriptModelException e) { - ExceptionHandler.handle(e, RefactoringMessages.OpenRefactoringWizardAction_refactoring, RefactoringMessages.OpenRefactoringWizardAction_exception); - } - } - - private static IFunction getSingleSelectedMethod(IStructuredSelection selection){ - if (selection.isEmpty() || selection.size() != 1) - return null; - if (selection.getFirstElement() instanceof IFunction) - return (IFunction)selection.getFirstElement(); - return null; - } - - private IFunction getSingleSelectedMethod(ITextSelection selection) throws JavaScriptModelException{ - //- when caret/selection on method name (call or declaration) -> that method - //- otherwise: caret position's enclosing method declaration - // - when caret inside argument list of method declaration -> enclosing method declaration - // - when caret inside argument list of method call -> enclosing method declaration (and NOT method call) - IJavaScriptElement[] elements= SelectionConverter.codeResolve(fEditor); - if (elements.length > 1) - return null; - if (elements.length == 1 && elements[0] instanceof IFunction) - return (IFunction)elements[0]; - IJavaScriptElement elementAt= SelectionConverter.getInputAsCompilationUnit(fEditor).getElementAt(selection.getOffset()); - if (elementAt instanceof IFunction) - return (IFunction)elementAt; - return null; - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/MoveAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/MoveAction.java deleted file mode 100644 index ee821c95..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/MoveAction.java +++ /dev/null @@ -1,256 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.IMember; -import org.eclipse.wst.jsdt.core.IFunction; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.internal.corext.refactoring.RefactoringAvailabilityTester; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.refactoring.RefactoringMessages; -import org.eclipse.wst.jsdt.internal.ui.refactoring.actions.MoveInstanceMethodAction; -import org.eclipse.wst.jsdt.internal.ui.refactoring.actions.MoveStaticMembersAction; -import org.eclipse.wst.jsdt.internal.ui.refactoring.reorg.ReorgMoveAction; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; - -/** - * This action moves JavaScript elements to a new location. The action prompts - * the user for the new location. - * <p> - * The action is applicable to a homogeneous selection containing either - * projects, package fragment roots, package fragments, compilation units, - * or static methods. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class MoveAction extends SelectionDispatchAction{ -//TODO: remove duplicate availability checks. Look at -//- f...Action.selectionChanged -//- f...Action.isEnabled -//- ...Refactoring.isAvailable -//- try... -//... and remove duplicated code for text/structured selections. -//We have to clean this up, once we have a long term solution to -//bug 35748 (no JavaElements for local types). - - private JavaEditor fEditor; - private MoveInstanceMethodAction fMoveInstanceMethodAction; - private MoveStaticMembersAction fMoveStaticMembersAction; - private ReorgMoveAction fReorgMoveAction; - - /** - * Creates a new <code>MoveAction</code>. The action requires - * that the selection provided by the site's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public MoveAction(IWorkbenchSite site) { - super(site); - setText(RefactoringMessages.MoveAction_text); - fMoveStaticMembersAction= new MoveStaticMembersAction(site); - fMoveInstanceMethodAction= new MoveInstanceMethodAction(site); - fReorgMoveAction= new ReorgMoveAction(site); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.MOVE_ACTION); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public MoveAction(JavaEditor editor) { - super(editor.getEditorSite()); - fEditor= editor; - setText(RefactoringMessages.MoveAction_text); - fMoveStaticMembersAction= new MoveStaticMembersAction(editor); - fMoveInstanceMethodAction= new MoveInstanceMethodAction(editor); - fReorgMoveAction= new ReorgMoveAction(editor.getEditorSite()); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.MOVE_ACTION); - } - - /* - * @see ISelectionChangedListener#selectionChanged(SelectionChangedEvent) - */ - public void selectionChanged(SelectionChangedEvent event) { - fMoveStaticMembersAction.selectionChanged(event); - fMoveInstanceMethodAction.selectionChanged(event); - fReorgMoveAction.selectionChanged(event); - setEnabled(computeEnableState()); - } - - /* - * @see org.eclipse.wst.jsdt.ui.actions.SelectionDispatchAction#run(org.eclipse.jface.viewers.IStructuredSelection) - */ - public void run(IStructuredSelection selection) { - try { - if (fMoveInstanceMethodAction.isEnabled() && tryMoveInstanceMethod(selection)) - return; - - if (fMoveStaticMembersAction.isEnabled() && tryMoveStaticMembers(selection)) - return; - - if (fReorgMoveAction.isEnabled()) - fReorgMoveAction.run(); - - } catch (JavaScriptModelException e) { - ExceptionHandler.handle(e, RefactoringMessages.OpenRefactoringWizardAction_refactoring, RefactoringMessages.OpenRefactoringWizardAction_exception); - } - - } - - /* - * @see org.eclipse.wst.jsdt.ui.actions.SelectionDispatchAction#run(org.eclipse.jface.text.ITextSelection) - */ - public void run(ITextSelection selection) { - try { - if (!ActionUtil.isEditable(fEditor)) - return; - if (fMoveStaticMembersAction.isEnabled() && tryMoveStaticMembers(selection)) - return; - - if (fMoveInstanceMethodAction.isEnabled() && tryMoveInstanceMethod(selection)) - return; - - if (tryReorgMove(selection)) - return; - - MessageDialog.openInformation(getShell(), RefactoringMessages.MoveAction_Move, RefactoringMessages.MoveAction_select); - } catch (JavaScriptModelException e) { - ExceptionHandler.handle(e, RefactoringMessages.OpenRefactoringWizardAction_refactoring, RefactoringMessages.OpenRefactoringWizardAction_exception); - } - } - - private boolean tryMoveStaticMembers(ITextSelection selection) throws JavaScriptModelException { - IJavaScriptElement element= SelectionConverter.getElementAtOffset(fEditor); - if (element == null || !(element instanceof IMember)) - return false; - IMember[] array= new IMember[] { (IMember) element}; - if (!RefactoringAvailabilityTester.isMoveStaticMembersAvailable(array)) - return false; - fMoveStaticMembersAction.run(selection); - return true; - } - - private static IMember[] getSelectedMembers(IStructuredSelection selection){ - if (selection.isEmpty()) - return null; - - for (Iterator iter= selection.iterator(); iter.hasNext(); ) { - if (! (iter.next() instanceof IMember)) - return null; - } - return convertToMemberArray(selection.toArray()); - } - - private static IMember[] convertToMemberArray(Object[] obj) { - if (obj == null) - return null; - Set memberSet= new HashSet(); - memberSet.addAll(Arrays.asList(obj)); - return (IMember[]) memberSet.toArray(new IMember[memberSet.size()]); - } - - private boolean tryMoveStaticMembers(IStructuredSelection selection) throws JavaScriptModelException { - IMember[] array= getSelectedMembers(selection); - if (!RefactoringAvailabilityTester.isMoveStaticMembersAvailable(array)) - return false; - fMoveStaticMembersAction.run(selection); - return true; - } - - private boolean tryMoveInstanceMethod(ITextSelection selection) throws JavaScriptModelException { - IJavaScriptElement element= SelectionConverter.getElementAtOffset(fEditor); - if (element == null || !(element instanceof IFunction)) - return false; - - IFunction method= (IFunction) element; - if (!RefactoringAvailabilityTester.isMoveMethodAvailable(method)) - return false; - fMoveInstanceMethodAction.run(selection); - return true; - } - - private boolean tryMoveInstanceMethod(IStructuredSelection selection) throws JavaScriptModelException { - IFunction method= getSingleSelectedMethod(selection); - if (method == null) - return false; - if (!RefactoringAvailabilityTester.isMoveMethodAvailable(method)) - return false; - fMoveInstanceMethodAction.run(selection); - return true; - } - - private static IFunction getSingleSelectedMethod(IStructuredSelection selection) { - if (selection.isEmpty() || selection.size() != 1) - return null; - - Object first= selection.getFirstElement(); - if (! (first instanceof IFunction)) - return null; - return (IFunction) first; - } - - - private boolean tryReorgMove(ITextSelection selection) throws JavaScriptModelException{ - IJavaScriptElement element= SelectionConverter.getElementAtOffset(fEditor); - if (element == null) - return false; - StructuredSelection mockStructuredSelection= new StructuredSelection(element); - fReorgMoveAction.selectionChanged(mockStructuredSelection); - if (!fReorgMoveAction.isEnabled()) - return false; - - fReorgMoveAction.run(mockStructuredSelection); - return true; - } - - - /* - * @see SelectionDispatchAction#update(ISelection) - */ - public void update(ISelection selection) { - fMoveStaticMembersAction.update(selection); - fMoveInstanceMethodAction.update(selection); - fReorgMoveAction.update(selection); - setEnabled(computeEnableState()); - } - - private boolean computeEnableState(){ - return fMoveStaticMembersAction.isEnabled() - || fMoveInstanceMethodAction.isEnabled() - || fReorgMoveAction.isEnabled(); - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/NavigateActionGroup.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/NavigateActionGroup.java deleted file mode 100644 index c6ed66c1..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/NavigateActionGroup.java +++ /dev/null @@ -1,107 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.actions.ActionContext; -import org.eclipse.ui.actions.ActionGroup; - -/** - * Action group that adds the open and show actions to a context menu and - * the action bar's navigate menu. This action group reuses the <code> - * OpenEditorActionGroup</code> and <code>OpenViewActionGroup</code>. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class NavigateActionGroup extends ActionGroup { - - private OpenEditorActionGroup fOpenEditorActionGroup; - private OpenViewActionGroup fOpenViewActionGroup; - - /** - * Creates a new <code>NavigateActionGroup</code>. The group requires - * that the selection provided by the part's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param part the view part that owns this action group - */ - public NavigateActionGroup(IViewPart part) { - fOpenEditorActionGroup= new OpenEditorActionGroup(part); - fOpenViewActionGroup= new OpenViewActionGroup(part); - } - - /** - * Returns the open action managed by this action group. - * - * @return the open action. Returns <code>null</code> if the group - * doesn't provide any open action - */ - public IAction getOpenAction() { - return fOpenEditorActionGroup.getOpenAction(); - } - - /* (non-Javadoc) - * Method declared in ActionGroup - */ - public void dispose() { - super.dispose(); - fOpenEditorActionGroup.dispose(); - fOpenViewActionGroup.dispose(); - } - - /* (non-Javadoc) - * Method declared in ActionGroup - */ - public void fillActionBars(IActionBars actionBars) { - super.fillActionBars(actionBars); - fOpenEditorActionGroup.fillActionBars(actionBars); - fOpenViewActionGroup.fillActionBars(actionBars); - } - - /* (non-Javadoc) - * Method declared in ActionGroup - */ - public void fillContextMenu(IMenuManager menu) { - super.fillContextMenu(menu); - - fOpenEditorActionGroup.fillContextMenu(menu); - fOpenViewActionGroup.fillContextMenu(menu); - } - - /* (non-Javadoc) - * Method declared in ActionGroup - */ - public void setContext(ActionContext context) { - super.setContext(context); - fOpenEditorActionGroup.setContext(context); - fOpenViewActionGroup.setContext(context); - } - - /* (non-Javadoc) - * Method declared in ActionGroup - */ - public void updateActionBars() { - super.updateActionBars(); - fOpenEditorActionGroup.updateActionBars(); - fOpenViewActionGroup.updateActionBars(); - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OccurrencesSearchGroup.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OccurrencesSearchGroup.java deleted file mode 100644 index 230942f9..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OccurrencesSearchGroup.java +++ /dev/null @@ -1,192 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.actions.ActionGroup; -import org.eclipse.ui.keys.IBindingService; -import org.eclipse.ui.texteditor.ITextEditorActionConstants; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.search.SearchMessages; -import org.eclipse.wst.jsdt.ui.IContextMenuConstants; - -/** - * Action group that adds the occurrences in file actions - * to a context menu and the global menu bar. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class OccurrencesSearchGroup extends ActionGroup { - - private IWorkbenchSite fSite; - private JavaEditor fEditor; - private IActionBars fActionBars; - - private String fGroupId; - - private FindOccurrencesInFileAction fOccurrencesInFileAction; - private FindExceptionOccurrencesAction fExceptionOccurrencesAction; - private FindImplementOccurrencesAction fFindImplementorOccurrencesAction; - - /** - * Creates a new <code>ImplementorsSearchGroup</code>. The group - * requires that the selection provided by the site's selection provider - * is of type <code>org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the view part that owns this action group - */ - public OccurrencesSearchGroup(IWorkbenchSite site) { - fSite= site; - fGroupId= IContextMenuConstants.GROUP_SEARCH; - - fOccurrencesInFileAction= new FindOccurrencesInFileAction(site); - fOccurrencesInFileAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_OCCURRENCES_IN_FILE); - // Need to reset the label - fOccurrencesInFileAction.setText(SearchMessages.Search_FindOccurrencesInFile_shortLabel); - - fExceptionOccurrencesAction= new FindExceptionOccurrencesAction(site); - fExceptionOccurrencesAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_EXCEPTION_OCCURRENCES_IN_FILE); - - fFindImplementorOccurrencesAction= new FindImplementOccurrencesAction(site); - fFindImplementorOccurrencesAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_IMPLEMENT_OCCURRENCES_IN_FILE); - - // register the actions as selection listeners - ISelectionProvider provider= fSite.getSelectionProvider(); - ISelection selection= provider.getSelection(); - registerAction(fOccurrencesInFileAction, provider, selection); - registerAction(fExceptionOccurrencesAction, provider, selection); - registerAction(fFindImplementorOccurrencesAction, provider, selection); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * - * @param editor the JavaScript editor - */ - public OccurrencesSearchGroup(JavaEditor editor) { - fEditor= editor; - fSite= fEditor.getSite(); - fGroupId= ITextEditorActionConstants.GROUP_FIND; - - fOccurrencesInFileAction= new FindOccurrencesInFileAction(fEditor); - fOccurrencesInFileAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_OCCURRENCES_IN_FILE); - // Need to reset the label - fOccurrencesInFileAction.setText(SearchMessages.Search_FindOccurrencesInFile_shortLabel); - fEditor.setAction("SearchOccurrencesInFile", fOccurrencesInFileAction); //$NON-NLS-1$ - - fExceptionOccurrencesAction= new FindExceptionOccurrencesAction(fEditor); - fExceptionOccurrencesAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_EXCEPTION_OCCURRENCES_IN_FILE); - fEditor.setAction("SearchExceptionOccurrences", fExceptionOccurrencesAction); //$NON-NLS-1$ - - fFindImplementorOccurrencesAction= new FindImplementOccurrencesAction(fEditor); - fFindImplementorOccurrencesAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_IMPLEMENT_OCCURRENCES_IN_FILE); - fEditor.setAction("SearchImplementOccurrences", fFindImplementorOccurrencesAction); //$NON-NLS-1$ - } - - private void registerAction(SelectionDispatchAction action, ISelectionProvider provider, ISelection selection){ - action.update(selection); - provider.addSelectionChangedListener(action); - } - - private IAction[] getActions() { - IAction[] actions= new IAction[3]; - actions[0]= fOccurrencesInFileAction; - actions[1]= fExceptionOccurrencesAction; - actions[2]= fFindImplementorOccurrencesAction; - return actions; - } - - /* - * Method declared on ActionGroup. - */ - public void fillContextMenu(IMenuManager manager) { - String menuText= SearchMessages.group_occurrences; - String shortcut= getShortcutString(); - if (shortcut != null) { - menuText= menuText + '\t' + shortcut; - } - - MenuManager javaSearchMM= new MenuManager(menuText, IContextMenuConstants.GROUP_SEARCH); - IAction[] actions= getActions(); - for (int i= 0; i < actions.length; i++) { - IAction action= actions[i]; - if (action.isEnabled()) - javaSearchMM.add(action); - } - - if (!javaSearchMM.isEmpty()) - manager.appendToGroup(fGroupId, javaSearchMM); - } - - private String getShortcutString() { - IBindingService bindingService= (IBindingService)PlatformUI.getWorkbench().getAdapter(IBindingService.class); - if (bindingService == null) - return null; - return bindingService.getBestActiveBindingFormattedFor(IJavaEditorActionDefinitionIds.SEARCH_OCCURRENCES_IN_FILE_QUICK_MENU); - } - - /* - * Method declared on ActionGroup. - */ - public void fillActionBars(IActionBars actionBars) { - Assert.isNotNull(actionBars); - super.fillActionBars(actionBars); - fActionBars= actionBars; - updateGlobalActionHandlers(); - } - - /* - * Method declared on ActionGroup. - */ - public void dispose() { - ISelectionProvider provider= fSite.getSelectionProvider(); - if (provider != null) { - disposeAction(fFindImplementorOccurrencesAction, provider); - disposeAction(fExceptionOccurrencesAction, provider); - disposeAction(fOccurrencesInFileAction, provider); - } - super.dispose(); - fFindImplementorOccurrencesAction= null; - fExceptionOccurrencesAction= null; - fOccurrencesInFileAction= null; - updateGlobalActionHandlers(); - } - - private void updateGlobalActionHandlers() { - if (fActionBars != null) { - fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_OCCURRENCES_IN_FILE, fOccurrencesInFileAction); -// fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_EXCEPTION_OCCURRENCES, fExceptionOccurrencesAction); -// fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_IMPLEMENT_OCCURRENCES, fFindImplementorOccurrencesAction); - } - } - - private void disposeAction(ISelectionChangedListener action, ISelectionProvider provider) { - if (action != null) - provider.removeSelectionChangedListener(action); - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OpenAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OpenAction.java deleted file mode 100644 index 61aef244..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OpenAction.java +++ /dev/null @@ -1,225 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.lang.reflect.InvocationTargetException; -import java.util.Iterator; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.util.OpenStrategy; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.texteditor.IEditorStatusLine; -import org.eclipse.wst.jsdt.core.IJavaScriptUnit; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.ISourceReference; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.internal.corext.util.JavaModelUtil; -import org.eclipse.wst.jsdt.internal.corext.util.Messages; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.EditorUtility; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; -import org.eclipse.wst.jsdt.internal.ui.viewsupport.JavaUILabelProvider; -import org.eclipse.wst.jsdt.ui.JavaScriptUI; - -/** - * This action opens a JavaScript editor on a JavaScript element or file. - * <p> - * The action is applicable to selections containing elements of - * type <code>IJavaScriptUnit</code>, <code>IMember</code> - * or <code>IFile</code>. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class OpenAction extends SelectionDispatchAction { - - private JavaEditor fEditor; - - /** - * Creates a new <code>OpenAction</code>. The action requires - * that the selection provided by the site's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public OpenAction(IWorkbenchSite site) { - super(site); - setText(ActionMessages.OpenAction_label); - setToolTipText(ActionMessages.OpenAction_tooltip); - setDescription(ActionMessages.OpenAction_description); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.OPEN_ACTION); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public OpenAction(JavaEditor editor) { - this(editor.getEditorSite()); - fEditor= editor; - setText(ActionMessages.OpenAction_declaration_label); - setEnabled(EditorUtility.getEditorInputJavaElement(fEditor, false) != null); - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void selectionChanged(ITextSelection selection) { - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void selectionChanged(IStructuredSelection selection) { - setEnabled(checkEnabled(selection)); - } - - private boolean checkEnabled(IStructuredSelection selection) { - if (selection.isEmpty()) - return false; - for (Iterator iter= selection.iterator(); iter.hasNext();) { - Object element= iter.next(); - if (element instanceof ISourceReference) - continue; - if (element instanceof IFile) - continue; - if (JavaModelUtil.isOpenableStorage(element)) - continue; - return false; - } - return true; - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void run(ITextSelection selection) { - if (!isProcessable()) - return; - try { - IJavaScriptElement[] elements= SelectionConverter.codeResolveForked(fEditor, false); - if (elements == null || elements.length == 0) { - IEditorStatusLine statusLine= (IEditorStatusLine) fEditor.getAdapter(IEditorStatusLine.class); - if (statusLine != null) - statusLine.setMessage(true, ActionMessages.OpenAction_error_messageBadSelection, null); - getShell().getDisplay().beep(); - return; - } - IJavaScriptElement element= elements[0]; - if (elements.length > 1) { - element= SelectionConverter.selectJavaElement(elements, getShell(), getDialogTitle(), ActionMessages.OpenAction_select_element); - if (element == null) - return; - } - - if (element!=null) - { - int type= element.getElementType(); - if (type == IJavaScriptElement.JAVASCRIPT_PROJECT || type == IJavaScriptElement.PACKAGE_FRAGMENT_ROOT || type == IJavaScriptElement.PACKAGE_FRAGMENT) - element= EditorUtility.getEditorInputJavaElement(fEditor, false); - run(new Object[] {element} ); - } - } catch (InvocationTargetException e) { - ExceptionHandler.handle(e, getShell(), getDialogTitle(), ActionMessages.OpenAction_error_message); - } catch (InterruptedException e) { - // ignore - } - } - - private boolean isProcessable() { - if (fEditor != null) { - IJavaScriptElement je= EditorUtility.getEditorInputJavaElement(fEditor, false); - if (je instanceof IJavaScriptUnit && !JavaModelUtil.isPrimary((IJavaScriptUnit)je)) - return true; // can process non-primary working copies - } - return ActionUtil.isProcessable(fEditor); - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void run(IStructuredSelection selection) { - if (!checkEnabled(selection)) - return; - run(selection.toArray()); - } - - /** - * Note: this method is for internal use only. Clients should not call this method. - * - * @param elements the elements to process - */ - public void run(Object[] elements) { - if (elements == null) - return; - - MultiStatus status= new MultiStatus(JavaScriptUI.ID_PLUGIN, IStatus.OK, ActionMessages.OpenAction_multistatus_message, null); - - for (int i= 0; i < elements.length; i++) { - Object element= elements[i]; - try { - element= getElementToOpen(element); - boolean activateOnOpen= fEditor != null ? true : OpenStrategy.activateOnOpen(); - IEditorPart part= EditorUtility.openInEditor(element, activateOnOpen); - if (part != null && element instanceof IJavaScriptElement) - JavaScriptUI.revealInEditor(part, (IJavaScriptElement)element); - } catch (PartInitException e) { - String message= Messages.format(ActionMessages.OpenAction_error_problem_opening_editor, new String[] { new JavaUILabelProvider().getText(element), e.getStatus().getMessage() }); - status.add(new Status(IStatus.ERROR, JavaScriptUI.ID_PLUGIN, IStatus.ERROR, message, null)); - } catch (CoreException e) { - String message= Messages.format(ActionMessages.OpenAction_error_problem_opening_editor, new String[] { new JavaUILabelProvider().getText(element), e.getStatus().getMessage() }); - status.add(new Status(IStatus.ERROR, JavaScriptUI.ID_PLUGIN, IStatus.ERROR, message, null)); - JavaScriptPlugin.log(e); - } - } - if (!status.isOK()) { - IStatus[] children= status.getChildren(); - ErrorDialog.openError(getShell(), getDialogTitle(), ActionMessages.OpenAction_error_message, children.length == 1 ? children[0] : status); - } - } - - /** - * Note: this method is for internal use only. Clients should not call this method. - * - * @param object the element to open - * @return the real element to open - * @throws JavaScriptModelException if an error occurs while accessing the JavaScript model - */ - public Object getElementToOpen(Object object) throws JavaScriptModelException { - return object; - } - - private String getDialogTitle() { - return ActionMessages.OpenAction_error_title; - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OpenEditorActionGroup.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OpenEditorActionGroup.java deleted file mode 100644 index f5099ede..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OpenEditorActionGroup.java +++ /dev/null @@ -1,157 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.actions.ActionGroup; -import org.eclipse.ui.actions.OpenWithMenu; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.ui.IContextMenuConstants; - -/** - * Action group that adds the actions opening a new editor to the - * context menu and the action bar's navigate menu. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class OpenEditorActionGroup extends ActionGroup { - - private IWorkbenchSite fSite; - private boolean fIsEditorOwner; - private OpenAction fOpen; - - /** - * Creates a new <code>OpenActionGroup</code>. The group requires - * that the selection provided by the part's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param part the view part that owns this action group - */ - public OpenEditorActionGroup(IViewPart part) { - fSite= part.getSite(); - fOpen= new OpenAction(fSite); - fOpen.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_EDITOR); - initialize(fSite.getSelectionProvider()); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public OpenEditorActionGroup(JavaEditor editor) { - fIsEditorOwner= true; - fOpen= new OpenAction(editor); - fOpen.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_EDITOR); - editor.setAction("OpenEditor", fOpen); //$NON-NLS-1$ - fSite= editor.getEditorSite(); - initialize(fSite.getSelectionProvider()); - } - - /** - * Returns the open action managed by this action group. - * - * @return the open action. Returns <code>null</code> if the group - * doesn't provide any open action - */ - public IAction getOpenAction() { - return fOpen; - } - - private void initialize(ISelectionProvider provider) { - ISelection selection= provider.getSelection(); - fOpen.update(selection); - if (!fIsEditorOwner) { - provider.addSelectionChangedListener(fOpen); - } - } - - /* (non-Javadoc) - * Method declared in ActionGroup - */ - public void fillActionBars(IActionBars actionBar) { - super.fillActionBars(actionBar); - setGlobalActionHandlers(actionBar); - } - - /* (non-Javadoc) - * Method declared in ActionGroup - */ - public void fillContextMenu(IMenuManager menu) { - super.fillContextMenu(menu); - appendToGroup(menu, fOpen); - if (!fIsEditorOwner) { - addOpenWithMenu(menu); - } - } - - /* - * @see ActionGroup#dispose() - */ - public void dispose() { - ISelectionProvider provider= fSite.getSelectionProvider(); - provider.removeSelectionChangedListener(fOpen); - super.dispose(); - } - - private void setGlobalActionHandlers(IActionBars actionBars) { - actionBars.setGlobalActionHandler(JdtActionConstants.OPEN, fOpen); - } - - private void appendToGroup(IMenuManager menu, IAction action) { - if (action.isEnabled()) - menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, action); - } - - private void addOpenWithMenu(IMenuManager menu) { - ISelection selection= getContext().getSelection(); - if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) - return; - IStructuredSelection ss= (IStructuredSelection)selection; - if (ss.size() != 1) - return; - - Object o= ss.getFirstElement(); - if (!(o instanceof IAdaptable)) - return; - - IAdaptable element= (IAdaptable)o; - Object resource= element.getAdapter(IResource.class); - if (!(resource instanceof IFile)) - return; - - // Create a menu. - IMenuManager submenu= new MenuManager(ActionMessages.OpenWithMenu_label); - submenu.add(new OpenWithMenu(fSite.getPage(), (IFile) resource)); - - // Add the submenu. - menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, submenu); - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OpenExternalJavadocAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OpenExternalJavadocAction.java deleted file mode 100644 index 41682e12..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OpenExternalJavadocAction.java +++ /dev/null @@ -1,202 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.lang.reflect.InvocationTargetException; -import java.net.URL; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.IPackageFragmentRoot; -import org.eclipse.wst.jsdt.internal.corext.util.JavaModelUtil; -import org.eclipse.wst.jsdt.internal.corext.util.Messages; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.OpenBrowserUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; -import org.eclipse.wst.jsdt.ui.JavaScriptElementLabels; -import org.eclipse.wst.jsdt.ui.JavaScriptUI; - -/** - * This action opens the selected element's Javadoc in an external - * browser. - * <p> - * The action is applicable to selections containing elements of - * type <code>IJavaScriptElement</code>. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class OpenExternalJavadocAction extends SelectionDispatchAction { - - private JavaEditor fEditor; - - /** - * Creates a new <code>OpenExternalJavadocAction</code>. The action requires - * that the selection provided by the site's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing additional context information for this action - */ - public OpenExternalJavadocAction(IWorkbenchSite site) { - super(site); - setText(ActionMessages.OpenExternalJavadocAction_label); - setDescription(ActionMessages.OpenExternalJavadocAction_description); - setToolTipText(ActionMessages.OpenExternalJavadocAction_tooltip); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.OPEN_EXTERNAL_JAVADOC_ACTION); - } - - - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public OpenExternalJavadocAction(JavaEditor editor) { - this(editor.getEditorSite()); - fEditor= editor; - setEnabled(SelectionConverter.canOperateOn(fEditor)); - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void selectionChanged(ITextSelection selection) { - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void selectionChanged(IStructuredSelection selection) { - setEnabled(checkEnabled(selection)); - } - - private boolean checkEnabled(IStructuredSelection selection) { - if (selection.size() != 1) - return false; - return selection.getFirstElement() instanceof IJavaScriptElement; - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void run(ITextSelection selection) { - IJavaScriptElement element= SelectionConverter.getInput(fEditor); - if (!ActionUtil.isProcessable(getShell(), element)) - return; - - try { - IJavaScriptElement[] elements= SelectionConverter.codeResolveOrInputForked(fEditor); - if (elements == null || elements.length == 0) - return; - IJavaScriptElement candidate= elements[0]; - if (elements.length > 1) { - candidate= SelectionConverter.selectJavaElement(elements, getShell(), getDialogTitle(), ActionMessages.OpenExternalJavadocAction_select_element); - } - if (candidate != null) { - run(candidate); - } - } catch (InvocationTargetException e) { - ExceptionHandler.handle(e, getShell(), getDialogTitle(), ActionMessages.OpenExternalJavadocAction_code_resolve_failed); - } catch (InterruptedException e) { - // cancelled - } - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void run(IStructuredSelection selection) { - if (!checkEnabled(selection)) - return; - IJavaScriptElement element= (IJavaScriptElement)selection.getFirstElement(); - if (!ActionUtil.isProcessable(getShell(), element)) - return; - run(element); - } - - /* - * No Javadoc since the method isn't meant to be public but is - * since the beginning - */ - public void run(IJavaScriptElement element) { - if (element == null) - return; - Shell shell= getShell(); - try { - String labelName= JavaScriptElementLabels.getElementLabel(element, JavaScriptElementLabels.ALL_DEFAULT); - - URL baseURL= JavaScriptUI.getJSdocBaseLocation(element); - if (baseURL == null) { - IPackageFragmentRoot root= JavaModelUtil.getPackageFragmentRoot(element); - if (root != null && root.getKind() == IPackageFragmentRoot.K_BINARY) { - String message= ActionMessages.OpenExternalJavadocAction_libraries_no_location; - showMessage(shell, Messages.format(message, new String[] { labelName, root.getElementName() }), false); - } else { - IJavaScriptElement annotatedElement= element.getJavaScriptProject(); - String message= ActionMessages.OpenExternalJavadocAction_source_no_location; - showMessage(shell, Messages.format(message, new String[] { labelName, annotatedElement.getElementName() }), false); - } - return; - } - URL url= JavaScriptUI.getJSdocLocation(element, true); - if (url != null) { - OpenBrowserUtil.open(url, shell.getDisplay(), getTitle()); - } - } catch (CoreException e) { - JavaScriptPlugin.log(e); - showMessage(shell, ActionMessages.OpenExternalJavadocAction_opening_failed, true); - } - } - - private static void showMessage(final Shell shell, final String message, final boolean isError) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (isError) { - MessageDialog.openError(shell, getTitle(), message); - } else { - MessageDialog.openInformation(shell, getTitle(), message); - } - } - }); - } - - private static String getTitle() { - return ActionMessages.OpenExternalJavadocAction_dialog_title; - } - - /** - * Note: this method is for internal use only. Clients should not call this method. - * - * @return the dialog default title - */ - protected String getDialogTitle() { - return getTitle(); - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OpenJavaPerspectiveAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OpenJavaPerspectiveAction.java deleted file mode 100644 index 04bd532f..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OpenJavaPerspectiveAction.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.jface.action.Action; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.WorkbenchException; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; -import org.eclipse.wst.jsdt.ui.JavaScriptUI; - -/** - * Action to programmatically open a JavaScript perspective. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class OpenJavaPerspectiveAction extends Action { - - /** - * Create a new <code>OpenJavaPerspectiveAction</code>. - */ - public OpenJavaPerspectiveAction() { - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.OPEN_JAVA_PERSPECTIVE_ACTION); - } - - public void run() { - IWorkbench workbench= JavaScriptPlugin.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(JavaScriptUI.ID_PERSPECTIVE, window, input); - } catch (WorkbenchException e) { - ExceptionHandler.handle(e, window.getShell(), - ActionMessages.OpenJavaPerspectiveAction_dialog_title, - ActionMessages.OpenJavaPerspectiveAction_error_open_failed); - } - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OpenNewClassWizardAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OpenNewClassWizardAction.java deleted file mode 100644 index c203641d..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OpenNewClassWizardAction.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.ui.INewWizard; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaPluginImages; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages; -import org.eclipse.wst.jsdt.internal.ui.wizards.NewClassCreationWizard; -import org.eclipse.wst.jsdt.ui.wizards.NewClassWizardPage; - -/** - * <p>Action that opens the new class wizard. The action initialized the wizard with either the selection - * as configured by {@link #setSelection(org.eclipse.jface.viewers.IStructuredSelection)} or takes a preconfigured - * new class wizard page, see {@link #setConfiguredWizardPage(NewClassWizardPage)}.</p> - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class OpenNewClassWizardAction extends AbstractOpenWizardAction { - - private NewClassWizardPage fPage; - private boolean fOpenEditorOnFinish; - - /** - * Creates an instance of the <code>OpenNewClassWizardAction</code>. - */ - public OpenNewClassWizardAction() { - setText(ActionMessages.OpenNewClassWizardAction_text); - setDescription(ActionMessages.OpenNewClassWizardAction_description); - setToolTipText(ActionMessages.OpenNewClassWizardAction_tooltip); - setImageDescriptor(JavaPluginImages.DESC_WIZBAN_NEWCLASS); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.OPEN_CLASS_WIZARD_ACTION); - - fPage= null; - fOpenEditorOnFinish= true; - } - - /** - * Sets a page to be used by the wizard or <code>null</code> to use a page initialized with values - * from the current selection (see {@link #getSelection()} and {@link #setSelection(org.eclipse.jface.viewers.IStructuredSelection)}). - * @param page the page to use or <code>null</code> - */ - public void setConfiguredWizardPage(NewClassWizardPage page) { - fPage= page; - } - - /** - * Specifies if the wizard will open the created type with the default editor. The default behaviour is to open - * an editor. - * - * @param openEditorOnFinish if set, the wizard will open the created type with the default editor - * - * - */ - public void setOpenEditorOnFinish(boolean openEditorOnFinish) { - fOpenEditorOnFinish= openEditorOnFinish; - } - - /* (non-Javadoc) - * @see org.eclipse.wst.jsdt.ui.actions.AbstractOpenWizardAction#createWizard() - */ - protected final INewWizard createWizard() throws CoreException { - return new NewClassCreationWizard(fPage, fOpenEditorOnFinish); - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OpenNewJavaProjectWizardAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OpenNewJavaProjectWizardAction.java deleted file mode 100644 index f5d1834f..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OpenNewJavaProjectWizardAction.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.INewWizard; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.JavaPluginImages; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages; -import org.eclipse.wst.jsdt.internal.ui.wizards.JavaProjectWizard; - -/** - * <p>Action that opens the new JavaScript project wizard. The action initializes the wizard with the - * selection as configured by {@link #setSelection(org.eclipse.jface.viewers.IStructuredSelection)} or the selection of - * the active workbench window.</p> - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class OpenNewJavaProjectWizardAction extends AbstractOpenWizardAction { - - /** - * Creates an instance of the <code>OpenNewJavaProjectWizardAction</code>. - */ - public OpenNewJavaProjectWizardAction() { - setText(ActionMessages.OpenNewJavaProjectWizardAction_text); - setDescription(ActionMessages.OpenNewJavaProjectWizardAction_description); - setToolTipText(ActionMessages.OpenNewJavaProjectWizardAction_tooltip); - setImageDescriptor(JavaPluginImages.DESC_WIZBAN_NEWJPRJ); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.OPEN_PROJECT_WIZARD_ACTION); - setShell(JavaScriptPlugin.getActiveWorkbenchShell()); - } - - /* (non-Javadoc) - * @see org.eclipse.wst.jsdt.ui.actions.AbstractOpenWizardAction#createWizard() - */ - protected final INewWizard createWizard() throws CoreException { - return new JavaProjectWizard(); - } - - /* (non-Javadoc) - * @see org.eclipse.wst.jsdt.ui.actions.AbstractOpenWizardAction#doCreateProjectFirstOnEmptyWorkspace(Shell) - */ - protected boolean doCreateProjectFirstOnEmptyWorkspace(Shell shell) { - return true; // can work on an empty workspace - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OpenProjectAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OpenProjectAction.java deleted file mode 100644 index 7f8b2639..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OpenProjectAction.java +++ /dev/null @@ -1,227 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResourceChangeEvent; -import org.eclipse.core.resources.IResourceChangeListener; -import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.jface.viewers.ArrayContentProvider; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.window.Window; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.IWorkingSet; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.actions.OpenResourceAction; -import org.eclipse.ui.dialogs.ListSelectionDialog; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages; -import org.eclipse.wst.jsdt.internal.ui.actions.WorkbenchRunnableAdapter; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; -import org.eclipse.wst.jsdt.ui.JavaScriptElementLabelProvider; - -/** - * Action to open a closed project. Action either opens the closed projects - * provided by the structured selection or presents a dialog from which the - * user can select the projects to be opened. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class OpenProjectAction extends SelectionDispatchAction implements IResourceChangeListener { - - private int CLOSED_PROJECTS_SELECTED= 1; - private int OTHER_ELEMENTS_SELECTED= 2; - - private OpenResourceAction fWorkbenchAction; - - /** - * Creates a new <code>OpenProjectAction</code>. The action requires - * that the selection provided by the site's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public OpenProjectAction(IWorkbenchSite site) { - super(site); - fWorkbenchAction= new OpenResourceAction(site.getShell()); - setText(fWorkbenchAction.getText()); - setToolTipText(fWorkbenchAction.getToolTipText()); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.OPEN_PROJECT_ACTION); - setEnabled(hasClosedProjectsInWorkspace()); - } - - /* - * @see IResourceChangeListener#resourceChanged(IResourceChangeEvent) - */ - public void resourceChanged(IResourceChangeEvent event) { - IResourceDelta delta = event.getDelta(); - if (delta != null) { - IResourceDelta[] projDeltas = delta.getAffectedChildren(IResourceDelta.CHANGED); - for (int i = 0; i < projDeltas.length; ++i) { - IResourceDelta projDelta = projDeltas[i]; - if ((projDelta.getFlags() & IResourceDelta.OPEN) != 0) { - setEnabled(hasClosedProjectsInWorkspace()); - return; - } - } - } - } - - //---- normal selection ------------------------------------- - - /* (non-Javadoc) - * @see org.eclipse.wst.jsdt.ui.actions.SelectionDispatchAction#selectionChanged(org.eclipse.jface.viewers.ISelection) - */ - public void selectionChanged(ISelection selection) { - } - - /* (non-Javadoc) - * @see org.eclipse.wst.jsdt.ui.actions.SelectionDispatchAction#run(org.eclipse.jface.viewers.ISelection) - */ - public void run(ISelection selection) { - internalRun(null); - } - - private int evaluateSelection(IStructuredSelection selection, List allClosedProjects) { - Object[] array= selection.toArray(); - int selectionStatus = 0; - for (int i= 0; i < array.length; i++) { - Object curr= array[i]; - if (isClosedProject(curr)) { - if (allClosedProjects != null) - allClosedProjects.add(curr); - selectionStatus |= CLOSED_PROJECTS_SELECTED; - } else { - if (curr instanceof IWorkingSet) { - IAdaptable[] elements= ((IWorkingSet) curr).getElements(); - for (int k= 0; k < elements.length; k++) { - Object elem= elements[k]; - if (isClosedProject(elem)) { - if (allClosedProjects != null) - allClosedProjects.add(elem); - selectionStatus |= CLOSED_PROJECTS_SELECTED; - } - } - } - selectionStatus |= OTHER_ELEMENTS_SELECTED; - } - - } - return selectionStatus; - } - - private static boolean isClosedProject(Object element) { - // assume all closed project are rendered as IProject - return element instanceof IProject && !((IProject) element).isOpen(); - } - - - //---- structured selection --------------------------------------- - - /* (non-Javadoc) - * @see org.eclipse.wst.jsdt.ui.actions.SelectionDispatchAction#run(org.eclipse.jface.viewers.IStructuredSelection) - */ - public void run(IStructuredSelection selection) { - ArrayList allClosedProjects= new ArrayList(); - int selectionStatus= evaluateSelection(selection, allClosedProjects); - if (selectionStatus == CLOSED_PROJECTS_SELECTED) { // only closed projects selected - fWorkbenchAction.selectionChanged(new StructuredSelection(allClosedProjects)); - fWorkbenchAction.run(); - } else { - internalRun(allClosedProjects); - } - } - - private void internalRun(List initialSelection) { - ListSelectionDialog dialog= new ListSelectionDialog(getShell(), getClosedProjectsInWorkspace(), new ArrayContentProvider(), new JavaScriptElementLabelProvider(), ActionMessages.OpenProjectAction_dialog_message); - dialog.setTitle(ActionMessages.OpenProjectAction_dialog_title); - if (initialSelection != null && !initialSelection.isEmpty()) { - dialog.setInitialElementSelections(initialSelection); - } - int result= dialog.open(); - if (result != Window.OK) - return; - final Object[] projects= dialog.getResult(); - IWorkspaceRunnable runnable= createRunnable(projects); - try { - PlatformUI.getWorkbench().getProgressService().run(true, true, new WorkbenchRunnableAdapter(runnable)); - } catch (InvocationTargetException e) { - ExceptionHandler.handle(e, getShell(), ActionMessages.OpenProjectAction_dialog_title, ActionMessages.OpenProjectAction_error_message); - } catch (InterruptedException e) { - // user cancelled - } - } - - private IWorkspaceRunnable createRunnable(final Object[] projects) { - return new IWorkspaceRunnable() { - public void run(IProgressMonitor monitor) throws CoreException { - monitor.beginTask("", projects.length); //$NON-NLS-1$ - MultiStatus errorStatus= null; - for (int i = 0; i < projects.length; i++) { - IProject project= (IProject)projects[i]; - try { - project.open(new SubProgressMonitor(monitor, 1)); - } catch (CoreException e) { - if (errorStatus == null) - errorStatus = new MultiStatus(JavaScriptPlugin.getPluginId(), IStatus.ERROR, ActionMessages.OpenProjectAction_error_message, null); - errorStatus.add(e.getStatus()); - } - } - monitor.done(); - if (errorStatus != null) - throw new CoreException(errorStatus); - } - }; - } - - private Object[] getClosedProjectsInWorkspace() { - IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects(); - List result= new ArrayList(5); - for (int i = 0; i < projects.length; i++) { - IProject project= projects[i]; - if (!project.isOpen()) - result.add(project); - } - return result.toArray(); - } - - private boolean hasClosedProjectsInWorkspace() { - IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects(); - for (int i = 0; i < projects.length; i++) { - if (!projects[i].isOpen()) - return true; - } - return false; - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OpenSuperImplementationAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OpenSuperImplementationAction.java deleted file mode 100644 index 69ad7147..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OpenSuperImplementationAction.java +++ /dev/null @@ -1,195 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.Flags; -import org.eclipse.wst.jsdt.core.IFunction; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.IType; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.internal.corext.util.Messages; -import org.eclipse.wst.jsdt.internal.corext.util.MethodOverrideTester; -import org.eclipse.wst.jsdt.internal.corext.util.SuperTypeHierarchyCache; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; -import org.eclipse.wst.jsdt.ui.JavaScriptUI; - -/** - * The action opens a JavaScript editor on the selected method's super implementation. - * <p> - * The action is applicable to selections containing elements of type <code> - * IFunction</code>. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class OpenSuperImplementationAction extends SelectionDispatchAction { - - private JavaEditor fEditor; - - /** - * Creates a new <code>OpenSuperImplementationAction</code>. The action requires - * that the selection provided by the site's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public OpenSuperImplementationAction(IWorkbenchSite site) { - super(site); - setText(ActionMessages.OpenSuperImplementationAction_label); - setDescription(ActionMessages.OpenSuperImplementationAction_description); - setToolTipText(ActionMessages.OpenSuperImplementationAction_tooltip); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.OPEN_SUPER_IMPLEMENTATION_ACTION); - } - - - - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public OpenSuperImplementationAction(JavaEditor editor) { - this(editor.getEditorSite()); - fEditor= editor; - setEnabled(SelectionConverter.canOperateOn(fEditor)); - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void selectionChanged(ITextSelection selection) { - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void selectionChanged(IStructuredSelection selection) { - IFunction method= getMethod(selection); - - setEnabled(method != null && checkMethod(method)); - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void run(ITextSelection selection) { - if (!ActionUtil.isProcessable(fEditor)) - return; - IJavaScriptElement element= elementAtOffset(); - if (element == null || !(element instanceof IFunction)) { - MessageDialog.openInformation(getShell(), getDialogTitle(), ActionMessages.OpenSuperImplementationAction_not_applicable); - return; - } - run((IFunction) element); - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void run(IStructuredSelection selection) { - run(getMethod(selection)); - } - - /* - * No Javadoc since the method isn't meant to be public but is - * since the beginning - */ - public void run(IFunction 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, method.getElementName())); - return; - } - - try { - IFunction impl= findSuperImplementation(method); - if (impl != null) { - JavaScriptUI.openInEditor(impl, true, true); - } - } catch (CoreException e) { - ExceptionHandler.handle(e, getDialogTitle(), ActionMessages.OpenSuperImplementationAction_error_message); - } - } - - private IFunction findSuperImplementation(IFunction method) throws JavaScriptModelException { - MethodOverrideTester tester= SuperTypeHierarchyCache.getMethodOverrideTester(method.getDeclaringType()); - return tester.findOverriddenMethod(method, false); - } - - - private IFunction getMethod(IStructuredSelection selection) { - if (selection.size() != 1) - return null; - Object element= selection.getFirstElement(); - if (element instanceof IFunction) { - return (IFunction) element; - } - return null; - } - - private boolean checkMethod(IFunction method) { - try { - int flags= method.getFlags(); - if (!Flags.isStatic(flags) && !Flags.isPrivate(flags)) { - IType declaringType= method.getDeclaringType(); - if (declaringType==null) - return false; - if (SuperTypeHierarchyCache.hasInCache(declaringType)) { - if (findSuperImplementation(method) == null) { - return false; - } - } - return true; - } - } catch (JavaScriptModelException e) { - if (!e.isDoesNotExist()) { - JavaScriptPlugin.log(e); - } - } - return false; - } - - private IJavaScriptElement elementAtOffset() { - try { - return SelectionConverter.getElementAtOffset(fEditor); - } catch(JavaScriptModelException e) { - } - return null; - } - - private static String getDialogTitle() { - return ActionMessages.OpenSuperImplementationAction_error_title; - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OpenTypeHierarchyAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OpenTypeHierarchyAction.java deleted file mode 100644 index 33b19f31..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OpenTypeHierarchyAction.java +++ /dev/null @@ -1,259 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IClassFile; -import org.eclipse.wst.jsdt.core.IImportDeclaration; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.IJavaScriptUnit; -import org.eclipse.wst.jsdt.core.IPackageFragment; -import org.eclipse.wst.jsdt.core.IType; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.core.Signature; -import org.eclipse.wst.jsdt.internal.corext.util.JavaModelUtil; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.IJavaStatusConstants; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.browsing.LogicalPackage; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; -import org.eclipse.wst.jsdt.internal.ui.util.OpenTypeHierarchyUtil; - -/** - * This action opens a type hierarchy on the selected type. - * <p> - * The action is applicable to selections containing elements of type - * <code>IType</code>. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class OpenTypeHierarchyAction extends SelectionDispatchAction { - - private JavaEditor fEditor; - - /** - * Creates a new <code>OpenTypeHierarchyAction</code>. The action requires - * that the selection provided by the site's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public OpenTypeHierarchyAction(IWorkbenchSite site) { - super(site); - setText(ActionMessages.OpenTypeHierarchyAction_label); - setToolTipText(ActionMessages.OpenTypeHierarchyAction_tooltip); - setDescription(ActionMessages.OpenTypeHierarchyAction_description); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.OPEN_TYPE_HIERARCHY_ACTION); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public OpenTypeHierarchyAction(JavaEditor editor) { - this(editor.getEditorSite()); - fEditor= editor; - setEnabled(SelectionConverter.canOperateOn(fEditor)); - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void selectionChanged(ITextSelection selection) { - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void selectionChanged(IStructuredSelection selection) { - setEnabled(isEnabled(selection)); - } - - private boolean isEnabled(IStructuredSelection selection) { - if (selection.size() != 1) - return false; - Object input= selection.getFirstElement(); - - - if (input instanceof LogicalPackage) - return true; - - if (!(input instanceof IJavaScriptElement)) - return false; - switch (((IJavaScriptElement)input).getElementType()) { - case IJavaScriptElement.INITIALIZER: - case IJavaScriptElement.METHOD: - case IJavaScriptElement.FIELD: - case IJavaScriptElement.TYPE: - return true; - case IJavaScriptElement.PACKAGE_FRAGMENT_ROOT: - case IJavaScriptElement.JAVASCRIPT_PROJECT: - case IJavaScriptElement.PACKAGE_FRAGMENT: - case IJavaScriptElement.IMPORT_DECLARATION: - case IJavaScriptElement.CLASS_FILE: - case IJavaScriptElement.JAVASCRIPT_UNIT: - return true; - case IJavaScriptElement.LOCAL_VARIABLE: - default: - return false; - } - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void run(ITextSelection selection) { - IJavaScriptElement input= SelectionConverter.getInput(fEditor); - if (!ActionUtil.isProcessable(getShell(), input)) - return; - - try { - IJavaScriptElement[] elements= SelectionConverter.codeResolveOrInputForked(fEditor); - if (elements == null) - return; - List candidates= new ArrayList(elements.length); - for (int i= 0; i < elements.length; i++) { - IJavaScriptElement[] resolvedElements= OpenTypeHierarchyUtil.getCandidates(elements[i]); - if (resolvedElements != null) - candidates.addAll(Arrays.asList(resolvedElements)); - } - run((IJavaScriptElement[])candidates.toArray(new IJavaScriptElement[candidates.size()])); - } catch (InvocationTargetException e) { - ExceptionHandler.handle(e, getShell(), getDialogTitle(), ActionMessages.SelectionConverter_codeResolve_failed); - } catch (InterruptedException e) { - // cancelled - } - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void run(IStructuredSelection selection) { - if (selection.size() != 1) - return; - Object input= selection.getFirstElement(); - - if (input instanceof LogicalPackage) { - IPackageFragment[] fragments= ((LogicalPackage)input).getFragments(); - if (fragments.length == 0) - return; - input= fragments[0]; - } - - if (!(input instanceof IJavaScriptElement)) { - IStatus status= createStatus(ActionMessages.OpenTypeHierarchyAction_messages_no_java_element); - ErrorDialog.openError(getShell(), getDialogTitle(), ActionMessages.OpenTypeHierarchyAction_messages_title, status); - return; - } - IJavaScriptElement element= (IJavaScriptElement) input; - if (!ActionUtil.isProcessable(getShell(), element)) - return; - - List result= new ArrayList(1); - IStatus status= compileCandidates(result, element); - if (status.isOK()) { - run((IJavaScriptElement[]) result.toArray(new IJavaScriptElement[result.size()])); - } else { - ErrorDialog.openError(getShell(), getDialogTitle(), ActionMessages.OpenTypeHierarchyAction_messages_title, status); - } - } - - /* - * No Javadoc since the method isn't meant to be public but is - * since the beginning - */ - public void run(IJavaScriptElement[] elements) { - if (elements.length == 0) { - getShell().getDisplay().beep(); - return; - } - OpenTypeHierarchyUtil.open(elements, getSite().getWorkbenchWindow()); - } - - private static String getDialogTitle() { - return ActionMessages.OpenTypeHierarchyAction_dialog_title; - } - - private static IStatus compileCandidates(List result, IJavaScriptElement elem) { - IStatus ok= new Status(IStatus.OK, JavaScriptPlugin.getPluginId(), 0, "", null); //$NON-NLS-1$ - try { - switch (elem.getElementType()) { - case IJavaScriptElement.INITIALIZER: - case IJavaScriptElement.METHOD: - case IJavaScriptElement.FIELD: - case IJavaScriptElement.TYPE: - case IJavaScriptElement.PACKAGE_FRAGMENT_ROOT: - case IJavaScriptElement.JAVASCRIPT_PROJECT: - result.add(elem); - return ok; - case IJavaScriptElement.PACKAGE_FRAGMENT: - if (((IPackageFragment)elem).containsJavaResources()) { - result.add(elem); - return ok; - } - return createStatus(ActionMessages.OpenTypeHierarchyAction_messages_no_java_resources); - case IJavaScriptElement.IMPORT_DECLARATION: - IImportDeclaration decl= (IImportDeclaration) elem; - if (decl.isOnDemand()) { - elem= JavaModelUtil.findTypeContainer(elem.getJavaScriptProject(), Signature.getQualifier(elem.getElementName())); - } else { - elem= elem.getJavaScriptProject().findType(elem.getElementName()); - } - if (elem != null) { - result.add(elem); - return ok; - } - return createStatus(ActionMessages.OpenTypeHierarchyAction_messages_unknown_import_decl); - case IJavaScriptElement.CLASS_FILE: - result.add(((IClassFile)elem).getType()); - return ok; - case IJavaScriptElement.JAVASCRIPT_UNIT: - IJavaScriptUnit cu= (IJavaScriptUnit)elem; - IType[] types= cu.getTypes(); - if (types.length > 0) { - result.addAll(Arrays.asList(types)); - return ok; - } - return createStatus(ActionMessages.OpenTypeHierarchyAction_messages_no_types); - } - } catch (JavaScriptModelException e) { - return e.getStatus(); - } - return createStatus(ActionMessages.OpenTypeHierarchyAction_messages_no_valid_java_element); - } - - private static IStatus createStatus(String message) { - return new Status(IStatus.INFO, JavaScriptPlugin.getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, message, null); - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OpenViewActionGroup.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OpenViewActionGroup.java deleted file mode 100644 index 9074ec09..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OpenViewActionGroup.java +++ /dev/null @@ -1,314 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.actions.ActionFactory; -import org.eclipse.ui.actions.ActionGroup; -import org.eclipse.ui.actions.ContributionItemFactory; -import org.eclipse.ui.dialogs.PropertyDialogAction; -import org.eclipse.ui.keys.IBindingService; -import org.eclipse.ui.part.Page; -import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages; -import org.eclipse.wst.jsdt.internal.ui.callhierarchy.OpenCallHierarchyAction; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.ui.IContextMenuConstants; - -/** - * Action group that adds actions to open a new JDT view part or an external - * viewer to a context menu and the global menu bar. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class OpenViewActionGroup extends ActionGroup { - - private boolean fEditorIsOwner; - private boolean fIsTypeHiararchyViewerOwner; - private boolean fIsCallHiararchyViewerOwner; - - private ISelectionProvider fSelectionProvider; - - private OpenSuperImplementationAction fOpenSuperImplementation; - private OpenExternalJavadocAction fOpenExternalJavadoc; - private OpenTypeHierarchyAction fOpenTypeHierarchy; - private OpenCallHierarchyAction fOpenCallHierarchy; - private PropertyDialogAction fOpenPropertiesDialog; - - private boolean fShowOpenPropertiesAction= true; - private boolean fShowShowInMenu= true; - - /** - * Creates a new <code>OpenActionGroup</code>. The group requires - * that the selection provided by the page's selection provider is - * of type {@link IStructuredSelection}. - * - * @param page the page that owns this action group - */ - public OpenViewActionGroup(Page page) { - createSiteActions(page.getSite(), null); - } - - /** - * Creates a new <code>OpenActionGroup</code>. The group requires - * that the selection provided by the given selection provider is - * of type {@link IStructuredSelection}. - * - * @param page the page that owns this action group - * @param selectionProvider the selection provider used instead of the - * page selection provider. - * - * - */ - public OpenViewActionGroup(Page page, ISelectionProvider selectionProvider) { - createSiteActions(page.getSite(), selectionProvider); - } - - /** - * Creates a new <code>OpenActionGroup</code>. The group requires - * that the selection provided by the part's selection provider is - * of type {@link IStructuredSelection}. - * - * @param part the view part that owns this action group - */ - public OpenViewActionGroup(IViewPart part) { - this(part, null); - } - - /** - * Creates a new <code>OpenActionGroup</code>. The group requires - * that the selection provided by the given selection provider is of type - * {@link IStructuredSelection}. - * - * @param part the view part that owns this action group - * @param selectionProvider the selection provider used instead of the - * page selection provider. - * - * - */ - public OpenViewActionGroup(IViewPart part, ISelectionProvider selectionProvider) { - createSiteActions(part.getSite(), selectionProvider); - // we do a name check here to avoid class loading. - String partName= part.getClass().getName(); - fIsTypeHiararchyViewerOwner= "org.eclipse.wst.jsdt.internal.ui.typehierarchy.TypeHierarchyViewPart".equals(partName); //$NON-NLS-1$ - fIsCallHiararchyViewerOwner= "org.eclipse.wst.jsdt.internal.ui.callhierarchy.CallHierarchyViewPart".equals(partName); //$NON-NLS-1$ - } - - /** - * Creates a new <code>OpenActionGroup</code>. The group requires - * that the selection provided by the given selection provider is of type - * {@link IStructuredSelection}. - * - * @param site the site that will own the action group. - * @param selectionProvider the selection provider used instead of the - * page selection provider. - * - * - */ - public OpenViewActionGroup(IWorkbenchSite site, ISelectionProvider selectionProvider) { - createSiteActions(site, selectionProvider); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param part the editor part - */ - public OpenViewActionGroup(JavaEditor part) { - fEditorIsOwner= true; - fShowShowInMenu= false; - - fOpenSuperImplementation= new OpenSuperImplementationAction(part); - fOpenSuperImplementation.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_SUPER_IMPLEMENTATION); - part.setAction("OpenSuperImplementation", fOpenSuperImplementation); //$NON-NLS-1$ - - fOpenExternalJavadoc= new OpenExternalJavadocAction(part); - fOpenExternalJavadoc.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_EXTERNAL_JAVADOC); - part.setAction("OpenExternalJavadoc", fOpenExternalJavadoc); //$NON-NLS-1$ - - fOpenTypeHierarchy= new OpenTypeHierarchyAction(part); - fOpenTypeHierarchy.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_TYPE_HIERARCHY); - part.setAction("OpenTypeHierarchy", fOpenTypeHierarchy); //$NON-NLS-1$ - - fOpenCallHierarchy= new OpenCallHierarchyAction(part); - fOpenCallHierarchy.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_CALL_HIERARCHY); - part.setAction("OpenCallHierarchy", fOpenCallHierarchy); //$NON-NLS-1$ - - initialize(part.getEditorSite().getSelectionProvider()); - } - - /** - * Specifies if this action group also contains the 'Properties' action ({@link PropertyDialogAction}). - * By default, the action is contained in the group. - * - * @param enable If set, the 'Properties' action is part of this action group - * - */ - public void containsOpenPropertiesAction(boolean enable) { - fShowOpenPropertiesAction= enable; - } - - /** - * Specifies if this action group also contains the 'Show In' menu (See {@link ContributionItemFactory#VIEWS_SHOW_IN}). - * By default, the action is contained in the group except for editors. - * - * @param enable If set, the 'Show In' menu is part of this action group - * - */ - public void containsShowInMenu(boolean enable) { - fShowShowInMenu= enable; - } - - private void createSiteActions(IWorkbenchSite site, ISelectionProvider specialProvider) { - fOpenSuperImplementation= new OpenSuperImplementationAction(site); - fOpenSuperImplementation.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_SUPER_IMPLEMENTATION); - fOpenSuperImplementation.setSpecialSelectionProvider(specialProvider); - - fOpenExternalJavadoc= new OpenExternalJavadocAction(site); - fOpenExternalJavadoc.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_EXTERNAL_JAVADOC); - fOpenExternalJavadoc.setSpecialSelectionProvider(specialProvider); - - fOpenTypeHierarchy= new OpenTypeHierarchyAction(site); - fOpenTypeHierarchy.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_TYPE_HIERARCHY); - fOpenTypeHierarchy.setSpecialSelectionProvider(specialProvider); - - fOpenCallHierarchy= new OpenCallHierarchyAction(site); - fOpenCallHierarchy.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_CALL_HIERARCHY); - fOpenCallHierarchy.setSpecialSelectionProvider(specialProvider); - - ISelectionProvider provider= specialProvider != null ? specialProvider : site.getSelectionProvider(); - - fOpenPropertiesDialog= new PropertyDialogAction(site, provider); - fOpenPropertiesDialog.setActionDefinitionId(IWorkbenchActionDefinitionIds.PROPERTIES); - - initialize(provider); - } - - private void initialize(ISelectionProvider provider) { - fSelectionProvider= provider; - ISelection selection= provider.getSelection(); - fOpenSuperImplementation.update(selection); - fOpenExternalJavadoc.update(selection); - fOpenTypeHierarchy.update(selection); - fOpenCallHierarchy.update(selection); - if (!fEditorIsOwner) { - if (fShowOpenPropertiesAction) { - if (selection instanceof IStructuredSelection) { - fOpenPropertiesDialog.selectionChanged((IStructuredSelection) selection); - } else { - fOpenPropertiesDialog.selectionChanged(selection); - } - } - provider.addSelectionChangedListener(fOpenSuperImplementation); - provider.addSelectionChangedListener(fOpenExternalJavadoc); - provider.addSelectionChangedListener(fOpenTypeHierarchy); - provider.addSelectionChangedListener(fOpenCallHierarchy); - // no need to register the open properties dialog action since it registers itself - } - } - - /* (non-Javadoc) - * Method declared in ActionGroup - */ - public void fillActionBars(IActionBars actionBar) { - super.fillActionBars(actionBar); - setGlobalActionHandlers(actionBar); - } - - /* (non-Javadoc) - * Method declared in ActionGroup - */ - public void fillContextMenu(IMenuManager menu) { - super.fillContextMenu(menu); - if (!fIsTypeHiararchyViewerOwner) - appendToGroup(menu, fOpenTypeHierarchy); - if (!fIsCallHiararchyViewerOwner) - appendToGroup(menu, fOpenCallHierarchy); - - if (fShowShowInMenu) { - MenuManager showInSubMenu= new MenuManager(getShowInMenuLabel()); - IWorkbenchWindow workbenchWindow= fOpenSuperImplementation.getSite().getWorkbenchWindow(); - showInSubMenu.add(ContributionItemFactory.VIEWS_SHOW_IN.create(workbenchWindow)); - menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, showInSubMenu); - } - - IStructuredSelection selection= getStructuredSelection(); - if (fShowOpenPropertiesAction && selection != null) - menu.appendToGroup(IContextMenuConstants.GROUP_PROPERTIES, fOpenPropertiesDialog); - } - - private String getShowInMenuLabel() { - String keyBinding= null; - - IBindingService bindingService= (IBindingService) PlatformUI.getWorkbench().getAdapter(IBindingService.class); - if (bindingService != null) - keyBinding= bindingService.getBestActiveBindingFormattedFor("org.eclipse.ui.navigate.showInQuickMenu"); //$NON-NLS-1$ - - if (keyBinding == null) - keyBinding= ""; //$NON-NLS-1$ - - return ActionMessages.OpenViewActionGroup_showInAction_label + '\t' + keyBinding; - } - - /* - * @see ActionGroup#dispose() - */ - public void dispose() { - fSelectionProvider.removeSelectionChangedListener(fOpenSuperImplementation); - fSelectionProvider.removeSelectionChangedListener(fOpenExternalJavadoc); - fSelectionProvider.removeSelectionChangedListener(fOpenTypeHierarchy); - fSelectionProvider.removeSelectionChangedListener(fOpenCallHierarchy); - super.dispose(); - } - - private void setGlobalActionHandlers(IActionBars actionBars) { - actionBars.setGlobalActionHandler(JdtActionConstants.OPEN_SUPER_IMPLEMENTATION, fOpenSuperImplementation); - actionBars.setGlobalActionHandler(JdtActionConstants.OPEN_EXTERNAL_JAVA_DOC, fOpenExternalJavadoc); - actionBars.setGlobalActionHandler(JdtActionConstants.OPEN_TYPE_HIERARCHY, fOpenTypeHierarchy); - actionBars.setGlobalActionHandler(JdtActionConstants.OPEN_CALL_HIERARCHY, fOpenCallHierarchy); - - if (!fEditorIsOwner && fShowOpenPropertiesAction) - actionBars.setGlobalActionHandler(ActionFactory.PROPERTIES.getId(), fOpenPropertiesDialog); - } - - private void appendToGroup(IMenuManager menu, IAction action) { - if (action.isEnabled()) - menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, action); - } - - private IStructuredSelection getStructuredSelection() { - ISelection selection= getContext().getSelection(); - if (selection instanceof IStructuredSelection) - return (IStructuredSelection)selection; - return null; - } - - - - -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OrganizeImportsAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OrganizeImportsAction.java deleted file mode 100644 index a91035e2..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OrganizeImportsAction.java +++ /dev/null @@ -1,397 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.lang.reflect.InvocationTargetException; -import java.util.Comparator; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IStatusLineManager; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.operation.IRunnableContext; -import org.eclipse.jface.text.DocumentEvent; -import org.eclipse.jface.text.IEditingSupport; -import org.eclipse.jface.text.IEditingSupportRegistry; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.IRewriteTarget; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.window.Window; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IObjectActionDelegate; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.progress.IProgressService; -import org.eclipse.wst.jsdt.core.IJavaScriptUnit; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.ISourceRange; -import org.eclipse.wst.jsdt.core.compiler.IProblem; -import org.eclipse.wst.jsdt.core.dom.JavaScriptUnit; -import org.eclipse.wst.jsdt.core.search.TypeNameMatch; -import org.eclipse.wst.jsdt.internal.corext.codemanipulation.CodeGenerationSettings; -import org.eclipse.wst.jsdt.internal.corext.codemanipulation.OrganizeImportsOperation; -import org.eclipse.wst.jsdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery; -import org.eclipse.wst.jsdt.internal.corext.util.History; -import org.eclipse.wst.jsdt.internal.corext.util.Messages; -import org.eclipse.wst.jsdt.internal.corext.util.QualifiedTypeNameHistory; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.MultiOrganizeImportAction; -import org.eclipse.wst.jsdt.internal.ui.actions.WorkbenchRunnableAdapter; -import org.eclipse.wst.jsdt.internal.ui.dialogs.MultiElementListSelectionDialog; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.ASTProvider; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.EditorUtility; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.preferences.JavaPreferencesSettings; -import org.eclipse.wst.jsdt.internal.ui.util.ElementValidator; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; -import org.eclipse.wst.jsdt.internal.ui.util.TypeNameMatchLabelProvider; -import org.eclipse.wst.jsdt.ui.JavaScriptUI; - -import com.ibm.icu.text.Collator; - -/** - * Organizes the imports of a compilation unit. - * <p> - * The action is applicable to selections containing elements of - * type <code>IJavaScriptUnit</code> or <code>IPackage - * </code>. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class OrganizeImportsAction extends SelectionDispatchAction { - - private static final OrganizeImportComparator ORGANIZE_IMPORT_COMPARATOR= new OrganizeImportComparator(); - - private JavaEditor fEditor; - /** <code>true</code> if the query dialog is showing. */ - private boolean fIsQueryShowing= false; - private final MultiOrganizeImportAction fCleanUpDelegate; - - /* (non-Javadoc) - * Class implements IObjectActionDelegate - */ - public static class ObjectDelegate implements IObjectActionDelegate { - private OrganizeImportsAction fAction; - public void setActivePart(IAction action, IWorkbenchPart targetPart) { - fAction= new OrganizeImportsAction(targetPart.getSite()); - } - public void run(IAction action) { - fAction.run(); - } - public void selectionChanged(IAction action, ISelection selection) { - if (fAction == null) - action.setEnabled(false); - } - } - - private static final class OrganizeImportComparator implements Comparator { - - public int compare(Object o1, Object o2) { - if (((String)o1).equals(o2)) - return 0; - - History history= QualifiedTypeNameHistory.getDefault(); - - int pos1= history.getPosition(o1); - int pos2= history.getPosition(o2); - - if (pos1 == pos2) - return Collator.getInstance().compare(o1, o2); - - if (pos1 > pos2) { - return -1; - } else { - return 1; - } - } - - } - - /** - * Creates a new <code>OrganizeImportsAction</code>. The action requires - * that the selection provided by the site's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public OrganizeImportsAction(IWorkbenchSite site) { - super(site); - - fCleanUpDelegate= new MultiOrganizeImportAction(site); - - setText(ActionMessages.OrganizeImportsAction_label); - setToolTipText(ActionMessages.OrganizeImportsAction_tooltip); - setDescription(ActionMessages.OrganizeImportsAction_description); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.ORGANIZE_IMPORTS_ACTION); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public OrganizeImportsAction(JavaEditor editor) { - super(editor.getEditorSite()); - - fEditor= editor; - fCleanUpDelegate= new MultiOrganizeImportAction(editor); - - setText(ActionMessages.OrganizeImportsAction_label); - setToolTipText(ActionMessages.OrganizeImportsAction_tooltip); - setDescription(ActionMessages.OrganizeImportsAction_description); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.ORGANIZE_IMPORTS_ACTION); - - setEnabled(fCleanUpDelegate.isEnabled()); - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void selectionChanged(ITextSelection selection) { - fCleanUpDelegate.selectionChanged(selection); - setEnabled(fCleanUpDelegate.isEnabled()); - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void selectionChanged(IStructuredSelection selection) { - fCleanUpDelegate.selectionChanged(selection); - setEnabled(fCleanUpDelegate.isEnabled()); - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void run(ITextSelection selection) { - IJavaScriptUnit cu= getCompilationUnit(fEditor); - if (cu != null) { - run(cu); - } - } - - private static IJavaScriptUnit getCompilationUnit(JavaEditor editor) { - IJavaScriptElement element= JavaScriptUI.getEditorInputJavaElement(editor.getEditorInput()); - if (!(element instanceof IJavaScriptUnit)) - return null; - - return (IJavaScriptUnit)element; - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void run(IStructuredSelection selection) { - IJavaScriptUnit[] cus= fCleanUpDelegate.getCompilationUnits(selection); - if (cus.length == 0) { - MessageDialog.openInformation(getShell(), ActionMessages.OrganizeImportsAction_EmptySelection_title, ActionMessages.OrganizeImportsAction_EmptySelection_description); - } else if (cus.length == 1) { - run(cus[0]); - } else { - fCleanUpDelegate.run(selection); - } - } - - /** - * Perform organize import on multiple compilation units. No editors are opened. - * @param cus The compilation units to run on - */ - public void runOnMultiple(final IJavaScriptUnit[] cus) { - if (cus.length == 0) - return; - - fCleanUpDelegate.run(new StructuredSelection(cus)); - } - - /** - * Note: This method is for internal use only. Clients should not call this method. - * @param cu The compilation unit to process - */ - public void run(IJavaScriptUnit cu) { - if (!ElementValidator.check(cu, getShell(), ActionMessages.OrganizeImportsAction_error_title, fEditor != null)) - return; - if (!ActionUtil.isEditable(fEditor, getShell(), cu)) - return; - - IEditingSupport helper= createViewerHelper(); - try { - CodeGenerationSettings settings= JavaPreferencesSettings.getCodeGenerationSettings(cu.getJavaScriptProject()); - - if (fEditor == null && EditorUtility.isOpenInEditor(cu) == null) { - IEditorPart editor= JavaScriptUI.openInEditor(cu); - if (editor instanceof JavaEditor) { - fEditor= (JavaEditor) editor; - } - } - - JavaScriptUnit astRoot= JavaScriptPlugin.getDefault().getASTProvider().getAST(cu, ASTProvider.WAIT_ACTIVE_ONLY, null); - - OrganizeImportsOperation op= new OrganizeImportsOperation(cu, astRoot, settings.importIgnoreLowercase, !cu.isWorkingCopy(), true, createChooseImportQuery()); - - IRewriteTarget target= null; - if (fEditor != null) { - target= (IRewriteTarget) fEditor.getAdapter(IRewriteTarget.class); - if (target != null) { - target.beginCompoundChange(); - } - } - - IProgressService progressService= PlatformUI.getWorkbench().getProgressService(); - IRunnableContext context= getSite().getWorkbenchWindow(); - if (context == null) { - context= progressService; - } - try { - registerHelper(helper); - progressService.runInUI(context, new WorkbenchRunnableAdapter(op, op.getScheduleRule()), op.getScheduleRule()); - IProblem parseError= op.getParseError(); - if (parseError != null) { - String message= Messages.format(ActionMessages.OrganizeImportsAction_single_error_parse, parseError.getMessage()); - MessageDialog.openInformation(getShell(), ActionMessages.OrganizeImportsAction_error_title, message); - if (fEditor != null && parseError.getSourceStart() != -1) { - fEditor.selectAndReveal(parseError.getSourceStart(), parseError.getSourceEnd() - parseError.getSourceStart() + 1); - } - } else { - if (fEditor != null) { - setStatusBarMessage(getOrganizeInfo(op)); - } - } - } catch (InvocationTargetException e) { - ExceptionHandler.handle(e, getShell(), ActionMessages.OrganizeImportsAction_error_title, ActionMessages.OrganizeImportsAction_error_message); - } catch (InterruptedException e) { - } finally { - deregisterHelper(helper); - if (target != null) { - target.endCompoundChange(); - } - } - } catch (CoreException e) { - ExceptionHandler.handle(e, getShell(), ActionMessages.OrganizeImportsAction_error_title, ActionMessages.OrganizeImportsAction_error_message); - } - } - - private String getOrganizeInfo(OrganizeImportsOperation op) { - int nImportsAdded= op.getNumberOfImportsAdded(); - if (nImportsAdded >= 0) { - return Messages.format(ActionMessages.OrganizeImportsAction_summary_added, String.valueOf(nImportsAdded)); - } else { - return Messages.format(ActionMessages.OrganizeImportsAction_summary_removed, String.valueOf(-nImportsAdded)); - } - } - - private IChooseImportQuery createChooseImportQuery() { - return new IChooseImportQuery() { - public TypeNameMatch[] chooseImports(TypeNameMatch[][] openChoices, ISourceRange[] ranges) { - return doChooseImports(openChoices, ranges); - } - }; - } - - private TypeNameMatch[] doChooseImports(TypeNameMatch[][] openChoices, final ISourceRange[] ranges) { - // remember selection - ISelection sel= fEditor != null ? fEditor.getSelectionProvider().getSelection() : null; - TypeNameMatch[] result= null; - ILabelProvider labelProvider= new TypeNameMatchLabelProvider(TypeNameMatchLabelProvider.SHOW_FULLYQUALIFIED); - - MultiElementListSelectionDialog dialog= new MultiElementListSelectionDialog(getShell(), labelProvider) { - protected void handleSelectionChanged() { - super.handleSelectionChanged(); - // show choices in editor - doListSelectionChanged(getCurrentPage(), ranges); - } - }; - fIsQueryShowing= true; - dialog.setTitle(ActionMessages.OrganizeImportsAction_selectiondialog_title); - dialog.setMessage(ActionMessages.OrganizeImportsAction_selectiondialog_message); - dialog.setElements(openChoices); - dialog.setComparator(ORGANIZE_IMPORT_COMPARATOR); - if (dialog.open() == Window.OK) { - Object[] res= dialog.getResult(); - result= new TypeNameMatch[res.length]; - for (int i= 0; i < res.length; i++) { - Object[] array= (Object[]) res[i]; - if (array.length > 0) { - result[i]= (TypeNameMatch) array[0]; - QualifiedTypeNameHistory.remember(result[i].getFullyQualifiedName()); - } - } - } - // restore selection - if (sel instanceof ITextSelection) { - ITextSelection textSelection= (ITextSelection) sel; - fEditor.selectAndReveal(textSelection.getOffset(), textSelection.getLength()); - } - fIsQueryShowing= false; - return result; - } - - private void doListSelectionChanged(int page, ISourceRange[] ranges) { - if (fEditor != null && ranges != null && page >= 0 && page < ranges.length) { - ISourceRange range= ranges[page]; - fEditor.selectAndReveal(range.getOffset(), range.getLength()); - } - } - - private void setStatusBarMessage(String message) { - IStatusLineManager manager= fEditor.getEditorSite().getActionBars().getStatusLineManager(); - manager.setMessage(message); - } - - private IEditingSupport createViewerHelper() { - return new IEditingSupport() { - public boolean isOriginator(DocumentEvent event, IRegion subjectRegion) { - return true; // assume true, since we only register while we are active - } - public boolean ownsFocusShell() { - return fIsQueryShowing; - } - - }; - } - - private void registerHelper(IEditingSupport helper) { - if (fEditor == null) - return; - ISourceViewer viewer= fEditor.getViewer(); - if (viewer instanceof IEditingSupportRegistry) { - IEditingSupportRegistry registry= (IEditingSupportRegistry) viewer; - registry.register(helper); - } - } - - private void deregisterHelper(IEditingSupport helper) { - if (fEditor == null) - return; - ISourceViewer viewer= fEditor.getViewer(); - if (viewer instanceof IEditingSupportRegistry) { - IEditingSupportRegistry registry= (IEditingSupportRegistry) viewer; - registry.unregister(helper); - } - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OverrideMethodsAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OverrideMethodsAction.java deleted file mode 100644 index 8a1e40f7..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/OverrideMethodsAction.java +++ /dev/null @@ -1,276 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; - -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.operation.IRunnableContext; -import org.eclipse.jface.text.IRewriteTarget; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IJavaScriptUnit; -import org.eclipse.wst.jsdt.core.IType; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.core.dom.JavaScriptUnit; -import org.eclipse.wst.jsdt.core.dom.IFunctionBinding; -import org.eclipse.wst.jsdt.core.dom.ITypeBinding; -import org.eclipse.wst.jsdt.internal.corext.codemanipulation.AddUnimplementedMethodsOperation; -import org.eclipse.wst.jsdt.internal.corext.dom.ASTNodes; -import org.eclipse.wst.jsdt.internal.corext.util.JavaModelUtil; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.actions.WorkbenchRunnableAdapter; -import org.eclipse.wst.jsdt.internal.ui.dialogs.OverrideMethodDialog; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.CompilationUnitEditor; -import org.eclipse.wst.jsdt.internal.ui.util.BusyIndicatorRunnableContext; -import org.eclipse.wst.jsdt.internal.ui.util.ElementValidator; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; -import org.eclipse.wst.jsdt.ui.JavaScriptUI; - -/** - * Adds unimplemented methods of a type. The action opens a dialog from which the user can - * choose the methods to be added. - * <p> - * Will open the parent compilation unit in a JavaScript editor. The result is unsaved, so the - * user can decide if the changes are acceptable. - * <p> - * The action is applicable to structured selections containing elements of type - * {@link org.eclipse.wst.jsdt.core.IType}. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class OverrideMethodsAction extends SelectionDispatchAction { - - /** The dialog title */ - private static final String DIALOG_TITLE= ActionMessages.OverrideMethodsAction_error_title; - - /** The compilation unit editor */ - private CompilationUnitEditor fEditor; - - /** - * Note: This constructor is for internal use only. Clients should not call this - * constructor. - * @param editor the compilation unit editor - */ - public OverrideMethodsAction(final CompilationUnitEditor editor) { - this(editor.getEditorSite()); - fEditor= editor; - setEnabled(checkEnabledEditor()); - } - - /** - * Creates a new override method action. - * <p> - * The action requires that the selection provided by the site's selection provider is - * of type {@link org.eclipse.jface.viewers.IStructuredSelection}. - * - * @param site the workbench site providing context information for this action - */ - public OverrideMethodsAction(final IWorkbenchSite site) { - super(site); - setText(ActionMessages.OverrideMethodsAction_label); - setDescription(ActionMessages.OverrideMethodsAction_description); - setToolTipText(ActionMessages.OverrideMethodsAction_tooltip); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.ADD_UNIMPLEMENTED_METHODS_ACTION); - } - - private boolean canEnable(IStructuredSelection selection) throws JavaScriptModelException { - if ((selection.size() == 1) && (selection.getFirstElement() instanceof IType)) { - final IType type= (IType) selection.getFirstElement(); - return type.getJavaScriptUnit() != null; - } - if ((selection.size() == 1) && (selection.getFirstElement() instanceof IJavaScriptUnit)) - return true; - return false; - } - - private boolean checkEnabledEditor() { - return fEditor != null && SelectionConverter.canOperateOn(fEditor); - } - - private String getDialogTitle() { - return DIALOG_TITLE; - } - - private IType getSelectedType(IStructuredSelection selection) throws JavaScriptModelException { - final Object[] elements= selection.toArray(); - if (elements.length == 1 && (elements[0] instanceof IType)) { - final IType type= (IType) elements[0]; - if (type.getJavaScriptUnit() != null) { - return type; - } - } else if (elements[0] instanceof IJavaScriptUnit) { - final IType type= ((IJavaScriptUnit) elements[0]).findPrimaryType(); - if (type != null) - return type; - } - return null; - } - - /* - * @see org.eclipse.wst.jsdt.ui.actions.SelectionDispatchAction#run(org.eclipse.jface.viewers.IStructuredSelection) - */ - public void run(IStructuredSelection selection) { - try { - final IType type= getSelectedType(selection); - if (type == null) { - MessageDialog.openInformation(getShell(), getDialogTitle(), ActionMessages.OverrideMethodsAction_not_applicable); - notifyResult(false); - return; - } - if (!ElementValidator.check(type, getShell(), getDialogTitle(), false) || !ActionUtil.isEditable(getShell(), type)) { - notifyResult(false); - return; - } - run(getShell(), type); - } catch (CoreException exception) { - ExceptionHandler.handle(exception, getShell(), getDialogTitle(), ActionMessages.OverrideMethodsAction_error_actionfailed); - } - } - - /* - * @see org.eclipse.wst.jsdt.ui.actions.SelectionDispatchAction#run(org.eclipse.jface.text.ITextSelection) - */ - public void run(ITextSelection selection) { - try { - final IType type= SelectionConverter.getTypeAtOffset(fEditor); - if (type != null) { - if (!ElementValidator.check(type, getShell(), getDialogTitle(), false) || !ActionUtil.isEditable(fEditor, getShell(), type)) { - notifyResult(false); - return; - } - run(getShell(), type); - } else { - MessageDialog.openInformation(getShell(), getDialogTitle(), ActionMessages.OverrideMethodsAction_not_applicable); - } - } catch (JavaScriptModelException e) { - ExceptionHandler.handle(e, getShell(), getDialogTitle(), null); - } catch (CoreException e) { - ExceptionHandler.handle(e, getShell(), getDialogTitle(), ActionMessages.OverrideMethodsAction_error_actionfailed); - } - } - - private void run(Shell shell, IType type) throws CoreException { - final OverrideMethodDialog dialog= new OverrideMethodDialog(shell, fEditor, type,false); - if (!dialog.hasMethodsToOverride()) { - MessageDialog.openInformation(shell, getDialogTitle(), ActionMessages.OverrideMethodsAction_error_nothing_found); - notifyResult(false); - return; - } - if (dialog.open() != Window.OK) { - notifyResult(false); - return; - } - - final Object[] selected= dialog.getResult(); - if (selected == null) { - notifyResult(false); - return; - } - - ArrayList methods= new ArrayList(); - for (int i= 0; i < selected.length; i++) { - Object elem= selected[i]; - if (elem instanceof IFunctionBinding) { - methods.add(elem); - } - } - IFunctionBinding[] methodToOverride= (IFunctionBinding[]) methods.toArray(new IFunctionBinding[methods.size()]); - - - final IEditorPart editor= JavaScriptUI.openInEditor(type.getJavaScriptUnit()); - final IRewriteTarget target= editor != null ? (IRewriteTarget) editor.getAdapter(IRewriteTarget.class) : null; - if (target != null) - target.beginCompoundChange(); - try { - JavaScriptUnit astRoot= dialog.getCompilationUnit(); - final ITypeBinding typeBinding= ASTNodes.getTypeBinding(astRoot, type); - int insertPos= dialog.getInsertOffset(); - - AddUnimplementedMethodsOperation operation= (AddUnimplementedMethodsOperation) createRunnable(astRoot, typeBinding, methodToOverride, insertPos, dialog.getGenerateComment()); - IRunnableContext context= JavaScriptPlugin.getActiveWorkbenchWindow(); - if (context == null) - context= new BusyIndicatorRunnableContext(); - PlatformUI.getWorkbench().getProgressService().runInUI(context, new WorkbenchRunnableAdapter(operation, operation.getSchedulingRule()), operation.getSchedulingRule()); - final String[] created= operation.getCreatedMethods(); - if (created == null || created.length == 0) - MessageDialog.openInformation(shell, getDialogTitle(), ActionMessages.OverrideMethodsAction_error_nothing_found); - } catch (InvocationTargetException exception) { - ExceptionHandler.handle(exception, shell, getDialogTitle(), null); - } catch (InterruptedException exception) { - // Do nothing. Operation has been canceled by user. - } finally { - if (target != null) - target.endCompoundChange(); - } - notifyResult(true); - } - - /** - * Returns a runnable that creates the method stubs for overridden methods. - * - * @param astRoot the AST of the compilation unit to work on. The AST must have been created from a {@link IJavaScriptUnit}, that - * means {@link org.eclipse.wst.jsdt.core.dom.ASTParser#setSource(IJavaScriptUnit)} was used. - * @param type the binding of the type to add the new methods to. The type binding must correspond to a type declaration in the AST. - * @param methodToOverride the bindings of methods to override or <code>null</code> to implement all unimplemented, abstract methods from super types. - * @param insertPos a hint for a location in the source where to insert the new methods or <code>-1</code> to use the default behavior. - * @param createComments if set, comments will be added to the new methods. - * @return returns a runnable that creates the methods stubs. - * @throws IllegalArgumentException a {@link IllegalArgumentException} is thrown if the AST passed has not been created from a {@link IJavaScriptUnit}. - * - * - */ - public static IWorkspaceRunnable createRunnable(JavaScriptUnit astRoot, ITypeBinding type, IFunctionBinding[] methodToOverride, int insertPos, boolean createComments) { - AddUnimplementedMethodsOperation operation= new AddUnimplementedMethodsOperation(astRoot, type, methodToOverride, insertPos, true, true, false); - operation.setCreateComments(createComments); - return operation; - } - - /* - * @see org.eclipse.wst.jsdt.ui.actions.SelectionDispatchAction#selectionChanged(org.eclipse.jface.viewers.IStructuredSelection) - */ - public void selectionChanged(IStructuredSelection selection) { - try { - setEnabled(canEnable(selection)); - } catch (JavaScriptModelException exception) { - if (JavaModelUtil.isExceptionToBeLogged(exception)) - JavaScriptPlugin.log(exception); - setEnabled(false); - } - } - - /* - * @see org.eclipse.wst.jsdt.ui.actions.SelectionDispatchAction#run(org.eclipse.jface.text.ITextSelection) - */ - public void selectionChanged(ITextSelection selection) { - // Do nothing - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ProjectActionGroup.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ProjectActionGroup.java deleted file mode 100644 index fc909046..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ProjectActionGroup.java +++ /dev/null @@ -1,218 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.IWorkingSet; -import org.eclipse.ui.actions.ActionGroup; -import org.eclipse.ui.actions.CloseResourceAction; -import org.eclipse.ui.actions.CloseUnrelatedProjectsAction; -import org.eclipse.ui.ide.IDEActionFactory; -import org.eclipse.wst.jsdt.core.IJavaScriptProject; -import org.eclipse.wst.jsdt.ui.IContextMenuConstants; - -/** - * Adds actions to open and close a project to the global menu bar. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class ProjectActionGroup extends ActionGroup { - - private IWorkbenchSite fSite; - - private OpenProjectAction fOpenAction; - private CloseResourceAction fCloseAction; - private CloseResourceAction fCloseUnrelatedAction; - - private ISelectionChangedListener fSelectionChangedListener; - - /** - * Creates a new <code>ProjectActionGroup</code>. The group requires - * that the selection provided by the site's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param part the view part that owns this action group - */ - public ProjectActionGroup(IViewPart part) { - fSite = part.getSite(); - Shell shell= fSite.getShell(); - ISelectionProvider provider= fSite.getSelectionProvider(); - ISelection selection= provider.getSelection(); - - fCloseAction= new CloseResourceAction(shell); - fCloseAction.setActionDefinitionId("org.eclipse.ui.project.closeProject"); //$NON-NLS-1$ - - fCloseUnrelatedAction= new CloseUnrelatedProjectsAction(shell); - fCloseUnrelatedAction.setActionDefinitionId("org.eclipse.ui.project.closeUnrelatedProjects"); //$NON-NLS-1$ - - fOpenAction= new OpenProjectAction(fSite); - fOpenAction.setActionDefinitionId("org.eclipse.ui.project.openProject"); //$NON-NLS-1$ - if (selection instanceof IStructuredSelection) { - IStructuredSelection s= (IStructuredSelection)selection; - fOpenAction.selectionChanged(s); - fCloseAction.selectionChanged(s); - fCloseUnrelatedAction.selectionChanged(s); - } - - fSelectionChangedListener= new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - ISelection s= event.getSelection(); - if (s instanceof IStructuredSelection) { - performSelectionChanged((IStructuredSelection) s); - } - } - }; - provider.addSelectionChangedListener(fSelectionChangedListener); - - IWorkspace workspace= ResourcesPlugin.getWorkspace(); - workspace.addResourceChangeListener(fOpenAction); - workspace.addResourceChangeListener(fCloseAction); - workspace.addResourceChangeListener(fCloseUnrelatedAction); - } - - protected void performSelectionChanged(IStructuredSelection structuredSelection) { - Object[] array= structuredSelection.toArray(); - ArrayList openProjects= new ArrayList(); - int selectionStatus= evaluateSelection(array, openProjects); - StructuredSelection sel= new StructuredSelection(openProjects); - - fOpenAction.setEnabled(selectionStatus == CLOSED_PROJECTS_SELECTED || (selectionStatus == 0 && hasClosedProjectsInWorkspace())); - fCloseAction.selectionChanged(sel); - fCloseUnrelatedAction.selectionChanged(sel); - } - - private int CLOSED_PROJECTS_SELECTED= 1; - private int NON_PROJECT_SELECTED= 2; - - private int evaluateSelection(Object[] array, List allOpenProjects) { - int status= 0; - for (int i= 0; i < array.length; i++) { - Object curr= array[i]; - if (curr instanceof IJavaScriptProject) { - curr= ((IJavaScriptProject) curr).getProject(); - } - if (curr instanceof IProject) { - IProject project= (IProject) curr; - if (project.isOpen()) { - allOpenProjects.add(project); - } else { - status |= CLOSED_PROJECTS_SELECTED; - } - } else { - if (curr instanceof IWorkingSet) { - int res= evaluateSelection(((IWorkingSet) curr).getElements(), allOpenProjects); - status |= res; - } else { - status |= NON_PROJECT_SELECTED; - } - } - } - return status; - } - - private boolean hasClosedProjectsInWorkspace() { - IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects(); - for (int i = 0; i < projects.length; i++) { - if (!projects[i].isOpen()) - return true; - } - return false; - } - - /* (non-Javadoc) - * Method declared in ActionGroup - */ - public void fillActionBars(IActionBars actionBars) { - super.fillActionBars(actionBars); - actionBars.setGlobalActionHandler(IDEActionFactory.CLOSE_PROJECT.getId(), fCloseAction); - actionBars.setGlobalActionHandler(IDEActionFactory.CLOSE_UNRELATED_PROJECTS.getId(), fCloseUnrelatedAction); - actionBars.setGlobalActionHandler(IDEActionFactory.OPEN_PROJECT.getId(), fOpenAction); - } - - /* (non-Javadoc) - * Method declared in ActionGroup - */ - public void fillContextMenu(IMenuManager menu) { - super.fillContextMenu(menu); - if (fOpenAction.isEnabled()) - menu.appendToGroup(IContextMenuConstants.GROUP_BUILD, fOpenAction); - if (fCloseAction.isEnabled()) - menu.appendToGroup(IContextMenuConstants.GROUP_BUILD, fCloseAction); - if (fCloseUnrelatedAction.isEnabled() && areOnlyProjectsSelected(fCloseUnrelatedAction.getStructuredSelection())) - menu.appendToGroup(IContextMenuConstants.GROUP_BUILD, fCloseUnrelatedAction); - } - - /** - * Returns the open project action contained in this project action group. - * - * @return returns the open project action - * - * - */ - public OpenProjectAction getOpenProjectAction() { - return fOpenAction; - } - - private boolean areOnlyProjectsSelected(IStructuredSelection selection) { - if (selection.isEmpty()) - return false; - - Iterator iter= selection.iterator(); - while (iter.hasNext()) { - Object obj= iter.next(); - if (obj instanceof IAdaptable) { - if (((IAdaptable)obj).getAdapter(IProject.class) == null) - return false; - } - } - return true; - } - - /* - * @see ActionGroup#dispose() - */ - public void dispose() { - ISelectionProvider provider= fSite.getSelectionProvider(); - provider.removeSelectionChangedListener(fSelectionChangedListener); - - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - workspace.removeResourceChangeListener(fOpenAction); - workspace.removeResourceChangeListener(fCloseAction); - workspace.removeResourceChangeListener(fCloseUnrelatedAction); - super.dispose(); - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/PullUpAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/PullUpAction.java deleted file mode 100644 index 3bd0b7c5..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/PullUpAction.java +++ /dev/null @@ -1,179 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.IMember; -import org.eclipse.wst.jsdt.core.IType; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.internal.corext.refactoring.RefactoringAvailabilityTester; -import org.eclipse.wst.jsdt.internal.corext.refactoring.RefactoringExecutionStarter; -import org.eclipse.wst.jsdt.internal.corext.util.JavaModelUtil; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaTextSelection; -import org.eclipse.wst.jsdt.internal.ui.refactoring.RefactoringMessages; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; - -/** - * Action to pull up method and fields into a superclass. - * <p> - * Action is applicable to selections containing elements of type - * <code>IType</code> (top-level types only), <code>IField</code> and - * <code>IFunction</code>. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class PullUpAction extends SelectionDispatchAction { - - private static IMember[] getSelectedMembers(IStructuredSelection selection) { - if (selection.isEmpty()) - return null; - if (selection.size() == 1) { - try { - final IType type= RefactoringAvailabilityTester.getSingleSelectedType(selection); - if (type != null) - return new IType[] { type}; - } catch (JavaScriptModelException exception) { - JavaScriptPlugin.log(exception); - } - } - for (Iterator iter= selection.iterator(); iter.hasNext();) { - if (!(iter.next() instanceof IMember)) - return null; - } - Set memberSet= new HashSet(); - memberSet.addAll(Arrays.asList(selection.toArray())); - return (IMember[]) memberSet.toArray(new IMember[memberSet.size()]); - } - - private JavaEditor fEditor; - - /** - * Note: This constructor is for internal use only. Clients should not call - * this constructor. - * - * @param editor - * the JavaScript editor - */ - public PullUpAction(JavaEditor editor) { - this(editor.getEditorSite()); - fEditor= editor; - setEnabled(SelectionConverter.canOperateOn(fEditor)); - } - - /** - * Creates a new <code>PullUpAction</code>. The action requires that the - * selection provided by the site's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site - * the site providing context information for this action - */ - public PullUpAction(IWorkbenchSite site) { - super(site); - setText(RefactoringMessages.RefactoringGroup_pull_Up_label); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.PULL_UP_ACTION); - } - - private IMember getSelectedMemberFromEditor() throws JavaScriptModelException { - IJavaScriptElement element= SelectionConverter.resolveEnclosingElement(fEditor, (ITextSelection) fEditor.getSelectionProvider().getSelection()); - if (element == null || !(element instanceof IMember)) - return null; - return (IMember) element; - } - - /** - * {@inheritDoc} - */ - public void run(IStructuredSelection selection) { - try { - IMember[] members= getSelectedMembers(selection); - if (RefactoringAvailabilityTester.isPullUpAvailable(members) && ActionUtil.isEditable(getShell(), members[0])) - RefactoringExecutionStarter.startPullUpRefactoring(members, getShell()); - } catch (JavaScriptModelException e) { - ExceptionHandler.handle(e, RefactoringMessages.OpenRefactoringWizardAction_refactoring, RefactoringMessages.OpenRefactoringWizardAction_exception); - } - } - - /** - * {@inheritDoc} - */ - public void run(ITextSelection selection) { - try { - if (!ActionUtil.isEditable(fEditor)) - return; - IMember member= getSelectedMemberFromEditor(); - IMember[] array= new IMember[] { member}; - if (member != null && RefactoringAvailabilityTester.isPullUpAvailable(array)) { - RefactoringExecutionStarter.startPullUpRefactoring(array, getShell()); - } else { - MessageDialog.openInformation(getShell(), RefactoringMessages.OpenRefactoringWizardAction_unavailable, RefactoringMessages.PullUpAction_unavailable); - } - } catch (JavaScriptModelException e) { - ExceptionHandler.handle(e, RefactoringMessages.OpenRefactoringWizardAction_refactoring, RefactoringMessages.OpenRefactoringWizardAction_exception); - } - } - - /** - * {@inheritDoc} - */ - public void selectionChanged(IStructuredSelection selection) { - try { - setEnabled(RefactoringAvailabilityTester.isPullUpAvailable(selection)); - } catch (JavaScriptModelException e) { - // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253 - if (JavaModelUtil.isExceptionToBeLogged(e)) - JavaScriptPlugin.log(e); - setEnabled(false);// no UI - } - } - - /** - * {@inheritDoc} - */ - public void selectionChanged(ITextSelection selection) { - setEnabled(true); - } - - /** - * Note: This method is for internal use only. Clients should not call this - * method. - */ - public void selectionChanged(JavaTextSelection selection) { - try { - setEnabled(RefactoringAvailabilityTester.isPullUpAvailable(selection)); - } catch (JavaScriptModelException e) { - setEnabled(false); - } - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/PushDownAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/PushDownAction.java deleted file mode 100644 index 56978a08..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/PushDownAction.java +++ /dev/null @@ -1,179 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.IMember; -import org.eclipse.wst.jsdt.core.IType; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.internal.corext.refactoring.RefactoringAvailabilityTester; -import org.eclipse.wst.jsdt.internal.corext.refactoring.RefactoringExecutionStarter; -import org.eclipse.wst.jsdt.internal.corext.util.JavaModelUtil; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaTextSelection; -import org.eclipse.wst.jsdt.internal.ui.refactoring.RefactoringMessages; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; - -/** - * Action to push down methods and fields into subclasses. - * <p> - * Action is applicable to selections containing elements of type - * <code>IField</code> and <code>IFunction</code>. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class PushDownAction extends SelectionDispatchAction { - - private static IMember[] getSelectedMembers(IStructuredSelection selection) { - if (selection.isEmpty()) - return null; - if (selection.size() == 1) { - try { - final IType type= RefactoringAvailabilityTester.getSingleSelectedType(selection); - if (type != null) - return new IType[] { type}; - } catch (JavaScriptModelException exception) { - JavaScriptPlugin.log(exception); - } - } - for (Iterator iter= selection.iterator(); iter.hasNext();) { - if (!(iter.next() instanceof IMember)) - return null; - } - Set memberSet= new HashSet(); - memberSet.addAll(Arrays.asList(selection.toArray())); - return (IMember[]) memberSet.toArray(new IMember[memberSet.size()]); - } - - private JavaEditor fEditor; - - /** - * Note: This constructor is for internal use only. Clients should not call - * this constructor. - * - * @param editor the JavaScript editor - */ - public PushDownAction(JavaEditor editor) { - this(editor.getEditorSite()); - fEditor= editor; - setEnabled(SelectionConverter.canOperateOn(fEditor)); - } - - /** - * Creates a new <code>PushDownAction</code>. The action requires that - * the selection provided by the site's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site - * the site providing context information for this action - */ - public PushDownAction(IWorkbenchSite site) { - super(site); - setText(RefactoringMessages.PushDownAction_Push_Down); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.PUSH_DOWN_ACTION); - } - - private IMember getSelectedMemberFromEditor() throws JavaScriptModelException { - IJavaScriptElement element= SelectionConverter.resolveEnclosingElement(fEditor, (ITextSelection) fEditor.getSelectionProvider().getSelection()); - if (element == null || !(element instanceof IMember)) - return null; - return (IMember) element; - } - - /** - * {@inheritDoc} - */ - public void run(IStructuredSelection selection) { - try { - IMember[] members= getSelectedMembers(selection); - if (RefactoringAvailabilityTester.isPushDownAvailable(members) && ActionUtil.isEditable(getShell(), members[0])) - RefactoringExecutionStarter.startPushDownRefactoring(members, getShell()); - } catch (JavaScriptModelException e) { - ExceptionHandler.handle(e, RefactoringMessages.OpenRefactoringWizardAction_refactoring, RefactoringMessages.OpenRefactoringWizardAction_exception); - } - } - - /** - * {@inheritDoc} - */ - public void run(ITextSelection selection) { - try { - if (!ActionUtil.isEditable(fEditor)) - return; - IMember member= getSelectedMemberFromEditor(); - IMember[] array= new IMember[] { member}; - if (member != null && RefactoringAvailabilityTester.isPushDownAvailable(array)) { - RefactoringExecutionStarter.startPushDownRefactoring(array, getShell()); - } else { - MessageDialog.openInformation(getShell(), RefactoringMessages.OpenRefactoringWizardAction_unavailable, RefactoringMessages.PushDownAction_To_activate); - } - } catch (JavaScriptModelException e) { - ExceptionHandler.handle(e, RefactoringMessages.OpenRefactoringWizardAction_refactoring, RefactoringMessages.OpenRefactoringWizardAction_exception); - } - } - - /** - * {@inheritDoc} - */ - public void selectionChanged(IStructuredSelection selection) { - try { - setEnabled(RefactoringAvailabilityTester.isPushDownAvailable(selection)); - } catch (JavaScriptModelException e) { - // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253 - if (JavaModelUtil.isExceptionToBeLogged(e)) - JavaScriptPlugin.log(e); - setEnabled(false);// no UI - } - } - - /** - * {@inheritDoc} - */ - public void selectionChanged(ITextSelection selection) { - setEnabled(true); - } - - /** - * Note: This method is for internal use only. Clients should not call this - * method. - * - * @param selection - */ - public void selectionChanged(JavaTextSelection selection) { - try { - setEnabled(RefactoringAvailabilityTester.isPushDownAvailable(selection)); - } catch (JavaScriptModelException e) { - setEnabled(false); - } - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ReadReferencesSearchGroup.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ReadReferencesSearchGroup.java deleted file mode 100644 index e37e4d99..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ReadReferencesSearchGroup.java +++ /dev/null @@ -1,205 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.util.Iterator; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.IWorkingSet; -import org.eclipse.ui.actions.ActionGroup; -import org.eclipse.ui.texteditor.ITextEditorActionConstants; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.search.SearchMessages; -import org.eclipse.wst.jsdt.internal.ui.search.SearchUtil; -import org.eclipse.wst.jsdt.ui.IContextMenuConstants; - -/** - * Action group that adds the search for read references actions to a - * context menu and the global menu bar. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class ReadReferencesSearchGroup extends ActionGroup { - - private static final String MENU_TEXT= SearchMessages.group_readReferences; - - private IWorkbenchSite fSite; - private JavaEditor fEditor; - private IActionBars fActionBars; - - private String fGroupId; - - private FindReadReferencesAction fFindReadReferencesAction; - private FindReadReferencesInProjectAction fFindReadReferencesInProjectAction; - private FindReadReferencesInHierarchyAction fFindReadReferencesInHierarchyAction; - private FindReadReferencesInWorkingSetAction fFindReadReferencesInWorkingSetAction; - - /** - * Creates a new <code>ReadReferencesSearchGroup</code>. The group requires - * that the selection provided by the site's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the view part that owns this action group - */ - public ReadReferencesSearchGroup(IWorkbenchSite site) { - fSite= site; - fGroupId= IContextMenuConstants.GROUP_SEARCH; - - fFindReadReferencesAction= new FindReadReferencesAction(site); - fFindReadReferencesAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_WORKSPACE); - - fFindReadReferencesInProjectAction= new FindReadReferencesInProjectAction(site); - fFindReadReferencesInProjectAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_READ_ACCESS_IN_PROJECT); - - fFindReadReferencesInHierarchyAction= new FindReadReferencesInHierarchyAction(site); - fFindReadReferencesInHierarchyAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_HIERARCHY); - - fFindReadReferencesInWorkingSetAction= new FindReadReferencesInWorkingSetAction(site); - fFindReadReferencesInWorkingSetAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_WORKING_SET); - - // register the actions as selection listeners - ISelectionProvider provider= fSite.getSelectionProvider(); - ISelection selection= provider.getSelection(); - registerAction(fFindReadReferencesAction, provider, selection); - registerAction(fFindReadReferencesInProjectAction, provider, selection); - registerAction(fFindReadReferencesInHierarchyAction, provider, selection); - registerAction(fFindReadReferencesInWorkingSetAction, provider, selection); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public ReadReferencesSearchGroup(JavaEditor editor) { - fEditor= editor; - fSite= fEditor.getSite(); - fGroupId= ITextEditorActionConstants.GROUP_FIND; - - fFindReadReferencesAction= new FindReadReferencesAction(fEditor); - fFindReadReferencesAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_WORKSPACE); - fEditor.setAction("SearchReadAccessInWorkspace", fFindReadReferencesAction); //$NON-NLS-1$ - - fFindReadReferencesInProjectAction= new FindReadReferencesInProjectAction(fEditor); - fFindReadReferencesInProjectAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_READ_ACCESS_IN_PROJECT); - fEditor.setAction("SearchReadAccessInProject", fFindReadReferencesInProjectAction); //$NON-NLS-1$ - - fFindReadReferencesInHierarchyAction= new FindReadReferencesInHierarchyAction(fEditor); - fFindReadReferencesInHierarchyAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_HIERARCHY); - fEditor.setAction("SearchReadAccessInHierarchy", fFindReadReferencesInHierarchyAction); //$NON-NLS-1$ - - fFindReadReferencesInWorkingSetAction= new FindReadReferencesInWorkingSetAction(fEditor); - fFindReadReferencesInWorkingSetAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_WORKING_SET); - fEditor.setAction("SearchReadAccessInWorkingSet", fFindReadReferencesInWorkingSetAction); //$NON-NLS-1$ - } - - private void registerAction(SelectionDispatchAction action, ISelectionProvider provider, ISelection selection) { - action.update(selection); - provider.addSelectionChangedListener(action); - } - - private void addAction(IAction action, IMenuManager manager) { - if (action.isEnabled()) { - manager.add(action); - } - } - - private void addWorkingSetAction(IWorkingSet[] workingSets, IMenuManager manager) { - FindAction action; - if (fEditor != null) - action= new WorkingSetFindAction(fEditor, new FindReadReferencesInWorkingSetAction(fEditor, workingSets), SearchUtil.toString(workingSets)); - else - action= new WorkingSetFindAction(fSite, new FindReadReferencesInWorkingSetAction(fSite, workingSets), SearchUtil.toString(workingSets)); - action.update(getContext().getSelection()); - addAction(action, manager); - } - - - /* (non-Javadoc) - * Method declared on ActionGroup. - */ - public void fillContextMenu(IMenuManager manager) { - MenuManager javaSearchMM= new MenuManager(MENU_TEXT, IContextMenuConstants.GROUP_SEARCH); - addAction(fFindReadReferencesAction, javaSearchMM); - addAction(fFindReadReferencesInProjectAction, javaSearchMM); - addAction(fFindReadReferencesInHierarchyAction, javaSearchMM); - - javaSearchMM.add(new Separator()); - - Iterator iter= SearchUtil.getLRUWorkingSets().sortedIterator(); - while (iter.hasNext()) { - addWorkingSetAction((IWorkingSet[]) iter.next(), javaSearchMM); - } - addAction(fFindReadReferencesInWorkingSetAction, javaSearchMM); - - if (!javaSearchMM.isEmpty()) - manager.appendToGroup(fGroupId, javaSearchMM); - } - - /* - * Method declared on ActionGroup. - */ - public void fillActionBars(IActionBars actionBars) { - Assert.isNotNull(actionBars); - super.fillActionBars(actionBars); - fActionBars= actionBars; - updateGlobalActionHandlers(); - } - - /* - * Method declared on ActionGroup. - */ - public void dispose() { - ISelectionProvider provider= fSite.getSelectionProvider(); - if (provider != null) { - disposeAction(fFindReadReferencesAction, provider); - disposeAction(fFindReadReferencesInProjectAction, provider); - disposeAction(fFindReadReferencesInHierarchyAction, provider); - disposeAction(fFindReadReferencesInWorkingSetAction, provider); - } - fFindReadReferencesAction= null; - fFindReadReferencesInProjectAction= null; - fFindReadReferencesInHierarchyAction= null; - fFindReadReferencesInWorkingSetAction= null; - updateGlobalActionHandlers(); - super.dispose(); - } - - private void updateGlobalActionHandlers() { - if (fActionBars != null) { - fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_READ_ACCESS_IN_WORKSPACE, fFindReadReferencesAction); - fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_READ_ACCESS_IN_PROJECT, fFindReadReferencesInProjectAction); - fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_READ_ACCESS_IN_HIERARCHY, fFindReadReferencesInHierarchyAction); - fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_READ_ACCESS_IN_WORKING_SET, fFindReadReferencesInWorkingSetAction); - } - } - - private void disposeAction(ISelectionChangedListener action, ISelectionProvider provider) { - if (action != null) - provider.removeSelectionChangedListener(action); - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/RefactorActionGroup.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/RefactorActionGroup.java deleted file mode 100644 index 1506ca0a..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/RefactorActionGroup.java +++ /dev/null @@ -1,670 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.commands.operations.IUndoContext; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.PerformanceStats; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuListener; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.jface.commands.ActionHandler; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.swt.events.MenuAdapter; -import org.eclipse.swt.events.MenuEvent; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.actions.ActionFactory; -import org.eclipse.ui.actions.ActionGroup; -import org.eclipse.ui.handlers.IHandlerActivation; -import org.eclipse.ui.handlers.IHandlerService; -import org.eclipse.ui.operations.UndoRedoActionGroup; -import org.eclipse.ui.part.Page; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.internal.ui.IUIConstants; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.ExtractSuperClassAction; -import org.eclipse.wst.jsdt.internal.ui.actions.JDTQuickMenuAction; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.IClassFileEditorInput; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaTextSelection; -import org.eclipse.wst.jsdt.internal.ui.refactoring.RefactoringMessages; -import org.eclipse.wst.jsdt.ui.IContextMenuConstants; - -/** - * Action group that adds refactor actions (for example 'Rename', 'Move') - * to a context menu and the global menu bar. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class RefactorActionGroup extends ActionGroup { - - private static final String PERF_REFACTOR_ACTION_GROUP= "org.eclipse.wst.jsdt.ui/perf/explorer/RefactorActionGroup"; //$NON-NLS-1$ - - /** - * Pop-up menu: id of the refactor sub menu (value <code>org.eclipse.wst.jsdt.ui.refactoring.menu</code>). - * - * - */ - public static final String MENU_ID= "org.eclipse.wst.jsdt.ui.refactoring.menu"; //$NON-NLS-1$ - - /** - * Pop-up menu: id of the reorg group of the refactor sub menu (value - * <code>reorgGroup</code>). - * - * - */ - public static final String GROUP_REORG= "reorgGroup"; //$NON-NLS-1$ - - /** - * Pop-up menu: id of the type group of the refactor sub menu (value - * <code>typeGroup</code>). - * - * - */ - public static final String GROUP_TYPE= "typeGroup"; //$NON-NLS-1$ - - /** - * Pop-up menu: id of the coding group of the refactor sub menu (value - * <code>codingGroup</code>). - * - * - */ - public static final String GROUP_CODING= "codingGroup"; //$NON-NLS-1$ - - /** - * Pop-up menu: id of the coding group 2 of the refactor sub menu (value - * <code>codingGroup2</code>). - * - * - */ - public static final String GROUP_CODING2= "codingGroup2"; //$NON-NLS-1$ - - /** - * Pop-up menu: id of the reorg group 2 of the refactor sub menu (value - * <code>reorgGroup2</code>). - * - * - */ - private static final String GROUP_REORG2= "reorgGroup2"; //$NON-NLS-1$ //TODO(3.3): make public - - /** - * Pop-up menu: id of the type group 2 of the refactor sub menu (value - * <code>typeGroup2</code>). - * - * - */ - private static final String GROUP_TYPE2= "typeGroup2"; //$NON-NLS-1$ //TODO(3.3): make public - - private IWorkbenchSite fSite; - private JavaEditor fEditor; - private String fGroupName= IContextMenuConstants.GROUP_REORGANIZE; - private boolean fBinary= false; - - private SelectionDispatchAction fMoveAction; - private SelectionDispatchAction fRenameAction; - private SelectionDispatchAction fModifyParametersAction; -// private SelectionDispatchAction fConvertAnonymousToNestedAction; -// private SelectionDispatchAction fConvertNestedToTopAction; - - private SelectionDispatchAction fPullUpAction; - private SelectionDispatchAction fPushDownAction; -// private SelectionDispatchAction fExtractInterfaceAction; - private SelectionDispatchAction fExtractSupertypeAction; -// private SelectionDispatchAction fChangeTypeAction; - private SelectionDispatchAction fUseSupertypeAction; - - private SelectionDispatchAction fInlineAction; -// private SelectionDispatchAction fReplaceInvocationsAction; - private SelectionDispatchAction fIntroduceIndirectionAction; - private SelectionDispatchAction fExtractMethodAction; - private SelectionDispatchAction fExtractTempAction; - private SelectionDispatchAction fExtractConstantAction; - private SelectionDispatchAction fIntroduceParameterAction; - private SelectionDispatchAction fIntroduceFactoryAction; - private SelectionDispatchAction fConvertLocalToFieldAction; - private SelectionDispatchAction fSelfEncapsulateField; - - private UndoRedoActionGroup fUndoRedoActionGroup; - - private final List fActions= new ArrayList(); - - private static final String QUICK_MENU_ID= "org.eclipse.wst.jsdt.ui.edit.text.java.refactor.quickMenu"; //$NON-NLS-1$ - - private class RefactorQuickAccessAction extends JDTQuickMenuAction { - public RefactorQuickAccessAction(JavaEditor editor) { - super(editor, QUICK_MENU_ID); - } - protected void fillMenu(IMenuManager menu) { - fillQuickMenu(menu); - } - } - - private JDTQuickMenuAction fQuickAccessAction; - private IHandlerActivation fQuickAccessHandlerActivation; - private IHandlerService fHandlerService; - - private static class NoActionAvailable extends Action { - public NoActionAvailable() { - setEnabled(true); - setText(RefactoringMessages.RefactorActionGroup_no_refactoring_available); - } - } - private Action fNoActionAvailable= new NoActionAvailable(); - - /** - * Creates a new <code>RefactorActionGroup</code>. The group requires - * that the selection provided by the part's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param part the view part that owns this action group - */ - public RefactorActionGroup(IViewPart part) { - this(part.getSite()); - - IUndoContext workspaceContext= (IUndoContext)ResourcesPlugin.getWorkspace().getAdapter(IUndoContext.class); - fUndoRedoActionGroup= new UndoRedoActionGroup(part.getViewSite(), workspaceContext, true); - } - - /** - * Creates a new <code>RefactorActionGroup</code>. The action requires - * that the selection provided by the page's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param page the page that owns this action group - */ - public RefactorActionGroup(Page page) { - this(page.getSite()); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - * @param groupName the group name to add the actions to - * @param binary <code>true</code> if the action group is used in a binary environment, <code>false</code> otherwise - */ - public RefactorActionGroup(JavaEditor editor, String groupName, boolean binary) { - - final PerformanceStats stats= PerformanceStats.getStats(PERF_REFACTOR_ACTION_GROUP, this); - stats.startRun(); - - fSite= editor.getEditorSite(); - fEditor= editor; - fGroupName= groupName; - fBinary= binary; - - ISelectionProvider provider= editor.getSelectionProvider(); - ISelection selection= provider.getSelection(); - - if (!fBinary) { - fRenameAction= new RenameAction(editor); - initAction(fRenameAction, selection, IJavaEditorActionDefinitionIds.RENAME_ELEMENT); - editor.setAction("RenameElement", fRenameAction); //$NON-NLS-1$ - - fMoveAction= new MoveAction(editor); - initAction(fMoveAction, selection, IJavaEditorActionDefinitionIds.MOVE_ELEMENT); - editor.setAction("MoveElement", fMoveAction); //$NON-NLS-1$ - - fModifyParametersAction= new ModifyParametersAction(editor); - initAction(fModifyParametersAction, selection, IJavaEditorActionDefinitionIds.MODIFY_METHOD_PARAMETERS); - editor.setAction("ModifyParameters", fModifyParametersAction); //$NON-NLS-1$ - -// fConvertAnonymousToNestedAction= new ConvertAnonymousToNestedAction(editor); -// initUpdatingAction(fConvertAnonymousToNestedAction, provider, selection, IJavaEditorActionDefinitionIds.CONVERT_ANONYMOUS_TO_NESTED); -// editor.setAction("ConvertAnonymousToNested", fConvertAnonymousToNestedAction); //$NON-NLS-1$ -// -// fConvertNestedToTopAction= new ConvertNestedToTopAction(editor); -// initAction(fConvertNestedToTopAction, selection, IJavaEditorActionDefinitionIds.MOVE_INNER_TO_TOP); -// editor.setAction("MoveInnerToTop", fConvertNestedToTopAction); //$NON-NLS-1$ - - if (IUIConstants.SUPPORT_REFACTORING) - { - fPullUpAction= new PullUpAction(editor); - initAction(fPullUpAction, selection, IJavaEditorActionDefinitionIds.PULL_UP); - editor.setAction("PullUp", fPullUpAction); //$NON-NLS-1$ - - fPushDownAction= new PushDownAction(editor); - initAction(fPushDownAction, selection, IJavaEditorActionDefinitionIds.PUSH_DOWN); - editor.setAction("PushDown", fPushDownAction); //$NON-NLS-1$ - - fExtractSupertypeAction= new ExtractSuperClassAction(editor); - initAction(fExtractSupertypeAction, selection, ExtractSuperClassAction.EXTRACT_SUPERTYPE); - editor.setAction("ExtractSupertype", fExtractSupertypeAction); //$NON-NLS-1$ - - } - - fExtractMethodAction= new ExtractMethodAction(editor); - initUpdatingAction(fExtractMethodAction, provider, selection, IJavaEditorActionDefinitionIds.EXTRACT_METHOD); - editor.setAction("ExtractMethod", fExtractMethodAction); //$NON-NLS-1$ - - fExtractTempAction= new ExtractTempAction(editor); - initUpdatingAction(fExtractTempAction, provider, selection, IJavaEditorActionDefinitionIds.EXTRACT_LOCAL_VARIABLE); - editor.setAction("ExtractLocalVariable", fExtractTempAction); //$NON-NLS-1$ - - fExtractConstantAction= new ExtractConstantAction(editor); - initUpdatingAction(fExtractConstantAction, provider, selection, IJavaEditorActionDefinitionIds.EXTRACT_CONSTANT); - editor.setAction("ExtractConstant", fExtractConstantAction); //$NON-NLS-1$ - - fIntroduceParameterAction= new IntroduceParameterAction(editor); - initUpdatingAction(fIntroduceParameterAction, provider, selection, IJavaEditorActionDefinitionIds.INTRODUCE_PARAMETER); - editor.setAction("IntroduceParameter", fIntroduceParameterAction); //$NON-NLS-1$ - - if (IUIConstants.SUPPORT_REFACTORING) { - fIntroduceFactoryAction = new IntroduceFactoryAction(editor); - initUpdatingAction(fIntroduceFactoryAction, provider, - selection, - IJavaEditorActionDefinitionIds.INTRODUCE_FACTORY); - editor.setAction("IntroduceFactory", fIntroduceFactoryAction); //$NON-NLS-1$ - fConvertLocalToFieldAction = new ConvertLocalToFieldAction( - editor); - initUpdatingAction(fConvertLocalToFieldAction, provider, - selection, - IJavaEditorActionDefinitionIds.PROMOTE_LOCAL_VARIABLE); - editor.setAction("PromoteTemp", fConvertLocalToFieldAction); //$NON-NLS-1$ - fSelfEncapsulateField = new SelfEncapsulateFieldAction(editor); - initAction(fSelfEncapsulateField, selection, - IJavaEditorActionDefinitionIds.SELF_ENCAPSULATE_FIELD); - editor.setAction("SelfEncapsulateField", fSelfEncapsulateField); //$NON-NLS-1$ - } - } - if (IUIConstants.SUPPORT_REFACTORING) { - fIntroduceIndirectionAction = new IntroduceIndirectionAction(editor); - initUpdatingAction(fIntroduceIndirectionAction, provider, - selection, - IJavaEditorActionDefinitionIds.INTRODUCE_INDIRECTION); - editor.setAction( - "IntroduceIndirection", fIntroduceIndirectionAction); //$NON-NLS-1$ - fUseSupertypeAction = new UseSupertypeAction(editor); - initAction(fUseSupertypeAction, selection, - IJavaEditorActionDefinitionIds.USE_SUPERTYPE); - editor.setAction("UseSupertype", fUseSupertypeAction); //$NON-NLS-1$ - } - fInlineAction= new InlineAction(editor); - initAction(fInlineAction, selection, IJavaEditorActionDefinitionIds.INLINE); - editor.setAction("Inline", fInlineAction); //$NON-NLS-1$ - - installQuickAccessAction(); - - stats.endRun(); - } - - private RefactorActionGroup(IWorkbenchSite site) { - - final PerformanceStats stats= PerformanceStats.getStats(PERF_REFACTOR_ACTION_GROUP, this); - stats.startRun(); - - fSite= site; - ISelectionProvider provider= fSite.getSelectionProvider(); - ISelection selection= provider.getSelection(); - - if (!fBinary) { - - fMoveAction= new MoveAction(site); - initUpdatingAction(fMoveAction, provider, selection, IJavaEditorActionDefinitionIds.MOVE_ELEMENT); - - fRenameAction= new RenameAction(site); - initUpdatingAction(fRenameAction, provider, selection, IJavaEditorActionDefinitionIds.RENAME_ELEMENT); - - fModifyParametersAction= new ModifyParametersAction(fSite); - initUpdatingAction(fModifyParametersAction, provider, selection, IJavaEditorActionDefinitionIds.MODIFY_METHOD_PARAMETERS); - - if (IUIConstants.SUPPORT_REFACTORING) { - fPullUpAction = new PullUpAction(fSite); - initUpdatingAction(fPullUpAction, provider, selection, - IJavaEditorActionDefinitionIds.PULL_UP); - fPushDownAction = new PushDownAction(fSite); - initUpdatingAction(fPushDownAction, provider, selection, - IJavaEditorActionDefinitionIds.PUSH_DOWN); - fSelfEncapsulateField = new SelfEncapsulateFieldAction(fSite); - initUpdatingAction(fSelfEncapsulateField, provider, selection, - IJavaEditorActionDefinitionIds.SELF_ENCAPSULATE_FIELD); - fExtractSupertypeAction = new ExtractSuperClassAction(fSite); - initUpdatingAction(fExtractSupertypeAction, provider, - selection, ExtractSuperClassAction.EXTRACT_SUPERTYPE); - fIntroduceFactoryAction = new IntroduceFactoryAction(fSite); - initUpdatingAction(fIntroduceFactoryAction, provider, - selection, - IJavaEditorActionDefinitionIds.INTRODUCE_FACTORY); - } - -// fConvertAnonymousToNestedAction= new ConvertAnonymousToNestedAction(fSite); -// initUpdatingAction(fConvertAnonymousToNestedAction, provider, selection, IJavaEditorActionDefinitionIds.CONVERT_ANONYMOUS_TO_NESTED); - } - fInlineAction= new InlineAction(fSite); - initUpdatingAction(fInlineAction, provider, selection, IJavaEditorActionDefinitionIds.INLINE); - - if (IUIConstants.SUPPORT_REFACTORING) { - fUseSupertypeAction = new UseSupertypeAction(fSite); - initUpdatingAction(fUseSupertypeAction, provider, selection, - IJavaEditorActionDefinitionIds.USE_SUPERTYPE); - fIntroduceIndirectionAction = new IntroduceIndirectionAction(fSite); - initUpdatingAction(fIntroduceIndirectionAction, provider, - selection, - IJavaEditorActionDefinitionIds.INTRODUCE_INDIRECTION); - } - installQuickAccessAction(); - - stats.endRun(); - } - - private void installQuickAccessAction() { - fHandlerService= (IHandlerService)fSite.getService(IHandlerService.class); - if (fHandlerService != null) { - fQuickAccessAction= new RefactorQuickAccessAction(fEditor); - fQuickAccessHandlerActivation= fHandlerService.activateHandler(fQuickAccessAction.getActionDefinitionId(), new ActionHandler(fQuickAccessAction)); - } - } - - private void initAction(SelectionDispatchAction action, ISelection selection, String actionDefinitionId){ - initUpdatingAction(action, null, selection, actionDefinitionId); - } - - /** - * Sets actionDefinitionId, updates enablement, adds to fActions, - * and adds selection changed listener if provider is not <code>null</code>. - * - * @param action - * @param provider can be <code>null</code> - * @param selection - * @param actionDefinitionId - */ - private void initUpdatingAction(SelectionDispatchAction action, ISelectionProvider provider, ISelection selection, String actionDefinitionId){ - action.setActionDefinitionId(actionDefinitionId); - action.update(selection); - if (provider != null) - provider.addSelectionChangedListener(action); - fActions.add(action); - } - - /* (non-Javadoc) - * Method declared in ActionGroup - */ - public void fillActionBars(IActionBars actionBars) { - super.fillActionBars(actionBars); - if (!fBinary) { - if (IUIConstants.SUPPORT_REFACTORING) - actionBars.setGlobalActionHandler(JdtActionConstants.SELF_ENCAPSULATE_FIELD, fSelfEncapsulateField); - actionBars.setGlobalActionHandler(JdtActionConstants.MOVE, fMoveAction); - actionBars.setGlobalActionHandler(JdtActionConstants.RENAME, fRenameAction); - actionBars.setGlobalActionHandler(JdtActionConstants.MODIFY_PARAMETERS, fModifyParametersAction); - if (IUIConstants.SUPPORT_REFACTORING) { - actionBars.setGlobalActionHandler(JdtActionConstants.PULL_UP, - fPullUpAction); - actionBars.setGlobalActionHandler(JdtActionConstants.PUSH_DOWN, - fPushDownAction); - } - actionBars.setGlobalActionHandler(JdtActionConstants.EXTRACT_TEMP, fExtractTempAction); - if (IUIConstants.SUPPORT_REFACTORING) { - actionBars.setGlobalActionHandler( - JdtActionConstants.EXTRACT_CONSTANT, - fExtractConstantAction); - actionBars.setGlobalActionHandler( - JdtActionConstants.INTRODUCE_PARAMETER, - fIntroduceParameterAction); - actionBars.setGlobalActionHandler( - JdtActionConstants.INTRODUCE_FACTORY, - fIntroduceFactoryAction); - } - actionBars.setGlobalActionHandler(JdtActionConstants.EXTRACT_METHOD, fExtractMethodAction); - // actionBars.setGlobalActionHandler(JdtActionConstants.REPLACE_INVOCATIONS, fReplaceInvocationsAction); -// actionBars.setGlobalActionHandler(JdtActionConstants.EXTRACT_INTERFACE, fExtractInterfaceAction); - if (IUIConstants.SUPPORT_REFACTORING) { - actionBars.setGlobalActionHandler(ExtractSuperClassAction.EXTRACT_SUPERTYPES, fExtractSupertypeAction); - // actionBars.setGlobalActionHandler(JdtActionConstants.CHANGE_TYPE, fChangeTypeAction); - // actionBars.setGlobalActionHandler(JdtActionConstants.CONVERT_NESTED_TO_TOP, fConvertNestedToTopAction); - actionBars.setGlobalActionHandler(JdtActionConstants.CONVERT_LOCAL_TO_FIELD, fConvertLocalToFieldAction); - // actionBars.setGlobalActionHandler(JdtActionConstants.CONVERT_ANONYMOUS_TO_NESTED, fConvertAnonymousToNestedAction); - } - } - if (IUIConstants.SUPPORT_REFACTORING) { - actionBars.setGlobalActionHandler(JdtActionConstants.INLINE, fInlineAction); - actionBars.setGlobalActionHandler(JdtActionConstants.USE_SUPERTYPE, fUseSupertypeAction); - actionBars.setGlobalActionHandler(JdtActionConstants.INTRODUCE_INDIRECTION, fIntroduceIndirectionAction); - } - if (fUndoRedoActionGroup != null) { - fUndoRedoActionGroup.fillActionBars(actionBars); - } - } - - /** - * Retargets the File actions with the corresponding refactoring actions. - * - * @param actionBars the action bar to register the move and rename action with - */ - public void retargetFileMenuActions(IActionBars actionBars) { - actionBars.setGlobalActionHandler(ActionFactory.RENAME.getId(), fRenameAction); - actionBars.setGlobalActionHandler(ActionFactory.MOVE.getId(), fMoveAction); - } - - /* (non-Javadoc) - * Method declared in ActionGroup - */ - public void fillContextMenu(IMenuManager menu) { - super.fillContextMenu(menu); - addRefactorSubmenu(menu); - } - - /* - * @see ActionGroup#dispose() - */ - public void dispose() { - ISelectionProvider provider= fSite.getSelectionProvider(); - if (!fBinary) { - disposeAction(fMoveAction, provider); - disposeAction(fRenameAction, provider); - disposeAction(fExtractTempAction, provider); - disposeAction(fIntroduceParameterAction, provider); - disposeAction(fExtractMethodAction, provider); - if (IUIConstants.SUPPORT_REFACTORING) { - disposeAction(fSelfEncapsulateField, provider); - disposeAction(fModifyParametersAction, provider); - disposeAction(fPullUpAction, provider); - disposeAction(fPushDownAction, provider); - disposeAction(fExtractConstantAction, provider); - disposeAction(fIntroduceFactoryAction, provider); - // disposeAction(fReplaceInvocationsAction, provider); - // disposeAction(fExtractInterfaceAction, provider); - disposeAction(fExtractSupertypeAction, provider); - // disposeAction(fChangeTypeAction, provider); - // disposeAction(fConvertNestedToTopAction, provider); - disposeAction(fConvertLocalToFieldAction, provider); - // disposeAction(fConvertAnonymousToNestedAction, provider); - } - } - if (IUIConstants.SUPPORT_REFACTORING) { - disposeAction(fIntroduceIndirectionAction, provider); - disposeAction(fInlineAction, provider); - disposeAction(fUseSupertypeAction, provider); - } - if (fQuickAccessHandlerActivation != null && fHandlerService != null) { - fHandlerService.deactivateHandler(fQuickAccessHandlerActivation); - } - if (fUndoRedoActionGroup != null) { - fUndoRedoActionGroup.dispose(); - } - super.dispose(); - } - - private void disposeAction(ISelectionChangedListener action, ISelectionProvider provider) { - if (action != null) - provider.removeSelectionChangedListener(action); - } - - private void addRefactorSubmenu(IMenuManager menu) { - String menuText= ActionMessages.RefactorMenu_label; - if (fQuickAccessAction != null) { - menuText= fQuickAccessAction.addShortcut(menuText); - } - IMenuManager refactorSubmenu= new MenuManager(menuText, MENU_ID); - if (fEditor != null) { - IJavaScriptElement element= SelectionConverter.getInput(fEditor); - if (element != null && ActionUtil.isOnBuildPath(element)) { - refactorSubmenu.addMenuListener(new IMenuListener() { - public void menuAboutToShow(IMenuManager manager) { - refactorMenuShown(manager); - } - }); - refactorSubmenu.add(fNoActionAvailable); - menu.appendToGroup(fGroupName, refactorSubmenu); - } - } else { - ISelection selection= fSite.getSelectionProvider().getSelection(); - for (Iterator iter= fActions.iterator(); iter.hasNext(); ) { - ((SelectionDispatchAction)iter.next()).update(selection); - } - if (fillRefactorMenu(refactorSubmenu) > 0) - menu.appendToGroup(fGroupName, refactorSubmenu); - } - } - - private int fillRefactorMenu(IMenuManager refactorSubmenu) { - int added= 0; - refactorSubmenu.add(new Separator(GROUP_REORG)); - added+= addAction(refactorSubmenu, fRenameAction); - added+= addAction(refactorSubmenu, fMoveAction); - refactorSubmenu.add(new Separator(GROUP_CODING)); - added+= addAction(refactorSubmenu, fModifyParametersAction); - added+= addAction(refactorSubmenu, fExtractMethodAction); - added+= addAction(refactorSubmenu, fExtractTempAction); - if (IUIConstants.SUPPORT_REFACTORING) { - added += addAction(refactorSubmenu, fExtractConstantAction); - added += addAction(refactorSubmenu, fInlineAction); - refactorSubmenu.add(new Separator(GROUP_REORG2)); - // added+= addAction(refactorSubmenu, fConvertAnonymousToNestedAction); - // added+= addAction(refactorSubmenu, fConvertNestedToTopAction); - added += addAction(refactorSubmenu, fConvertLocalToFieldAction); - refactorSubmenu.add(new Separator(GROUP_TYPE)); - // added+= addAction(refactorSubmenu, fExtractInterfaceAction); - added += addAction(refactorSubmenu, fExtractSupertypeAction); - added += addAction(refactorSubmenu, fUseSupertypeAction); - added += addAction(refactorSubmenu, fPullUpAction); - added += addAction(refactorSubmenu, fPushDownAction); - } - refactorSubmenu.add(new Separator(GROUP_CODING2)); - if (IUIConstants.SUPPORT_REFACTORING) { - added += addAction(refactorSubmenu, fIntroduceIndirectionAction); - added += addAction(refactorSubmenu, fIntroduceFactoryAction); - } - added+= addAction(refactorSubmenu, fIntroduceParameterAction); - if (IUIConstants.SUPPORT_REFACTORING) - added+= addAction(refactorSubmenu, fSelfEncapsulateField); -// added+= addAction(refactorSubmenu, fReplaceInvocationsAction); - if (IUIConstants.SUPPORT_REFACTORING) { - refactorSubmenu.add(new Separator(GROUP_TYPE2)); - } - return added; - } - - private int addAction(IMenuManager menu, IAction action) { - if (action != null && action.isEnabled()) { - menu.add(action); - return 1; - } - return 0; - } - - private void refactorMenuShown(final IMenuManager refactorSubmenu) { - // we know that we have an MenuManager since we created it in - // addRefactorSubmenu. - Menu menu= ((MenuManager)refactorSubmenu).getMenu(); - menu.addMenuListener(new MenuAdapter() { - public void menuHidden(MenuEvent e) { - refactorMenuHidden(refactorSubmenu); - } - }); - ITextSelection textSelection= (ITextSelection)fEditor.getSelectionProvider().getSelection(); - JavaTextSelection javaSelection= new JavaTextSelection( - getEditorInput(), getDocument(), textSelection.getOffset(), textSelection.getLength()); - - for (Iterator iter= fActions.iterator(); iter.hasNext(); ) { - SelectionDispatchAction action= (SelectionDispatchAction)iter.next(); - action.update(javaSelection); - } - refactorSubmenu.removeAll(); - if (fillRefactorMenu(refactorSubmenu) == 0) - refactorSubmenu.add(fNoActionAvailable); - } - - private void refactorMenuHidden(IMenuManager manager) { - ITextSelection textSelection= (ITextSelection)fEditor.getSelectionProvider().getSelection(); - for (Iterator iter= fActions.iterator(); iter.hasNext(); ) { - SelectionDispatchAction action= (SelectionDispatchAction)iter.next(); - action.update(textSelection); - } - } - - private IJavaScriptElement getEditorInput() { - final IEditorInput input= fEditor.getEditorInput(); - if (input instanceof IClassFileEditorInput) { - IClassFileEditorInput extended= (IClassFileEditorInput) input; - return extended.getClassFile(); - } - return JavaScriptPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(input); - } - - private IDocument getDocument() { - return JavaScriptPlugin.getDefault().getCompilationUnitDocumentProvider(). - getDocument(fEditor.getEditorInput()); - } - - private void fillQuickMenu(IMenuManager menu) { - if (fEditor != null) { - IJavaScriptElement element= SelectionConverter.getInput(fEditor); - if (element == null || !ActionUtil.isOnBuildPath(element)) { - menu.add(fNoActionAvailable); - return; - } - ITextSelection textSelection= (ITextSelection)fEditor.getSelectionProvider().getSelection(); - JavaTextSelection javaSelection= new JavaTextSelection( - getEditorInput(), getDocument(), textSelection.getOffset(), textSelection.getLength()); - - for (Iterator iter= fActions.iterator(); iter.hasNext(); ) { - ((SelectionDispatchAction)iter.next()).update(javaSelection); - } - fillRefactorMenu(menu); - for (Iterator iter= fActions.iterator(); iter.hasNext(); ) { - ((SelectionDispatchAction)iter.next()).update(textSelection); - } - - } else { - ISelection selection= fSite.getSelectionProvider().getSelection(); - for (Iterator iter= fActions.iterator(); iter.hasNext(); ) { - ((SelectionDispatchAction)iter.next()).update(selection); - } - fillRefactorMenu(menu); - } - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ReferencesSearchGroup.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ReferencesSearchGroup.java deleted file mode 100644 index 8c62ce09..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ReferencesSearchGroup.java +++ /dev/null @@ -1,217 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.util.Iterator; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.IWorkingSet; -import org.eclipse.ui.actions.ActionGroup; -import org.eclipse.ui.texteditor.ITextEditorActionConstants; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.search.SearchMessages; -import org.eclipse.wst.jsdt.internal.ui.search.SearchUtil; -import org.eclipse.wst.jsdt.ui.IContextMenuConstants; - -/** - * Action group that adds the search for references actions to a - * context menu and the global menu bar. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class ReferencesSearchGroup extends ActionGroup { - - private static final String MENU_TEXT= SearchMessages.group_references; - - private IWorkbenchSite fSite; - private JavaEditor fEditor; - private IActionBars fActionBars; - - private String fGroupId; - - private FindReferencesAction fFindReferencesAction; - private FindReferencesInProjectAction fFindReferencesInProjectAction; - private FindReferencesInHierarchyAction fFindReferencesInHierarchyAction; - private FindReferencesInWorkingSetAction fFindReferencesInWorkingSetAction; - - /** - * Creates a new <code>ReferencesSearchGroup</code>. The group requires - * that the selection provided by the site's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the view part that owns this action group - */ - public ReferencesSearchGroup(IWorkbenchSite site) { - fSite= site; - fGroupId= IContextMenuConstants.GROUP_SEARCH; - - fFindReferencesAction= new FindReferencesAction(site); - fFindReferencesAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_REFERENCES_IN_WORKSPACE); - - fFindReferencesInProjectAction= new FindReferencesInProjectAction(site); - fFindReferencesInProjectAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_REFERENCES_IN_PROJECT); - - fFindReferencesInHierarchyAction= new FindReferencesInHierarchyAction(site); - fFindReferencesInHierarchyAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_REFERENCES_IN_HIERARCHY); - - fFindReferencesInWorkingSetAction= new FindReferencesInWorkingSetAction(site); - fFindReferencesInWorkingSetAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_REFERENCES_IN_WORKING_SET); - - // register the actions as selection listeners - ISelectionProvider provider= fSite.getSelectionProvider(); - ISelection selection= provider.getSelection(); - registerAction(fFindReferencesAction, provider, selection); - registerAction(fFindReferencesInProjectAction, provider, selection); - registerAction(fFindReferencesInHierarchyAction, provider, selection); - registerAction(fFindReferencesInWorkingSetAction, provider, selection); - } - - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public ReferencesSearchGroup(JavaEditor editor) { - Assert.isNotNull(editor); - fEditor= editor; - fSite= fEditor.getSite(); - fGroupId= ITextEditorActionConstants.GROUP_FIND; - - fFindReferencesAction= new FindReferencesAction(editor); - fFindReferencesAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_REFERENCES_IN_WORKSPACE); - fEditor.setAction("SearchReferencesInWorkspace", fFindReferencesAction); //$NON-NLS-1$ - - fFindReferencesInProjectAction= new FindReferencesInProjectAction(fEditor); - fFindReferencesInProjectAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_REFERENCES_IN_PROJECT); - fEditor.setAction("SearchReferencesInProject", fFindReferencesInProjectAction); //$NON-NLS-1$ - - fFindReferencesInHierarchyAction= new FindReferencesInHierarchyAction(fEditor); - fFindReferencesInHierarchyAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_REFERENCES_IN_HIERARCHY); - fEditor.setAction("SearchReferencesInHierarchy", fFindReferencesInHierarchyAction); //$NON-NLS-1$ - - fFindReferencesInWorkingSetAction= new FindReferencesInWorkingSetAction(fEditor); - fFindReferencesInWorkingSetAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_REFERENCES_IN_WORKING_SET); - fEditor.setAction("SearchReferencesInWorkingSet", fFindReferencesInWorkingSetAction); //$NON-NLS-1$ - } - - private void registerAction(SelectionDispatchAction action, ISelectionProvider provider, ISelection selection) { - action.update(selection); - provider.addSelectionChangedListener(action); - } - - /** - * Note: this method is for internal use only. Clients should not call this method. - * - * @return the menu label - */ - protected String getName() { - return MENU_TEXT; - } - - /* (non-Javadoc) - * Method declared in ActionGroup - */ - public void fillActionBars(IActionBars actionBars) { - Assert.isNotNull(actionBars); - super.fillActionBars(actionBars); - fActionBars= actionBars; - updateGlobalActionHandlers(); - } - - - private void addAction(IAction action, IMenuManager manager) { - if (action.isEnabled()) { - manager.add(action); - } - } - - private void addWorkingSetAction(IWorkingSet[] workingSets, IMenuManager manager) { - FindAction action; - if (fEditor != null) - action= new WorkingSetFindAction(fEditor, new FindReferencesInWorkingSetAction(fEditor, workingSets), SearchUtil.toString(workingSets)); - else - action= new WorkingSetFindAction(fSite, new FindReferencesInWorkingSetAction(fSite, workingSets), SearchUtil.toString(workingSets)); - action.update(getContext().getSelection()); - addAction(action, manager); - } - - - /* (non-Javadoc) - * Method declared on ActionGroup. - */ - public void fillContextMenu(IMenuManager manager) { - MenuManager javaSearchMM= new MenuManager(getName(), IContextMenuConstants.GROUP_SEARCH); - addAction(fFindReferencesAction, javaSearchMM); - addAction(fFindReferencesInProjectAction, javaSearchMM); - addAction(fFindReferencesInHierarchyAction, javaSearchMM); - - javaSearchMM.add(new Separator()); - - Iterator iter= SearchUtil.getLRUWorkingSets().sortedIterator(); - while (iter.hasNext()) { - addWorkingSetAction((IWorkingSet[]) iter.next(), javaSearchMM); - } - addAction(fFindReferencesInWorkingSetAction, javaSearchMM); - - if (!javaSearchMM.isEmpty()) - manager.appendToGroup(fGroupId, javaSearchMM); - } - - /* - * Overrides method declared in ActionGroup - */ - public void dispose() { - ISelectionProvider provider= fSite.getSelectionProvider(); - if (provider != null) { - disposeAction(fFindReferencesAction, provider); - disposeAction(fFindReferencesInProjectAction, provider); - disposeAction(fFindReferencesInHierarchyAction, provider); - disposeAction(fFindReferencesInWorkingSetAction, provider); - } - fFindReferencesAction= null; - fFindReferencesInProjectAction= null; - fFindReferencesInHierarchyAction= null; - fFindReferencesInWorkingSetAction= null; - updateGlobalActionHandlers(); - super.dispose(); - } - - private void updateGlobalActionHandlers() { - if (fActionBars != null) { - fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_REFERENCES_IN_WORKSPACE, fFindReferencesAction); - fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_REFERENCES_IN_PROJECT, fFindReferencesInProjectAction); - fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_REFERENCES_IN_HIERARCHY, fFindReferencesInHierarchyAction); - fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_REFERENCES_IN_WORKING_SET, fFindReferencesInWorkingSetAction); - } - } - - private void disposeAction(ISelectionChangedListener action, ISelectionProvider provider) { - if (action != null) - provider.removeSelectionChangedListener(action); - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/RefreshAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/RefreshAction.java deleted file mode 100644 index 0c3a3ffa..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/RefreshAction.java +++ /dev/null @@ -1,221 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.lang.reflect.InvocationTargetException; -import java.net.URI; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.filesystem.EFS; -import org.eclipse.core.filesystem.IFileStore; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.IWorkingSet; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.IJavaScriptModel; -import org.eclipse.wst.jsdt.core.JavaScriptCore; -import org.eclipse.wst.jsdt.internal.corext.util.Messages; -import org.eclipse.wst.jsdt.internal.corext.util.Resources; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaPluginImages; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages; -import org.eclipse.wst.jsdt.internal.ui.actions.WorkbenchRunnableAdapter; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; - -/** - * Action for refreshing the workspace from the local file system for - * the selected resources and all of their descendants. This action - * also considers external Jars managed by the JavaScript Model. - * <p> - * Action is applicable to selections containing resources and Java - * elements down to compilation units. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class RefreshAction extends SelectionDispatchAction { - - /** - * Creates a new <code>RefreshAction</code>. The action requires - * that the selection provided by the site's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public RefreshAction(IWorkbenchSite site) { - super(site); - setText(ActionMessages.RefreshAction_label); - setToolTipText(ActionMessages.RefreshAction_toolTip); - JavaPluginImages.setLocalImageDescriptors(this, "refresh_nav.gif");//$NON-NLS-1$ - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.REFRESH_ACTION); - } - - /* (non-Javadoc) - * Method declared in SelectionDispatchAction - */ - public void selectionChanged(IStructuredSelection selection) { - setEnabled(checkEnabled(selection)); - } - - private boolean checkEnabled(IStructuredSelection selection) { - if (selection.isEmpty()) - return true; - for (Iterator iter= selection.iterator(); iter.hasNext();) { - Object element= iter.next(); - if (element instanceof IWorkingSet) { - // don't inspect working sets any deeper. - } else if (element instanceof IAdaptable) { - IResource resource= (IResource)((IAdaptable)element).getAdapter(IResource.class); - if (resource == null) - return false; - if (resource.getType() == IResource.PROJECT && !((IProject)resource).isOpen()) - return false; - } else { - return false; - } - } - return true; - } - - /* (non-Javadoc) - * Method declared in SelectionDispatchAction - */ - public void run(IStructuredSelection selection) { - final IResource[] resources= getResources(selection); - IWorkspaceRunnable operation= new IWorkspaceRunnable() { - public void run(IProgressMonitor monitor) throws CoreException { - monitor.beginTask(ActionMessages.RefreshAction_progressMessage, resources.length * 2); - monitor.subTask(""); //$NON-NLS-1$ - List javaElements= new ArrayList(5); - for (int r= 0; r < resources.length; r++) { - IResource resource= resources[r]; - if (resource.getType() == IResource.PROJECT) { - checkLocationDeleted((IProject) resource); - } else if (resource.getType() == IResource.ROOT) { - IProject[] projects = ((IWorkspaceRoot)resource).getProjects(); - for (int p = 0; p < projects.length; p++) { - checkLocationDeleted(projects[p]); - } - } - resource.refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(monitor, 1)); - IJavaScriptElement jElement= JavaScriptCore.create(resource); - if (jElement != null && jElement.exists()) - javaElements.add(jElement); - } - IJavaScriptModel model= JavaScriptCore.create(ResourcesPlugin.getWorkspace().getRoot()); - model.refreshExternalArchives( - (IJavaScriptElement[]) javaElements.toArray(new IJavaScriptElement[javaElements.size()]), - new SubProgressMonitor(monitor, resources.length)); - } - }; - - try { - PlatformUI.getWorkbench().getProgressService().run(true, true, new WorkbenchRunnableAdapter(operation)); - } catch (InvocationTargetException e) { - ExceptionHandler.handle(e, getShell(), - ActionMessages.RefreshAction_error_title, - ActionMessages.RefreshAction_error_message); - } catch (InterruptedException e) { - // canceled - } - } - - private IResource[] getResources(IStructuredSelection selection) { - if (selection.isEmpty()) { - return new IResource[] {ResourcesPlugin.getWorkspace().getRoot()}; - } - - List result= new ArrayList(selection.size()); - getResources(result, selection.toArray()); - - for (Iterator iter= result.iterator(); iter.hasNext();) { - IResource resource= (IResource) iter.next(); - if (isDescendent(result, resource)) - iter.remove(); - } - - return (IResource[]) result.toArray(new IResource[result.size()]); - } - - private void getResources(List result, Object[] elements) { - for (int i= 0; i < elements.length; i++) { - Object element= elements[i]; - // Must check working set before IAdaptable since WorkingSet - // implements IAdaptable - if (element instanceof IWorkingSet) { - getResources(result, ((IWorkingSet)element).getElements()); - } else if (element instanceof IAdaptable) { - IResource resource= (IResource)((IAdaptable)element).getAdapter(IResource.class); - if (resource == null) - continue; - if (resource.getType() != IResource.PROJECT || - (resource.getType() == IResource.PROJECT && ((IProject)resource).isOpen())) { - result.add(resource); - } - } - } - } - - private boolean isDescendent(List candidates, IResource element) { - IResource parent= element.getParent(); - while (parent != null) { - if (candidates.contains(parent)) - return true; - parent= parent.getParent(); - } - return false; - } - - private void checkLocationDeleted(IProject project) throws CoreException { - if (!project.exists()) - return; - URI location= project.getLocationURI(); - if (location == null) - return; - IFileStore store= EFS.getStore(location); - if (!store.fetchInfo().exists()) { - final String message = Messages.format( - ActionMessages.RefreshAction_locationDeleted_message, - new Object[] { project.getName(), Resources.getLocationString(project) }); - final boolean[] result= new boolean[1]; - // Must prompt user in UI thread (we're in the operation thread here). - getShell().getDisplay().syncExec(new Runnable() { - public void run() { - result[0]= MessageDialog.openQuestion(getShell(), - ActionMessages.RefreshAction_locationDeleted_title, - message); - } - }); - if (result[0]) { - project.delete(true, true, null); - } - } - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/RemoveFromClasspathAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/RemoveFromClasspathAction.java deleted file mode 100644 index 745786a1..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/RemoveFromClasspathAction.java +++ /dev/null @@ -1,138 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IIncludePathEntry; -import org.eclipse.wst.jsdt.core.IPackageFragmentRoot; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.internal.corext.util.JavaModelUtil; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages; -import org.eclipse.wst.jsdt.internal.ui.actions.WorkbenchRunnableAdapter; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; - -/** - * Action to remove package fragment roots from the classpath of its parent - * project. Currently, the action is applicable to selections containing - * non-external archives (JAR or zip). - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class RemoveFromClasspathAction extends SelectionDispatchAction { - - /** - * Creates a new <code>RemoveFromClasspathAction</code>. The action requires - * that the selection provided by the site's selection provider is of type - * <code> org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public RemoveFromClasspathAction(IWorkbenchSite site) { - super(site); - setText(ActionMessages.RemoveFromClasspathAction_Remove); - setToolTipText(ActionMessages.RemoveFromClasspathAction_tooltip); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.REMOVE_FROM_CLASSPATH_ACTION); - } - - /* (non-Javadoc) - * Method declared in SelectionDispatchAction - */ - public void selectionChanged(IStructuredSelection selection) { - setEnabled(checkEnabled(selection)); - } - - private static boolean checkEnabled(IStructuredSelection selection) { - if (selection.isEmpty()) - return false; - for (Iterator iter= selection.iterator(); iter.hasNext();) { - if (! canRemove(iter.next())) - return false; - } - return true; - } - - /* (non-Javadoc) - * Method declared in SelectionDispatchAction - */ - public void run(final IStructuredSelection selection) { - try { - PlatformUI.getWorkbench().getActiveWorkbenchWindow().run(true, true, new WorkbenchRunnableAdapter(new IWorkspaceRunnable() { - public void run(IProgressMonitor pm) throws CoreException { - try{ - IPackageFragmentRoot[] roots= getRootsToRemove(selection); - pm.beginTask(ActionMessages.RemoveFromClasspathAction_Removing, roots.length); - for (int i= 0; i < roots.length; i++) { - int jCoreFlags= IPackageFragmentRoot.NO_RESOURCE_MODIFICATION | IPackageFragmentRoot.ORIGINATING_PROJECT_INCLUDEPATH; - roots[i].delete(IResource.NONE, jCoreFlags, new SubProgressMonitor(pm, 1)); - } - } finally { - pm.done(); - } - } - })); - } catch (InvocationTargetException e) { - ExceptionHandler.handle(e, getShell(), - ActionMessages.RemoveFromClasspathAction_exception_dialog_title, - ActionMessages.RemoveFromClasspathAction_Problems_occurred); - } catch (InterruptedException e) { - // canceled - } - } - - private static IPackageFragmentRoot[] getRootsToRemove(IStructuredSelection selection){ - List result= new ArrayList(selection.size()); - for (Iterator iter= selection.iterator(); iter.hasNext();) { - Object element= iter.next(); - if (canRemove(element)) - result.add(element); - } - return (IPackageFragmentRoot[]) result.toArray(new IPackageFragmentRoot[result.size()]); - } - - private static boolean canRemove(Object element){ - if (! (element instanceof IPackageFragmentRoot)) - return false; - IPackageFragmentRoot root= (IPackageFragmentRoot)element; - try { - IIncludePathEntry cpe= root.getRawIncludepathEntry(); - if (cpe == null || cpe.getEntryKind() == IIncludePathEntry.CPE_CONTAINER) - return false; // don't want to remove the container if only a child is selected - return true; - } catch (JavaScriptModelException e) { - if (JavaModelUtil.isExceptionToBeLogged(e)) - JavaScriptPlugin.log(e); - } - return false; - } -} - diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/RenameAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/RenameAction.java deleted file mode 100644 index 380c8703..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/RenameAction.java +++ /dev/null @@ -1,116 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.refactoring.RefactoringMessages; -import org.eclipse.wst.jsdt.internal.ui.refactoring.actions.RenameJavaElementAction; -import org.eclipse.wst.jsdt.internal.ui.refactoring.actions.RenameResourceAction; - -/** - * Renames a JavaScript element or workbench resource. - * <p> - * Action is applicable to selections containing elements of type - * <code>IJavaScriptElement</code> or <code>IResource</code>. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class RenameAction extends SelectionDispatchAction { - - private RenameJavaElementAction fRenameJavaElement; - private RenameResourceAction fRenameResource; - - /** - * Creates a new <code>RenameAction</code>. The action requires - * that the selection provided by the site's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public RenameAction(IWorkbenchSite site) { - super(site); - setText(RefactoringMessages.RenameAction_text); - fRenameJavaElement= new RenameJavaElementAction(site); - fRenameJavaElement.setText(getText()); - fRenameResource= new RenameResourceAction(site); - fRenameResource.setText(getText()); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.RENAME_ACTION); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public RenameAction(JavaEditor editor) { - this(editor.getEditorSite()); - fRenameJavaElement= new RenameJavaElementAction(editor); - } - - /* - * @see ISelectionChangedListener#selectionChanged(SelectionChangedEvent) - */ - public void selectionChanged(SelectionChangedEvent event) { - fRenameJavaElement.selectionChanged(event); - if (fRenameResource != null) - fRenameResource.selectionChanged(event); - setEnabled(computeEnabledState()); - } - - /* - * @see SelectionDispatchAction#update(ISelection) - */ - public void update(ISelection selection) { - fRenameJavaElement.update(selection); - - if (fRenameResource != null) - fRenameResource.update(selection); - - setEnabled(computeEnabledState()); - } - - private boolean computeEnabledState(){ - if (fRenameResource != null) { - return fRenameJavaElement.isEnabled() || fRenameResource.isEnabled(); - } else { - return fRenameJavaElement.isEnabled(); - } - } - - public void run(IStructuredSelection selection) { - if (fRenameJavaElement.isEnabled()) - fRenameJavaElement.run(selection); - if (fRenameResource != null && fRenameResource.isEnabled()) - fRenameResource.run(selection); - } - - public void run(ITextSelection selection) { - if (fRenameJavaElement.canRunInEditor()) - fRenameJavaElement.run(selection); - else - MessageDialog.openInformation(getShell(), RefactoringMessages.RenameAction_rename, RefactoringMessages.RenameAction_unavailable); - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ReplaceInvocationsAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ReplaceInvocationsAction.java deleted file mode 100644 index 9af06b6d..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ReplaceInvocationsAction.java +++ /dev/null @@ -1,141 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.IFunction; -import org.eclipse.wst.jsdt.core.ITypeRoot; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.internal.corext.refactoring.RefactoringAvailabilityTester; -import org.eclipse.wst.jsdt.internal.corext.refactoring.RefactoringExecutionStarter; -import org.eclipse.wst.jsdt.internal.corext.util.JavaModelUtil; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaTextSelection; -import org.eclipse.wst.jsdt.internal.ui.refactoring.RefactoringMessages; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; - -/** - * Action that replaces method invocations. This action may be invoked - * on source or binary methods or method invocations with or without attached source. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class ReplaceInvocationsAction extends SelectionDispatchAction { - - private JavaEditor fEditor; - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public ReplaceInvocationsAction(JavaEditor editor) { - this(editor.getEditorSite()); - fEditor= editor; - setEnabled(true); - } - - /** - * Creates a new <code>ReplaceInvocationsAction</code>. - * - * @param site the site providing context information for this action - */ - public ReplaceInvocationsAction(IWorkbenchSite site) { - super(site); - setText(RefactoringMessages.ReplaceInvocationsAction_label); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.REPLACE_INVOCATIONS_ACTION); - } - - //---- structured selection -------------------------------------------------- - - /* - * @see SelectionDispatchAction#selectionChanged(IStructuredSelection) - */ - public void selectionChanged(IStructuredSelection selection) { - try { - setEnabled(RefactoringAvailabilityTester.isReplaceInvocationsAvailable(selection)); - } catch (JavaScriptModelException e) { - if (JavaModelUtil.isExceptionToBeLogged(e)) - JavaScriptPlugin.log(e); - } - } - - /* - * @see SelectionDispatchAction#selectionChanged(ITextSelection) - */ - public void selectionChanged(ITextSelection selection) { - setEnabled(true); - } - - /** - * Note: This method is for internal use only. Clients should not call this method. - */ - public void selectionChanged(JavaTextSelection selection) { - try { - setEnabled(RefactoringAvailabilityTester.isReplaceInvocationsAvailable(selection)); - } catch (JavaScriptModelException e) { - setEnabled(false); - } - } - - /* - * @see SelectionDispatchAction#run(IStructuredSelection) - */ - public void run(IStructuredSelection selection) { - try { - Assert.isTrue(RefactoringAvailabilityTester.isReplaceInvocationsAvailable(selection)); - Object first= selection.getFirstElement(); - Assert.isTrue(first instanceof IFunction); - IFunction method= (IFunction) first; - if (ActionUtil.isProcessable(getShell(), method)) - RefactoringExecutionStarter.startReplaceInvocationsRefactoring(method, getShell()); - } catch (CoreException e) { - handleException(e); - } - } - - private void handleException(CoreException e) { - ExceptionHandler.handle(e, RefactoringMessages.ReplaceInvocationsAction_dialog_title, RefactoringMessages.ReplaceInvocationsAction_unavailable); - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction - */ - public void run(ITextSelection selection) { - try { - IJavaScriptElement editorInput= SelectionConverter.getInput(fEditor); - if ((editorInput instanceof ITypeRoot) - && ActionUtil.isProcessable(getShell(), editorInput)) { - ITypeRoot typeRoot= (ITypeRoot) editorInput; - RefactoringExecutionStarter.startReplaceInvocationsRefactoring(typeRoot, selection.getOffset(), selection.getLength(), getShell()); - } - } catch (JavaScriptModelException e) { - handleException(e); - } - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/SelectionDispatchAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/SelectionDispatchAction.java deleted file mode 100644 index 6a269cf5..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/SelectionDispatchAction.java +++ /dev/null @@ -1,254 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaTextSelection; - -/** - * Action that dispatches the <code>IAction#run()</code> and the - * <code>ISelectionChangedListener#selectionChanged</code> - * according to the type of the selection. - * - * <ul> - * <li>if selection is of type <code>ITextSelection</code> then - * <code>run(ITextSelection)</code> and <code>selectionChanged(ITextSelection)</code> - * is called.</li> - * <li>if selection is of type <code>IStructuredSelection</code> then - * <code>run(IStructuredSelection)</code> and <code> - * selectionChanged(IStructuredSelection)</code> is called.</li> - * <li>default is to call <code>run(ISelection)</code> and <code> - * selectionChanged(ISelection)</code>.</li> - * </ul> - * - * <p> - * Note: This class is not intended to be subclassed outside the JDT UI plug-in. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public abstract class SelectionDispatchAction extends Action implements ISelectionChangedListener { - - private IWorkbenchSite fSite; - private ISelectionProvider fSpecialSelectionProvider; - - /** - * Creates a new action with no text and no image. - * <p> - * Configure the action later using the set methods. - * </p> - * - * @param site the site this action is working on - */ - protected SelectionDispatchAction(IWorkbenchSite site) { - Assert.isNotNull(site); - fSite= site; - } - - /** - * Returns the site owning this action. - * - * @return the site owning this action - */ - public IWorkbenchSite getSite() { - return fSite; - } - - /** - * Returns the selection provided by the site owning this action. - * - * @return the site's selection - */ - public ISelection getSelection() { - ISelectionProvider selectionProvider= getSelectionProvider(); - if (selectionProvider != null) - return selectionProvider.getSelection(); - else - return null; - } - - /** - * Returns the shell provided by the site owning this action. - * - * @return the site's shell - */ - public Shell getShell() { - return fSite.getShell(); - } - - /** - * Returns the selection provider managed by the site owning this action or the selection - * provider explicitly set in {@link #setSpecialSelectionProvider(ISelectionProvider)}. - * - * @return the site's selection provider - */ - public ISelectionProvider getSelectionProvider() { - if (fSpecialSelectionProvider != null) { - return fSpecialSelectionProvider; - } - return fSite.getSelectionProvider(); - } - - /** - * Sets a special selection provider which will be used instead of the site's selection provider. - * This method should be used directly after constructing the action and before the action is - * registered as a selection listener. The invocation will not a perform a selection change notification. - * - * @param provider a special selection provider which is used - * instead of the site's selection provider or <code>null</code> to use the site's - * selection provider. Clients can for example use a {@link ConvertingSelectionProvider} - * to first convert a selection before passing it to the action. - * - * - */ - public void setSpecialSelectionProvider(ISelectionProvider provider) { - fSpecialSelectionProvider= provider; - } - - /** - * Updates the action's enablement state according to the given selection. This - * default implementation calls one of the <code>selectionChanged</code> - * methods depending on the type of the passed selection. - * - * @param selection the selection this action is working on - */ - public void update(ISelection selection) { - dispatchSelectionChanged(selection); - } - - /** - * Notifies this action that the given structured selection has changed. This default - * implementation calls <code>selectionChanged(ISelection selection)</code>. - * - * @param selection the new selection - */ - public void selectionChanged(IStructuredSelection selection) { - selectionChanged((ISelection)selection); - } - - /** - * Executes this actions with the given structured selection. This default implementation - * calls <code>run(ISelection selection)</code>. - * - * @param selection the selection - */ - public void run(IStructuredSelection selection) { - run((ISelection)selection); - } - - /** - * Note: This method is for internal use only. Clients should not call this method. - * - * @param selection the selection - */ - public void selectionChanged(JavaTextSelection selection) { - selectionChanged((ITextSelection)selection); - } - - /** - * Note: This method is for internal use only. Clients should not call this method. - * - * @param selection the selection - */ - public void run(JavaTextSelection selection) { - run((ITextSelection)selection); - } - - /** - * Notifies this action that the given text selection has changed. This default - * implementation calls <code>selectionChanged(ISelection selection)</code>. - * - * @param selection the new selection - */ - public void selectionChanged(ITextSelection selection) { - selectionChanged((ISelection)selection); - } - - /** - * Executes this actions with the given text selection. This default implementation - * calls <code>run(ISelection selection)</code>. - * - * @param selection the selection - */ - public void run(ITextSelection selection) { - run((ISelection)selection); - } - - /** - * Notifies this action that the given selection has changed. This default - * implementation sets the action's enablement state to <code>false</code>. - * - * @param selection the new selection - */ - public void selectionChanged(ISelection selection) { - setEnabled(false); - } - - /** - * Executes this actions with the given selection. This default implementation - * does nothing. - * - * @param selection the selection - */ - public void run(ISelection selection) { - } - - /* (non-Javadoc) - * Method declared on IAction. - */ - public void run() { - dispatchRun(getSelection()); - } - - /* (non-Javadoc) - * Method declared on ISelectionChangedListener. - */ - public void selectionChanged(SelectionChangedEvent event) { - dispatchSelectionChanged(event.getSelection()); - } - - private void dispatchSelectionChanged(ISelection selection) { - if (selection instanceof IStructuredSelection) { - selectionChanged((IStructuredSelection)selection); - } else if (selection instanceof JavaTextSelection) { - selectionChanged((JavaTextSelection)selection); - } else if (selection instanceof ITextSelection) { - selectionChanged((ITextSelection)selection); - } else { - selectionChanged(selection); - } - } - - private void dispatchRun(ISelection selection) { - if (selection instanceof IStructuredSelection) { - run((IStructuredSelection)selection); - } else if (selection instanceof JavaTextSelection) { - run((JavaTextSelection)selection); - } else if (selection instanceof ITextSelection) { - run((ITextSelection)selection); - } else { - run(selection); - } - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/SelfEncapsulateFieldAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/SelfEncapsulateFieldAction.java deleted file mode 100644 index 2c74af6b..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/SelfEncapsulateFieldAction.java +++ /dev/null @@ -1,165 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - - -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IField; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.internal.corext.refactoring.RefactoringAvailabilityTester; -import org.eclipse.wst.jsdt.internal.corext.refactoring.RefactoringExecutionStarter; -import org.eclipse.wst.jsdt.internal.corext.util.JavaModelUtil; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaTextSelection; -import org.eclipse.wst.jsdt.internal.ui.refactoring.RefactoringMessages; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; - -/** - * Action to run the self encapsulate field refactoring. - * <p> - * Action is applicable to selections containing elements of type - * <code>IField</code>. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class SelfEncapsulateFieldAction extends SelectionDispatchAction { - - private JavaEditor fEditor; - - /** - * Creates a new <code>SelfEncapsulateFieldAction</code>. The action requires - * that the selection provided by the site's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public SelfEncapsulateFieldAction(IWorkbenchSite site) { - super(site); - setText(ActionMessages.SelfEncapsulateFieldAction_label); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.SELF_ENCAPSULATE_ACTION); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * - * @param editor the JavaScript editor - */ - public SelfEncapsulateFieldAction(JavaEditor editor) { - this(editor.getEditorSite()); - fEditor= editor; - setEnabled(SelectionConverter.canOperateOn(fEditor)); - } - - //---- text selection ------------------------------------------------------- - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void selectionChanged(ITextSelection selection) { - setEnabled(true); - } - - /** - * Note: This method is for internal use only. Clients should not call this method. - */ - public void selectionChanged(JavaTextSelection selection) { - try { - setEnabled(RefactoringAvailabilityTester.isSelfEncapsulateAvailable(selection)); - } catch (JavaScriptModelException e) { - // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253 - if (JavaModelUtil.isExceptionToBeLogged(e)) - JavaScriptPlugin.log(e); - setEnabled(false);//no UI - } - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void run(ITextSelection selection) { - try { - IJavaScriptElement[] elements= SelectionConverter.codeResolve(fEditor); - if (elements.length != 1 || !(elements[0] instanceof IField)) { - MessageDialog.openInformation(getShell(), ActionMessages.SelfEncapsulateFieldAction_dialog_title, ActionMessages.SelfEncapsulateFieldAction_dialog_unavailable); - return; - } - IField field= (IField)elements[0]; - - if (!RefactoringAvailabilityTester.isSelfEncapsulateAvailable(field)) { - MessageDialog.openInformation(getShell(), ActionMessages.SelfEncapsulateFieldAction_dialog_title, ActionMessages.SelfEncapsulateFieldAction_dialog_unavailable); - return; - } - run(field); - } catch (JavaScriptModelException exception) { - JavaScriptPlugin.log(exception); - return; - } - } - - //---- structured selection ------------------------------------------------- - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void selectionChanged(IStructuredSelection selection) { - try { - setEnabled(RefactoringAvailabilityTester.isSelfEncapsulateAvailable(selection)); - } catch (JavaScriptModelException e) { - // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253 - if (JavaModelUtil.isExceptionToBeLogged(e)) - JavaScriptPlugin.log(e); - setEnabled(false);//no UI - } - } - - /* - * (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void run(IStructuredSelection selection) { - try { - if (RefactoringAvailabilityTester.isSelfEncapsulateAvailable(selection)) - run((IField) selection.getFirstElement()); - } catch (JavaScriptModelException e) { - ExceptionHandler.handle(e, RefactoringMessages.OpenRefactoringWizardAction_refactoring, RefactoringMessages.OpenRefactoringWizardAction_exception); - } - } - - //---- private helpers -------------------------------------------------------- - - /* - * Should be private. But got shipped in this state in 2.0 so changing this is a - * breaking API change. - */ - public void run(IField field) { - if (! ActionUtil.isEditable(fEditor, getShell(), field)) - return; - RefactoringExecutionStarter.startSelfEncapsulateRefactoring(field, getShell()); - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ShowActionGroup.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ShowActionGroup.java deleted file mode 100644 index 8569e62d..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ShowActionGroup.java +++ /dev/null @@ -1,134 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.actions.ActionGroup; -import org.eclipse.ui.part.Page; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.packageview.PackageExplorerPart; -import org.eclipse.wst.jsdt.ui.IContextMenuConstants; - -/** - * Action group that adds the show actions to a context menu and - * the action bar's navigate menu. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class ShowActionGroup extends ActionGroup { - - private boolean fIsPackageExplorer; - - private IWorkbenchSite fSite; - private ShowInPackageViewAction fShowInPackagesViewAction; - - /** - * Creates a new <code>ShowActionGroup</code>. The action requires - * that the selection provided by the page's selection provider is of type - * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param page the page that owns this action group - */ - public ShowActionGroup(Page page) { - this(page.getSite()); - } - - /** - * Creates a new <code>ShowActionGroup</code>. The action requires - * that the selection provided by the part's selection provider is of type - * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param part the view part that owns this action group - */ - public ShowActionGroup(IViewPart part) { - this(part.getSite()); - fIsPackageExplorer= part instanceof PackageExplorerPart; - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param part the JavaScript editor - */ - public ShowActionGroup(JavaEditor part) { - fShowInPackagesViewAction= new ShowInPackageViewAction(part); - fShowInPackagesViewAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SHOW_IN_PACKAGE_VIEW); - part.setAction("ShowInPackageView", fShowInPackagesViewAction); //$NON-NLS-1$ - - initialize(part.getSite(), true); - } - - private ShowActionGroup(IWorkbenchSite site) { - fShowInPackagesViewAction= new ShowInPackageViewAction(site); - fShowInPackagesViewAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SHOW_IN_PACKAGE_VIEW); - - initialize(site , false); - } - - private void initialize(IWorkbenchSite site, boolean isJavaEditor) { - fSite= site; - ISelectionProvider provider= fSite.getSelectionProvider(); - ISelection selection= provider.getSelection(); - fShowInPackagesViewAction.update(selection); - if (!isJavaEditor) { - provider.addSelectionChangedListener(fShowInPackagesViewAction); - } - } - - /* (non-Javadoc) - * Method declared in ActionGroup - */ - public void fillActionBars(IActionBars actionBar) { - super.fillActionBars(actionBar); - setGlobalActionHandlers(actionBar); - } - - /* (non-Javadoc) - * Method declared in ActionGroup - */ - public void fillContextMenu(IMenuManager menu) { - super.fillContextMenu(menu); - if (!fIsPackageExplorer) { - appendToGroup(menu, fShowInPackagesViewAction); - } - } - - /* - * @see ActionGroup#dispose() - */ - public void dispose() { - ISelectionProvider provider= fSite.getSelectionProvider(); - provider.removeSelectionChangedListener(fShowInPackagesViewAction); - super.dispose(); - } - - private void setGlobalActionHandlers(IActionBars actionBar) { - if (!fIsPackageExplorer) - actionBar.setGlobalActionHandler(JdtActionConstants.SHOW_IN_PACKAGE_VIEW, fShowInPackagesViewAction); - } - - private void appendToGroup(IMenuManager menu, IAction action) { - if (action.isEnabled()) - menu.appendToGroup(IContextMenuConstants.GROUP_SHOW, action); - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ShowInNavigatorViewAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ShowInNavigatorViewAction.java deleted file mode 100644 index 5057dc52..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ShowInNavigatorViewAction.java +++ /dev/null @@ -1,171 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.lang.reflect.InvocationTargetException; - -import org.eclipse.core.resources.IResource; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.ui.IPageLayout; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.part.ISetSelectionTarget; -import org.eclipse.wst.jsdt.core.IJavaScriptUnit; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; - -/** - * Reveals the selected element in the resource navigator view. - * <p> - * Action is applicable to structured selections containing JavaScript element - * or resources. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class ShowInNavigatorViewAction extends SelectionDispatchAction { - - private JavaEditor fEditor; - - /** - * Creates a new <code>ShowInNavigatorViewAction</code>. The action requires - * that the selection provided by the site's selection provider is of type - * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public ShowInNavigatorViewAction(IWorkbenchSite site) { - super(site); - setText(ActionMessages.ShowInNavigatorView_label); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.SHOW_IN_NAVIGATOR_VIEW_ACTION); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public ShowInNavigatorViewAction(JavaEditor editor) { - this(editor.getEditorSite()); - fEditor= editor; - setEnabled(SelectionConverter.canOperateOn(fEditor)); - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void selectionChanged(ITextSelection selection) { - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void selectionChanged(IStructuredSelection selection) { - setEnabled(getResource(selection) != null); - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void run(ITextSelection selection) { - IJavaScriptElement input= SelectionConverter.getInput(fEditor); - if (!ActionUtil.isProcessable(getShell(), input)) - return; - - - try { - IJavaScriptElement[] elements= SelectionConverter.codeResolveOrInputForked(fEditor); - if (elements == null || elements.length == 0) - return; - - IJavaScriptElement candidate= elements[0]; - if (elements.length > 1) { - candidate= SelectionConverter.selectJavaElement(elements, getShell(), getDialogTitle(), ActionMessages.ShowInNavigatorView_dialog_message); - } - if (candidate != null) { - run(getResource(candidate)); - } - } catch (InvocationTargetException e) { - ExceptionHandler.handle(e, getDialogTitle(), ActionMessages.SelectionConverter_codeResolve_failed); - } catch (InterruptedException e) { - // cancelled - } - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void run(IStructuredSelection selection) { - run(getResource(selection)); - } - - /* - * No Javadoc. The method should be internal but can't be changed since - * we shipped it with a public visibility - */ - public void run(IResource resource) { - if (resource == null) - return; - try { - IWorkbenchPage page= getSite().getWorkbenchWindow().getActivePage(); - IViewPart view= page.showView(IPageLayout.ID_RES_NAV); - if (view instanceof ISetSelectionTarget) { - ISelection selection= new StructuredSelection(resource); - ((ISetSelectionTarget)view).selectReveal(selection); - } - } catch(PartInitException e) { - ExceptionHandler.handle(e, getShell(), getDialogTitle(), ActionMessages.ShowInNavigatorView_error_activation_failed); - } - } - - private IResource getResource(IStructuredSelection selection) { - if (selection.size() != 1) - return null; - Object element= selection.getFirstElement(); - if (element instanceof IResource) - return (IResource)element; - if (element instanceof IJavaScriptElement) - return getResource((IJavaScriptElement)element); - return null; - } - - private IResource getResource(IJavaScriptElement element) { - if (element == null) - return null; - - element= (IJavaScriptElement) element.getOpenable(); - if (element instanceof IJavaScriptUnit) { - element= ((IJavaScriptUnit) element).getPrimary(); - } - return element.getResource(); - } - - private static String getDialogTitle() { - return ActionMessages.ShowInNavigatorView_dialog_title; - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ShowInPackageViewAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ShowInPackageViewAction.java deleted file mode 100644 index 9b49bdaa..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/ShowInPackageViewAction.java +++ /dev/null @@ -1,135 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.IOpenable; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.packageview.PackageExplorerPart; -/** - * This action reveals the currently selected JavaScript element in the - * package explorer. - * <p> - * The action is applicable to selections containing elements of type - * <code>IJavaScriptElement</code>. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class ShowInPackageViewAction extends SelectionDispatchAction { - - private JavaEditor fEditor; - - /** - * Creates a new <code>ShowInPackageViewAction</code>. The action requires - * that the selection provided by the site's selection provider is of type - * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public ShowInPackageViewAction(IWorkbenchSite site) { - super(site); - setText(ActionMessages.ShowInPackageViewAction_label); - setDescription(ActionMessages.ShowInPackageViewAction_description); - setToolTipText(ActionMessages.ShowInPackageViewAction_tooltip); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.SHOW_IN_PACKAGEVIEW_ACTION); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public ShowInPackageViewAction(JavaEditor editor) { - this(editor.getEditorSite()); - fEditor= editor; - setEnabled(SelectionConverter.canOperateOn(fEditor)); - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void selectionChanged(ITextSelection selection) { - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void selectionChanged(IStructuredSelection selection) { - setEnabled(checkEnabled(selection)); - } - - private boolean checkEnabled(IStructuredSelection selection) { - if (selection.size() != 1) - return false; - return selection.getFirstElement() instanceof IJavaScriptElement; - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void run(ITextSelection selection) { - try { - IJavaScriptElement element= SelectionConverter.getElementAtOffset(fEditor); - if (element != null) - run(element); - } catch (JavaScriptModelException e) { - JavaScriptPlugin.log(e); - String message= ActionMessages.ShowInPackageViewAction_error_message; - ErrorDialog.openError(getShell(), getDialogTitle(), message, e.getStatus()); - } - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction. - */ - public void run(IStructuredSelection selection) { - if (!checkEnabled(selection)) - return; - run((IJavaScriptElement)selection.getFirstElement()); - } - - /* - * No Javadoc. The method should be internal but can't be changed since - * we shipped it with a public visibility - */ - public void run(IJavaScriptElement element) { - if (element == null) - return; - - // reveal the top most element only - IOpenable openable= element.getOpenable(); - if (openable instanceof IJavaScriptElement) - element= (IJavaScriptElement)openable; - - PackageExplorerPart view= PackageExplorerPart.openInActivePerspective(); - view.tryToReveal(element); - } - - private static String getDialogTitle() { - return ActionMessages.ShowInPackageViewAction_dialog_title; - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/SortMembersAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/SortMembersAction.java deleted file mode 100644 index 782ec79e..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/SortMembersAction.java +++ /dev/null @@ -1,257 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.lang.reflect.InvocationTargetException; -import java.util.Iterator; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.text.source.IAnnotationModel; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IJavaScriptUnit; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.core.IParent; -import org.eclipse.wst.jsdt.core.IType; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.internal.corext.codemanipulation.SortMembersOperation; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.actions.WorkbenchRunnableAdapter; -import org.eclipse.wst.jsdt.internal.ui.dialogs.OptionalMessageDialog; -import org.eclipse.wst.jsdt.internal.ui.dialogs.SortMembersMessageDialog; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.CompilationUnitEditor; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.IJavaAnnotation; -import org.eclipse.wst.jsdt.internal.ui.util.BusyIndicatorRunnableContext; -import org.eclipse.wst.jsdt.internal.ui.util.ElementValidator; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; -import org.eclipse.wst.jsdt.ui.JavaScriptUI; - -/** - * Sorts the members of a compilation unit with the sort order as specified in - * the Sort Order preference page. - * <p> - * The action will open the parent compilation unit in a JavaScript editor. The result - * is unsaved, so the user can decide if the changes are acceptable. - * <p> - * The action is applicable to structured selections containing a single - * <code>IJavaScriptUnit</code> or top level <code>IType</code> in a - * compilation unit. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class SortMembersAction extends SelectionDispatchAction { - - private CompilationUnitEditor fEditor; - private final static String ID_OPTIONAL_DIALOG= "org.eclipse.wst.jsdt.ui.actions.SortMembersAction"; //$NON-NLS-1$ - - /** - * Creates a new <code>SortMembersAction</code>. The action requires - * that the selection provided by the site's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public SortMembersAction(IWorkbenchSite site) { - super(site); - setText(ActionMessages.SortMembersAction_label); - setDescription(ActionMessages.SortMembersAction_description); - setToolTipText(ActionMessages.SortMembersAction_tooltip); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.SORT_MEMBERS_ACTION); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the compilation unit editor - */ - public SortMembersAction(CompilationUnitEditor editor) { - this(editor.getEditorSite()); - fEditor= editor; - setEnabled(checkEnabledEditor()); - } - - private boolean checkEnabledEditor() { - return fEditor != null && SelectionConverter.canOperateOn(fEditor); - } - - //---- Structured Viewer ----------------------------------------------------------- - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction - */ - public void selectionChanged(IStructuredSelection selection) { - boolean enabled= false; - enabled= getSelectedCompilationUnit(selection) != null; - setEnabled(enabled); - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction - */ - public void run(IStructuredSelection selection) { - Shell shell= getShell(); - try { - IJavaScriptUnit cu= getSelectedCompilationUnit(selection); - if (cu == null) { - return; - } - IJavaScriptElement[] types= cu.getChildren(); - if (!hasMembersToSort(types)) { - return; - } - if (!ActionUtil.isEditable(getShell(), cu)) { - return; - } - - SortMembersMessageDialog dialog= new SortMembersMessageDialog(getShell()); - if (dialog.open() != Window.OK) { - return; - } - - if (!ElementValidator.check(cu, getShell(), getDialogTitle(), false)) { - return; - } - - // open an editor and work on a working copy - IEditorPart editor= JavaScriptUI.openInEditor(cu); - if (editor != null) { - run(shell, cu, editor, dialog.isNotSortingFieldsEnabled()); - } - } catch (CoreException e) { - ExceptionHandler.handle(e, shell, getDialogTitle(), null); - } - } - - private boolean hasMembersToSort(IJavaScriptElement[] members) throws JavaScriptModelException { - if (members.length > 1) { - return true; - } - if (members.length == 1) { - IJavaScriptElement elem= members[0]; - if (elem instanceof IParent) { - return hasMembersToSort(((IParent) elem).getChildren()); - } - } - return false; - } - - //---- JavaScript Editor -------------------------------------------------------------- - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction - */ - public void selectionChanged(ITextSelection selection) { - } - - /* (non-Javadoc) - * Method declared on SelectionDispatchAction - */ - public void run(ITextSelection selection) { - Shell shell= getShell(); - IJavaScriptElement input= SelectionConverter.getInput(fEditor); - if (input instanceof IJavaScriptUnit) { - if (!ActionUtil.isEditable(fEditor)) { - return; - } - SortMembersMessageDialog dialog= new SortMembersMessageDialog(getShell()); - if (dialog.open() != Window.OK) { - return; - } - if (!ElementValidator.check(input, getShell(), getDialogTitle(), true)) { - return; - } - run(shell, (IJavaScriptUnit) input, fEditor, dialog.isNotSortingFieldsEnabled()); - } else { - MessageDialog.openInformation(shell, getDialogTitle(), ActionMessages.SortMembersAction_not_applicable); - } - } - - //---- Helpers ------------------------------------------------------------------- - - private boolean containsRelevantMarkers(IEditorPart editor) { - IAnnotationModel model= JavaScriptUI.getDocumentProvider().getAnnotationModel(editor.getEditorInput()); - Iterator iterator= model.getAnnotationIterator(); - while (iterator.hasNext()) { - Object element= iterator.next(); - if (element instanceof IJavaAnnotation) { - IJavaAnnotation annot= (IJavaAnnotation) element; - if (!annot.isMarkedDeleted() && annot.isPersistent() && !annot.isProblem()) - return true; - } - } - return false; - } - - private void run(Shell shell, IJavaScriptUnit cu, IEditorPart editor, boolean isNotSortFields) { - if (containsRelevantMarkers(editor)) { - int returnCode= OptionalMessageDialog.open(ID_OPTIONAL_DIALOG, - getShell(), - getDialogTitle(), - null, - ActionMessages.SortMembersAction_containsmarkers, - MessageDialog.WARNING, - new String[] {IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL}, - 0); - if (returnCode != OptionalMessageDialog.NOT_SHOWN && - returnCode != Window.OK ) return; - } - - SortMembersOperation op= new SortMembersOperation(cu, null, isNotSortFields); - try { - BusyIndicatorRunnableContext context= new BusyIndicatorRunnableContext(); - PlatformUI.getWorkbench().getProgressService().runInUI(context, - new WorkbenchRunnableAdapter(op, op.getScheduleRule()), - op.getScheduleRule()); - } catch (InvocationTargetException e) { - ExceptionHandler.handle(e, shell, getDialogTitle(), null); - } catch (InterruptedException e) { - // Do nothing. Operation has been canceled by user. - } - } - - - private IJavaScriptUnit getSelectedCompilationUnit(IStructuredSelection selection) { - if (selection.size() == 1) { - Object element= selection.getFirstElement(); - if (element instanceof IJavaScriptUnit) { - return (IJavaScriptUnit) element; - } else if (element instanceof IType) { - IType type= (IType) element; - if (type.getParent() instanceof IJavaScriptUnit) { // only top level types - return type.getJavaScriptUnit(); - } - } - } - return null; - } - - private String getDialogTitle() { - return ActionMessages.SortMembersAction_dialog_title; - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/SurroundWithTryCatchAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/SurroundWithTryCatchAction.java deleted file mode 100644 index 39293ec7..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/SurroundWithTryCatchAction.java +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Sebastian Davids - Fixed bug 25898 - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.lang.reflect.InvocationTargetException; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.PerformChangeOperation; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; -import org.eclipse.ltk.core.refactoring.RefactoringStatusEntry; -import org.eclipse.ltk.ui.refactoring.RefactoringUI; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IJavaScriptUnit; -import org.eclipse.wst.jsdt.core.ISourceRange; -import org.eclipse.wst.jsdt.internal.corext.refactoring.base.JavaStatusContext; -import org.eclipse.wst.jsdt.internal.corext.refactoring.surround.ISurroundWithTryCatchQuery; -import org.eclipse.wst.jsdt.internal.corext.refactoring.surround.SurroundWithTryCatchRefactoring; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.actions.WorkbenchRunnableAdapter; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.CompilationUnitEditor; -import org.eclipse.wst.jsdt.internal.ui.refactoring.RefactoringMessages; -import org.eclipse.wst.jsdt.internal.ui.util.BusyIndicatorRunnableContext; -import org.eclipse.wst.jsdt.internal.ui.util.ElementValidator; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; - -/** - * Action to surround a set of statements with a try/catch block. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class SurroundWithTryCatchAction extends SelectionDispatchAction { - - private CompilationUnitEditor fEditor; - - private static class Query implements ISurroundWithTryCatchQuery { - private Shell fParent; - public Query(Shell shell) { - fParent= shell; - } - public boolean catchRuntimeException() { - MessageDialog dialog = new MessageDialog( - fParent, getDialogTitle(), null, // accept the default window icon - RefactoringMessages.SurroundWithTryCatchAction_no_exceptions, - MessageDialog.QUESTION, - new String[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL}, - 1) { - // Work around for http://dev.eclipse.org/bugs/show_bug.cgi?id=18303 - protected void createButtonsForButtonBar(Composite parent) { - super.createButtonsForButtonBar(parent); - Button button= getButton(1); - if (button != null) - button.setFocus(); - } - }; - return dialog.open() == 0; // yes selected - } - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the compilation unit editor - */ - public SurroundWithTryCatchAction(CompilationUnitEditor editor) { - super(editor.getEditorSite()); - setText(RefactoringMessages.SurroundWithTryCatchAction_label); - fEditor= editor; - setEnabled((fEditor != null && SelectionConverter.getInputAsCompilationUnit(fEditor) != null)); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.SURROUND_WITH_TRY_CATCH_ACTION); - } - - public void run(ITextSelection selection) { - if (!ActionUtil.isEditable(fEditor)) - return; - IJavaScriptUnit cu= SelectionConverter.getInputAsCompilationUnit(fEditor); - if (cu == null || !ElementValidator.checkValidateEdit(cu, getShell(), getDialogTitle())) - return; - SurroundWithTryCatchRefactoring refactoring= SurroundWithTryCatchRefactoring.create(cu, selection, new Query(getShell())); - - if (refactoring == null) - return; - try { - RefactoringStatus status= refactoring.checkInitialConditions(new NullProgressMonitor()); - if (status.hasFatalError()) { - RefactoringStatusEntry entry= status.getEntryMatchingSeverity(RefactoringStatus.FATAL); - MessageDialog.openInformation(getShell(), getDialogTitle(), entry.getMessage()); - if (entry.getContext() instanceof JavaStatusContext && fEditor != null) { - JavaStatusContext context= (JavaStatusContext)entry.getContext(); - ISourceRange range= context.getSourceRange(); - fEditor.setHighlightRange(range.getOffset(), range.getLength(), true); - } - return; - } - if (refactoring.stopExecution()) - return; - Change change= refactoring.createChange(new NullProgressMonitor()); - change.initializeValidationData(new NullProgressMonitor()); - PerformChangeOperation op= RefactoringUI.createUIAwareChangeOperation(change); - // must be fork == false since file buffers can't be manipulated in a different thread. - WorkbenchRunnableAdapter adapter= new WorkbenchRunnableAdapter(op); - PlatformUI.getWorkbench().getProgressService().runInUI( - new BusyIndicatorRunnableContext(), adapter, adapter.getSchedulingRule()); - } catch (CoreException e) { - ExceptionHandler.handle(e, getDialogTitle(), RefactoringMessages.SurroundWithTryCatchAction_exception); - } catch (InvocationTargetException e) { - ExceptionHandler.handle(e, getDialogTitle(), RefactoringMessages.SurroundWithTryCatchAction_exception); - } catch (InterruptedException e) { - // not cancelable - } - } - - public void selectionChanged(ITextSelection selection) { - setEnabled(selection.getLength() > 0 && (fEditor != null && SelectionConverter.getInputAsCompilationUnit(fEditor) != null)); - } - - private static String getDialogTitle() { - return RefactoringMessages.SurroundWithTryCatchAction_dialog_title; - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/UseSupertypeAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/UseSupertypeAction.java deleted file mode 100644 index e45bd938..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/UseSupertypeAction.java +++ /dev/null @@ -1,157 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.io.CharConversionException; - -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IJavaScriptUnit; -import org.eclipse.wst.jsdt.core.IType; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.internal.corext.refactoring.RefactoringAvailabilityTester; -import org.eclipse.wst.jsdt.internal.corext.refactoring.RefactoringExecutionStarter; -import org.eclipse.wst.jsdt.internal.corext.refactoring.util.JavaElementUtil; -import org.eclipse.wst.jsdt.internal.corext.util.JavaModelUtil; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin; -import org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil; -import org.eclipse.wst.jsdt.internal.ui.actions.SelectionConverter; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaTextSelection; -import org.eclipse.wst.jsdt.internal.ui.refactoring.RefactoringMessages; -import org.eclipse.wst.jsdt.internal.ui.refactoring.actions.RefactoringActions; -import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler; - -/** - * Tries to use a super type of a class where possible. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class UseSupertypeAction extends SelectionDispatchAction{ - - private JavaEditor fEditor; - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public UseSupertypeAction(JavaEditor editor) { - this(editor.getEditorSite()); - fEditor= editor; - setEnabled(SelectionConverter.canOperateOn(fEditor)); - } - - /** - * Creates a new <code>UseSupertypeAction</code>. The action requires - * that the selection provided by the site's selection provider is of type <code> - * org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the site providing context information for this action - */ - public UseSupertypeAction(IWorkbenchSite site) { - super(site); - setText(RefactoringMessages.UseSupertypeAction_use_Supertype); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.USE_SUPERTYPE_ACTION); - } - - //---- structured selection --------------------------------------------------- - - /* - * @see SelectionDispatchAction#selectionChanged(IStructuredSelection) - */ - public void selectionChanged(IStructuredSelection selection) { - try { - setEnabled(RefactoringAvailabilityTester.isUseSuperTypeAvailable(selection)); - } catch (JavaScriptModelException e) { - // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253 - if (!(e.getException() instanceof CharConversionException) && JavaModelUtil.isExceptionToBeLogged(e)) - JavaScriptPlugin.log(e); - setEnabled(false);// no UI - happens on selection changes - } - } - - /* - * @see SelectionDispatchAction#run(IStructuredSelection) - */ - public void run(IStructuredSelection selection) { - try { - if (RefactoringAvailabilityTester.isUseSuperTypeAvailable(selection)) { - IType singleSelectedType= getSingleSelectedType(selection); - if (! ActionUtil.isEditable(getShell(), singleSelectedType)) - return; - RefactoringExecutionStarter.startUseSupertypeRefactoring(singleSelectedType, getShell()); - } - } catch (JavaScriptModelException e) { - ExceptionHandler.handle(e, RefactoringMessages.OpenRefactoringWizardAction_refactoring, RefactoringMessages.OpenRefactoringWizardAction_exception); - } - } - - private static IType getSingleSelectedType(IStructuredSelection selection) throws JavaScriptModelException{ - if (selection.isEmpty() || selection.size() != 1) - return null; - - Object first= selection.getFirstElement(); - if (first instanceof IType) - return (IType)first; - if (first instanceof IJavaScriptUnit) - return JavaElementUtil.getMainType((IJavaScriptUnit)first); - return null; - } - - //---- text selection ------------------------------------------------------ - - /* - * @see SelectionDispatchAction#selectionChanged(ITextSelection) - */ - public void selectionChanged(ITextSelection selection) { - setEnabled(true); - } - - /** - * Note: This method is for internal use only. Clients should not call this method. - */ - public void selectionChanged(JavaTextSelection selection) { - try { - setEnabled(RefactoringAvailabilityTester.isUseSuperTypeAvailable(selection)); - } catch (JavaScriptModelException e) { - setEnabled(false); - } - } - - /* - * @see SelectionDispatchAction#run(ITextSelection) - */ - public void run(ITextSelection selection) { - try { - IType type= RefactoringActions.getEnclosingOrPrimaryType(fEditor); - if (RefactoringAvailabilityTester.isUseSuperTypeAvailable(type)) { - if (! ActionUtil.isEditable(fEditor, getShell(), type)) - return; - RefactoringExecutionStarter.startUseSupertypeRefactoring(type, getShell()); - } else { - MessageDialog.openInformation(getShell(), RefactoringMessages.OpenRefactoringWizardAction_unavailable, RefactoringMessages.UseSupertypeAction_to_activate); - } - } catch (JavaScriptModelException e) { - ExceptionHandler.handle(e, RefactoringMessages.OpenRefactoringWizardAction_refactoring, RefactoringMessages.OpenRefactoringWizardAction_exception); - } - } -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/WorkingSetFindAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/WorkingSetFindAction.java deleted file mode 100644 index d97fe573..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/WorkingSetFindAction.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.jsdt.core.IJavaScriptElement; -import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; - -/** - * Wraps a <code>JavaElementSearchActions</code> to find its results - * in the specified working set. - * <p> - * The action is applicable to selections and Search view entries - * representing a JavaScript element. - * - * <p> - * Note: This class is for internal use only. Clients should not use this class. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class WorkingSetFindAction extends FindAction { - - private FindAction fAction; - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - */ - public WorkingSetFindAction(IWorkbenchSite site, FindAction action, String workingSetName) { - super(site); - init(action, workingSetName); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - */ - public WorkingSetFindAction(JavaEditor editor, FindAction action, String workingSetName) { - super(editor); - init(action, workingSetName); - } - - Class[] getValidTypes() { - return null; // ignore, we override canOperateOn - } - - void init() { - // ignore: do our own init in 'init(FindAction, String)' - } - - private void init(FindAction action, String workingSetName) { - Assert.isNotNull(action); - fAction= action; - setText(workingSetName); - setImageDescriptor(action.getImageDescriptor()); - setToolTipText(action.getToolTipText()); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.WORKING_SET_FIND_ACTION); - } - - public void run(IJavaScriptElement element) { - fAction.run(element); - } - - boolean canOperateOn(IJavaScriptElement element) { - return fAction.canOperateOn(element); - } - - int getLimitTo() { - return -1; - } - - String getOperationUnavailableMessage() { - return fAction.getOperationUnavailableMessage(); - } - -} diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/WriteReferencesSearchGroup.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/WriteReferencesSearchGroup.java deleted file mode 100644 index 2286177f..00000000 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/ui/actions/WriteReferencesSearchGroup.java +++ /dev/null @@ -1,205 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.ui.actions; - -import java.util.Iterator; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.IWorkingSet; -import org.eclipse.ui.actions.ActionGroup; -import org.eclipse.ui.texteditor.ITextEditorActionConstants; -import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor; -import org.eclipse.wst.jsdt.internal.ui.search.SearchMessages; -import org.eclipse.wst.jsdt.internal.ui.search.SearchUtil; -import org.eclipse.wst.jsdt.ui.IContextMenuConstants; - -/** - * Action group that adds the search for write references actions to a - * context menu and the global menu bar. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class WriteReferencesSearchGroup extends ActionGroup { - - private static final String MENU_TEXT= SearchMessages.group_writeReferences; - - private IWorkbenchSite fSite; - private JavaEditor fEditor; - private IActionBars fActionBars; - - private String fGroupId; - - private FindWriteReferencesAction fFindWriteReferencesAction; - private FindWriteReferencesInProjectAction fFindWriteReferencesInProjectAction; - private FindWriteReferencesInHierarchyAction fFindWriteReferencesInHierarchyAction; - private FindWriteReferencesInWorkingSetAction fFindWriteReferencesInWorkingSetAction; - - /** - * Creates a new <code>WriteReferencesSearchGroup</code>. The action - * requires that the selection provided by the site's selection provider is of - * type <code>org.eclipse.jface.viewers.IStructuredSelection</code>. - * - * @param site the view part that owns this action group - */ - public WriteReferencesSearchGroup(IWorkbenchSite site) { - fSite= site; - fGroupId= IContextMenuConstants.GROUP_SEARCH; - - fFindWriteReferencesAction= new FindWriteReferencesAction(site); - fFindWriteReferencesAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_WORKSPACE); - - fFindWriteReferencesInProjectAction= new FindWriteReferencesInProjectAction(site); - fFindWriteReferencesInProjectAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_PROJECT); - - fFindWriteReferencesInHierarchyAction= new FindWriteReferencesInHierarchyAction(site); - fFindWriteReferencesInHierarchyAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_HIERARCHY); - - fFindWriteReferencesInWorkingSetAction= new FindWriteReferencesInWorkingSetAction(site); - fFindWriteReferencesInWorkingSetAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_WORKING_SET); - - // register the actions as selection listeners - ISelectionProvider provider= fSite.getSelectionProvider(); - ISelection selection= provider.getSelection(); - registerAction(fFindWriteReferencesAction, provider, selection); - registerAction(fFindWriteReferencesInProjectAction, provider, selection); - registerAction(fFindWriteReferencesInHierarchyAction, provider, selection); - registerAction(fFindWriteReferencesInWorkingSetAction, provider, selection); - } - - /** - * Note: This constructor is for internal use only. Clients should not call this constructor. - * @param editor the JavaScript editor - */ - public WriteReferencesSearchGroup(JavaEditor editor) { - fEditor= editor; - fSite= fEditor.getSite(); - fGroupId= ITextEditorActionConstants.GROUP_FIND; - - fFindWriteReferencesAction= new FindWriteReferencesAction(fEditor); - fFindWriteReferencesAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_WORKSPACE); - fEditor.setAction("SearchWriteAccessInWorkspace", fFindWriteReferencesAction); //$NON-NLS-1$ - - fFindWriteReferencesInProjectAction= new FindWriteReferencesInProjectAction(fEditor); - fFindWriteReferencesInProjectAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_PROJECT); - fEditor.setAction("SearchWriteAccessInProject", fFindWriteReferencesInProjectAction); //$NON-NLS-1$ - - fFindWriteReferencesInHierarchyAction= new FindWriteReferencesInHierarchyAction(fEditor); - fFindWriteReferencesInHierarchyAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_HIERARCHY); - fEditor.setAction("SearchWriteAccessInHierarchy", fFindWriteReferencesInHierarchyAction); //$NON-NLS-1$ - - fFindWriteReferencesInWorkingSetAction= new FindWriteReferencesInWorkingSetAction(fEditor); - fFindWriteReferencesInWorkingSetAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_WORKING_SET); - fEditor.setAction("SearchWriteAccessInWorkingSet", fFindWriteReferencesInWorkingSetAction); //$NON-NLS-1$ - } - - private void registerAction(SelectionDispatchAction action, ISelectionProvider provider, ISelection selection) { - action.update(selection); - provider.addSelectionChangedListener(action); - } - - private void addAction(IAction action, IMenuManager manager) { - if (action.isEnabled()) { - manager.add(action); - } - } - - private void addWorkingSetAction(IWorkingSet[] workingSets, IMenuManager manager) { - FindAction action; - if (fEditor != null) - action= new WorkingSetFindAction(fEditor, new FindWriteReferencesInWorkingSetAction(fEditor, workingSets), SearchUtil.toString(workingSets)); - else - action= new WorkingSetFindAction(fSite, new FindWriteReferencesInWorkingSetAction(fSite, workingSets), SearchUtil.toString(workingSets)); - action.update(getContext().getSelection()); - addAction(action, manager); - } - - - /* (non-Javadoc) - * Method declared on ActionGroup. - */ - public void fillContextMenu(IMenuManager manager) { - MenuManager javaSearchMM= new MenuManager(MENU_TEXT, IContextMenuConstants.GROUP_SEARCH); - addAction(fFindWriteReferencesAction, javaSearchMM); - addAction(fFindWriteReferencesInProjectAction, javaSearchMM); - addAction(fFindWriteReferencesInHierarchyAction, javaSearchMM); - - javaSearchMM.add(new Separator()); - - Iterator iter= SearchUtil.getLRUWorkingSets().sortedIterator(); - while (iter.hasNext()) { - addWorkingSetAction((IWorkingSet[]) iter.next(), javaSearchMM); - } - addAction(fFindWriteReferencesInWorkingSetAction, javaSearchMM); - - if (!javaSearchMM.isEmpty()) - manager.appendToGroup(fGroupId, javaSearchMM); - } - - /* - * Method declared on ActionGroup. - */ - public void fillActionBars(IActionBars actionBars) { - Assert.isNotNull(actionBars); - super.fillActionBars(actionBars); - fActionBars= actionBars; - updateGlobalActionHandlers(); - } - - /* - * Method declared on ActionGroup. - */ - public void dispose() { - ISelectionProvider provider= fSite.getSelectionProvider(); - if (provider != null) { - disposeAction(fFindWriteReferencesAction, provider); - disposeAction(fFindWriteReferencesInProjectAction, provider); - disposeAction(fFindWriteReferencesInHierarchyAction, provider); - disposeAction(fFindWriteReferencesInWorkingSetAction, provider); - } - fFindWriteReferencesAction= null; - fFindWriteReferencesInProjectAction= null; - fFindWriteReferencesInHierarchyAction= null; - fFindWriteReferencesInWorkingSetAction= null; - updateGlobalActionHandlers(); - super.dispose(); - } - - private void updateGlobalActionHandlers() { - if (fActionBars != null) { - fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_WRITE_ACCESS_IN_WORKSPACE, fFindWriteReferencesAction); - fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_WRITE_ACCESS_IN_PROJECT, fFindWriteReferencesInProjectAction); - fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_WRITE_ACCESS_IN_HIERARCHY, fFindWriteReferencesInHierarchyAction); - fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_WRITE_ACCESS_IN_WORKING_SET, fFindWriteReferencesInWorkingSetAction); - } - } - - private void disposeAction(ISelectionChangedListener action, ISelectionProvider provider) { - if (action != null) - provider.removeSelectionChangedListener(action); - } -} |