Search in sources :

Example 1 with RefactoringWizard

use of org.eclipse.ltk.ui.refactoring.RefactoringWizard in project webtools.sourceediting by eclipse.

the class RenameHandler method run.

public void run(ISelection selection, XSDSchema schema, XSDNamedComponent selectedComponent) {
    if (selectedComponent.getName() == null) {
        selectedComponent.setName(new String());
    }
    if (selectedComponent.getSchema() == null) {
        if (schema != null) {
            schema.updateElement(true);
        }
    }
    boolean rc = SaveDirtyFilesDialog.saveDirtyFiles();
    if (!rc) {
        return;
    }
    RefactoringComponent component = new XMLRefactoringComponent(selectedComponent, (IDOMElement) selectedComponent.getElement(), selectedComponent.getName(), selectedComponent.getTargetNamespace());
    RenameComponentProcessor processor = new RenameComponentProcessor(component, selectedComponent.getName());
    RenameRefactoring refactoring = new RenameRefactoring(processor);
    try {
        RefactoringWizard wizard = new RenameRefactoringWizard(refactoring, RefactoringWizardMessages.RenameComponentWizard_defaultPageTitle, RefactoringWizardMessages.RenameComponentWizard_inputPage_description, null);
        RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
        op.run(XSDEditorPlugin.getShell(), wizard.getDefaultPageTitle());
    } catch (InterruptedException e) {
    // do nothing. User action got canceled
    }
}
Also used : RefactoringWizardOpenOperation(org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation) RenameComponentProcessor(org.eclipse.wst.xsd.ui.internal.refactor.rename.RenameComponentProcessor) RenameRefactoringWizard(org.eclipse.wst.xsd.ui.internal.refactor.wizard.RenameRefactoringWizard) RenameRefactoringWizard(org.eclipse.wst.xsd.ui.internal.refactor.wizard.RenameRefactoringWizard) RefactoringWizard(org.eclipse.ltk.ui.refactoring.RefactoringWizard) XMLRefactoringComponent(org.eclipse.wst.xsd.ui.internal.refactor.XMLRefactoringComponent) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) XMLRefactoringComponent(org.eclipse.wst.xsd.ui.internal.refactor.XMLRefactoringComponent) RefactoringComponent(org.eclipse.wst.xsd.ui.internal.refactor.RefactoringComponent)

Example 2 with RefactoringWizard

use of org.eclipse.ltk.ui.refactoring.RefactoringWizard in project webtools.sourceediting by eclipse.

the class RenameResourceAction method run.

public void run(IStructuredSelection selection) {
    IResource resource = getResource(selection);
    RenameResourceProcessor processor = new RenameResourceProcessor(resource);
    if (!processor.isApplicable())
        return;
    RenameRefactoring refactoring = new RenameRefactoring(processor);
    try {
        RefactoringWizard wizard = new RenameRefactoringWizard(refactoring, // TODO: provide correct strings
        RefactoringWizardMessages.RenameComponentWizard_defaultPageTitle, RefactoringWizardMessages.RenameComponentWizard_inputPage_description, null);
        RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
        op.run(XSDEditorPlugin.getShell(), wizard.getDefaultPageTitle());
    } catch (InterruptedException e) {
    // do nothing. User action got cancelled
    }
}
Also used : RenameResourceProcessor(org.eclipse.wst.xsd.ui.internal.refactor.rename.RenameResourceProcessor) RefactoringWizardOpenOperation(org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation) RenameRefactoringWizard(org.eclipse.wst.xsd.ui.internal.refactor.wizard.RenameRefactoringWizard) RenameRefactoringWizard(org.eclipse.wst.xsd.ui.internal.refactor.wizard.RenameRefactoringWizard) RefactoringWizard(org.eclipse.ltk.ui.refactoring.RefactoringWizard) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) IResource(org.eclipse.core.resources.IResource)

Example 3 with RefactoringWizard

