Search in sources :

Example 1 with MultiStateTextFileChange

use of org.eclipse.ltk.core.refactoring.MultiStateTextFileChange 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 2 with MultiStateTextFileChange

use of org.eclipse.ltk.core.refactoring.MultiStateTextFileChange in project che by eclipse.

the class CompilationUnitChangeNode method createChildNodes.

@Override
protected ChildNode[] createChildNodes() {
    TextEditBasedChange change = getTextEditBasedChange();
    if (change instanceof MultiStateTextFileChange) {
        // no edit preview & edit disabling possible in the MultiStateTextFileChange (edits must be applied
        return new ChildNode[0];
    // in sequence)
    }
    ICompilationUnit cunit = (ICompilationUnit) change.getAdapter(ICompilationUnit.class);
    if (cunit != null) {
        List<ChildNode> children = new ArrayList<ChildNode>(5);
        Map<IJavaElement, JavaLanguageNode> map = new HashMap<IJavaElement, JavaLanguageNode>(20);
        TextEditBasedChangeGroup[] changes = getSortedChangeGroups(change);
        for (int i = 0; i < changes.length; i++) {
            TextEditBasedChangeGroup tec = changes[i];
            try {
                IJavaElement element = getModifiedJavaElement(tec, cunit);
                if (element.equals(cunit)) {
                    children.add(createTextEditGroupNode(this, tec));
                } else {
                    JavaLanguageNode pjce = getChangeElement(map, element, children, this);
                    pjce.addChild(createTextEditGroupNode(pjce, tec));
                }
            } catch (JavaModelException e) {
                children.add(createTextEditGroupNode(this, tec));
            }
        }
        return children.toArray(new ChildNode[children.size()]);
    } else {
        return EMPTY_CHILDREN;
    }
}
Also used : MultiStateTextFileChange(org.eclipse.ltk.core.refactoring.MultiStateTextFileChange) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IJavaElement(org.eclipse.jdt.core.IJavaElement) JavaModelException(org.eclipse.jdt.core.JavaModelException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TextEditBasedChangeGroup(org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup) TextEditBasedChange(org.eclipse.ltk.core.refactoring.TextEditBasedChange)

Example 3 with MultiStateTextFileChange

use of org.eclipse.ltk.core.refactoring.MultiStateTextFileChange in project che by eclipse.

the class TextEditChangeNode method createChildNodes.

protected ChildNode[] createChildNodes() {
    TextEditBasedChange change = getTextEditBasedChange();
    if (change instanceof MultiStateTextFileChange) {
        // no edit preview & edit disabling possible in the MultiStateTextFileChange (edits must be applied in sequence)
        return new ChildNode[0];
    }
    TextEditBasedChangeGroup[] groups = getSortedChangeGroups(change);
    ChildNode[] result = new ChildNode[groups.length];
    for (int i = 0; i < groups.length; i++) {
        result[i] = new TextEditGroupNode(this, groups[i]);
    }
    return result;
}
Also used : MultiStateTextFileChange(org.eclipse.ltk.core.refactoring.MultiStateTextFileChange) TextEditBasedChange(org.eclipse.ltk.core.refactoring.TextEditBasedChange) TextEditGroupNode(org.eclipse.ltk.internal.ui.refactoring.TextEditGroupNode) TextEditBasedChangeGroup(org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup)

Aggregations

MultiStateTextFileChange (org.eclipse.ltk.core.refactoring.MultiStateTextFileChange)3 TextEditBasedChange (org.eclipse.ltk.core.refactoring.TextEditBasedChange)2 TextEditBasedChangeGroup (org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 IFile (org.eclipse.core.resources.IFile)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)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 DocumentChange (org.eclipse.ltk.core.refactoring.DocumentChange)1 Refactoring (org.eclipse.ltk.core.refactoring.Refactoring)1 TextEditGroupNode (org.eclipse.ltk.internal.ui.refactoring.TextEditGroupNode)1 RefactoringWizard (org.eclipse.ltk.ui.refactoring.RefactoringWizard)1 UserInputWizardPage (org.eclipse.ltk.ui.refactoring.UserInputWizardPage)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1