use of org.eclipse.ltk.ui.refactoring.RefactoringWizard in project jbosstools-hibernate by jbosstools.

the class SaveQueryEditorListener method propertyChanged.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IPropertyListener#propertyChanged(java.lang.Object, int)
	 */
public void propertyChanged(Object source, int propId) {
    if (IEditorPart.PROP_DIRTY == propId && !editor.isDirty()) {
        IDocumentProvider docProvider = fromEditorPart.getDocumentProvider();
        final IFile file = ((IFileEditorInput) fromEditorPart.getEditorInput()).getFile();
        final IDocument doc = docProvider.getDocument(fromEditorPart.getEditorInput());
        boolean isDocChanged = true;
        try {
            if (query.equals(doc.get(position.x, position.y))) {
                isDocChanged = false;
            }
        } catch (BadLocationException e1) {
        // document changed and we can get the exception
        }
        final String editorTitle = fromEditorPart.getTitle();
        final String editor_name = editor instanceof HQLEditor ? JdtUiMessages.SaveQueryEditorListener_hql_editor : JdtUiMessages.SaveQueryEditorListener_cri_editor;
        if (isDocChanged) {
            String information_message = NLS.bind(JdtUiMessages.SaveQueryEditorListener_replacequestion_confirm, editorTitle);
            MessageDialog.openInformation(null, JdtUiMessages.SaveQueryEditorListener_replacetitle_info, information_message);
            return;
        }
        final String newQuery = editor.getEditorText();
        final String wizard_title = NLS.bind(JdtUiMessages.SaveQueryEditorListener_refactoringtitle, editor_name);
        Refactoring ref = new Refactoring() {

            @Override
            public RefactoringStatus checkFinalConditions(IProgressMonitor pm) {
                return RefactoringStatus.create(Status.OK_STATUS);
            }

            @Override
            public RefactoringStatus checkInitialConditions(IProgressMonitor pm) {
                return RefactoringStatus.create(Status.OK_STATUS);
            }

            @Override
            public Change createChange(IProgressMonitor pm) {
                String change_name = NLS.bind(JdtUiMessages.SaveQueryEditorListener_change_name, editor_name, editorTitle);
                DocumentChange change = new DocumentChange(change_name, doc);
                TextEdit replaceEdit = new ReplaceEdit(position.x, position.y, newQuery);
                change.setEdit(replaceEdit);
                String cc_name = NLS.bind(JdtUiMessages.SaveQueryEditorListener_composite_change_name, editor_name);
                MultiStateTextFileChange mChange = new MultiStateTextFileChange(cc_name, file);
                mChange.addChange(change);
                return mChange;
            }

            @Override
            public String getName() {
                return JdtUiMessages.SaveQueryEditorListener_composite_change_name;
            }
        };
        RefactoringWizard wizard = new RefactoringWizard(ref, RefactoringWizard.DIALOG_BASED_USER_INTERFACE) {

            @Override
            protected void addUserInputPages() {
                UserInputWizardPage page = new UserInputWizardPage(wizard_title) {

                    public void createControl(Composite parent) {
                        Composite container = new Composite(parent, SWT.NULL);
                        GridLayout layout = new GridLayout();
                        container.setLayout(layout);
                        layout.numColumns = 1;
                        layout.verticalSpacing = 9;
                        Label label = new Label(container, SWT.NULL);
                        label.setText(NLS.bind(JdtUiMessages.SaveQueryEditorListener_replacequestion, editor_name, editorTitle));
                        setControl(container);
                    }
                };
                addPage(page);
            }
        };
        wizard.setWindowTitle(wizard_title);
        wizard.setDefaultPageTitle(wizard_title);
        IWorkbenchWindow win = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        if (new RefactoringStarter().activate(wizard, win.getShell(), wizard_title, RefactoringSaveHelper.SAVE_ALL)) {
            query = newQuery;
            position.y = query.length();
            fromEditorPart.doSave(null);
        } else {
            if (editor.getDocumentProvider() instanceof TextFileDocumentProvider) {
                ((TextFileDocumentProvider) editor.getDocumentProvider()).setCanSaveDocument(editor.getEditorInput());
            }
        }
    }
}
Also used : MultiStateTextFileChange(org.eclipse.ltk.core.refactoring.MultiStateTextFileChange) UserInputWizardPage(org.eclipse.ltk.ui.refactoring.UserInputWizardPage) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) RefactoringStarter(org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter) DocumentChange(org.eclipse.ltk.core.refactoring.DocumentChange) TextFileDocumentProvider(org.eclipse.ui.editors.text.TextFileDocumentProvider) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GridLayout(org.eclipse.swt.layout.GridLayout) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) RefactoringWizard(org.eclipse.ltk.ui.refactoring.RefactoringWizard) IFileEditorInput(org.eclipse.ui.IFileEditorInput) TextEdit(org.eclipse.text.edits.TextEdit) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) HQLEditor(org.hibernate.eclipse.hqleditor.HQLEditor) Refactoring(org.eclipse.ltk.core.refactoring.Refactoring) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 4 with RefactoringWizard

use of org.eclipse.ltk.ui.refactoring.RefactoringWizard in project erlide_eclipse by erlang.

the class MoveFunctionDropHandler method handleDrop.

@Override
public IStatus handleDrop(final CommonDropAdapter dropAdapter, final DropTargetEvent dropTargetEvent, final Object target) {
    // get the source data
    final TransferData td = dropAdapter.getCurrentTransfer();
    final ISelection sel = (ISelection) LocalSelectionTransfer.getTransfer().nativeToJava(td);
    final TreeSelection s = (TreeSelection) sel;
    try {
        GlobalParameters.setSelection(s);
    } catch (final WranglerException e1) {
        e1.printStackTrace();
    }
    // get the target data
    String moduleName;
    IFile file;
    if (target instanceof IFile) {
        file = (IFile) target;
    } else {
        file = (IFile) ((IErlElement) target).getResource();
    }
    moduleName = file.getName();
    moduleName = moduleName.substring(0, moduleName.lastIndexOf("."));
    final MoveFunctionRefactoring refactoring = new MoveFunctionRefactoring();
    refactoring.setUserInput(moduleName);
    final RefactoringWizard wizard = new DefaultWranglerRefactoringWizard(refactoring, RefactoringWizard.DIALOG_BASED_USER_INTERFACE, new ArrayList<WranglerPage>());
    final Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
    final RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
    try {
        op.run(shell, refactoring.getName());
    } catch (final Exception e) {
        ErlLogger.error(e);
    }
    return Status.OK_STATUS;
}
Also used : IFile(org.eclipse.core.resources.IFile) MoveFunctionRefactoring(org.erlide.wrangler.refactoring.core.internal.MoveFunctionRefactoring) WranglerException(org.erlide.wrangler.refactoring.exception.WranglerException) WranglerException(org.erlide.wrangler.refactoring.exception.WranglerException) IErlElement(org.erlide.engine.model.IErlElement) Shell(org.eclipse.swt.widgets.Shell) RefactoringWizardOpenOperation(org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation) TransferData(org.eclipse.swt.dnd.TransferData) DefaultWranglerRefactoringWizard(org.erlide.wrangler.refactoring.ui.wizard.DefaultWranglerRefactoringWizard) RefactoringWizard(org.eclipse.ltk.ui.refactoring.RefactoringWizard) TreeSelection(org.eclipse.jface.viewers.TreeSelection) ISelection(org.eclipse.jface.viewers.ISelection) DefaultWranglerRefactoringWizard(org.erlide.wrangler.refactoring.ui.wizard.DefaultWranglerRefactoringWizard) WranglerPage(org.erlide.wrangler.refactoring.ui.wizardpages.WranglerPage)

Example 5 with RefactoringWizard

use of org.eclipse.ltk.ui.refactoring.RefactoringWizard in project webtools.sourceediting by eclipse.

the class RenameComponentAction method run.

public void run(ISelection selection) {
    if (selectedComponent.getName() == null) {
        selectedComponent.setName(new String());
    }
    if (selectedComponent.getSchema() == null) {
        if (getSchema() != null) {
            getSchema().updateElement(true);
        }
    }
    boolean rc = SaveDirtyFilesDialog.saveDirtyFiles();
    if (!rc) {
        return;
    }
    RefactoringComponent component = new XMLRefactoringComponent(selectedComponent, (IDOMElement) selectedComponent.getElement(), selectedComponent.getName(), selectedComponent.getTargetNamespace());
    RenameComponentProcessor processor = new RenameComponentProcessor(component, selectedComponent.getName());
    RenameRefactoring refactoring = new RenameRefactoring(processor);
    try {
        RefactoringWizard wizard = new RenameRefactoringWizard(refactoring, RefactoringWizardMessages.RenameComponentWizard_defaultPageTitle, RefactoringWizardMessages.RenameComponentWizard_inputPage_description, null);
        RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
        op.run(XSDEditorPlugin.getShell(), wizard.getDefaultPageTitle());
    // TODO (cs) I'm not sure why we need to do this.  See bug 145700
    // triggerBuild();
    } catch (InterruptedException e) {
    // do nothing. User action got cancelled
    }
}
Also used : RefactoringWizardOpenOperation(org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation) RenameComponentProcessor(org.eclipse.wst.xsd.ui.internal.refactor.rename.RenameComponentProcessor) RenameRefactoringWizard(org.eclipse.wst.xsd.ui.internal.refactor.wizard.RenameRefactoringWizard) RenameRefactoringWizard(org.eclipse.wst.xsd.ui.internal.refactor.wizard.RenameRefactoringWizard) RefactoringWizard(org.eclipse.ltk.ui.refactoring.RefactoringWizard) XMLRefactoringComponent(org.eclipse.wst.xsd.ui.internal.refactor.XMLRefactoringComponent) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) XMLRefactoringComponent(org.eclipse.wst.xsd.ui.internal.refactor.XMLRefactoringComponent) RefactoringComponent(org.eclipse.wst.xsd.ui.internal.refactor.RefactoringComponent)

Aggregations

RefactoringWizard (org.eclipse.ltk.ui.refactoring.RefactoringWizard)7 RefactoringWizardOpenOperation (org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation)6 RenameRefactoring (org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)5 RenameRefactoringWizard (org.eclipse.wst.xsd.ui.internal.refactor.wizard.RenameRefactoringWizard)5 IFile (org.eclipse.core.resources.IFile)2 RefactoringComponent (org.eclipse.wst.xsd.ui.internal.refactor.RefactoringComponent)2 XMLRefactoringComponent (org.eclipse.wst.xsd.ui.internal.refactor.XMLRefactoringComponent)2 RenameComponentProcessor (org.eclipse.wst.xsd.ui.internal.refactor.rename.RenameComponentProcessor)2 IResource (org.eclipse.core.resources.IResource)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 RefactoringStarter (org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 IDocument (org.eclipse.jface.text.IDocument)1 ISelection (org.eclipse.jface.viewers.ISelection)1 TreeSelection (org.eclipse.jface.viewers.TreeSelection)1 DocumentChange (org.eclipse.ltk.core.refactoring.DocumentChange)1 MultiStateTextFileChange (org.eclipse.ltk.core.refactoring.MultiStateTextFileChange)1 Refactoring (org.eclipse.ltk.core.refactoring.Refactoring)1 UserInputWizardPage (org.eclipse.ltk.ui.refactoring.UserInputWizardPage)1 TransferData (org.eclipse.swt.dnd.TransferData)1