Index: refactoring/apichanges.xml =================================================================== RCS file: /cvs/refactoring/apichanges.xml,v retrieving revision 1.1 diff -u -r1.1 apichanges.xml --- refactoring/apichanges.xml 10 May 2005 11:52:15 -0000 1.1 +++ refactoring/apichanges.xml 20 May 2005 07:27:27 -0000 @@ -56,7 +56,33 @@ - + + UI Framewrok needs improvement for integration with CVS and for SafeDelete refactoring + + + + + +methods added: +============= +ProblemDetails Problem.getDetails() + +Classes added: +============= +ProblemDetails +ProblemDetailsFactory +ProblemDetailsImplementation +ReadOnlyFilesHandler + + + + + + + + + + This API change is needed for rewrite of refactoring D'n'D support. Index: refactoring/nbproject/project.properties =================================================================== RCS file: /cvs/refactoring/nbproject/project.properties,v retrieving revision 1.10 diff -u -r1.10 project.properties --- refactoring/nbproject/project.properties 10 May 2005 11:52:16 -0000 1.10 +++ refactoring/nbproject/project.properties 20 May 2005 07:27:27 -0000 @@ -9,7 +9,7 @@ # Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun # Microsystems, Inc. All Rights Reserved. -spec.version.base=1.4.0 +spec.version.base=1.5.0 javadoc.arch=${basedir}/arch/arch-refactoring.xml javadoc.title=Refactoring API Index: refactoring/src/org/netbeans/modules/refactoring/spi/AccessorImpl.java =================================================================== RCS file: /cvs/refactoring/src/org/netbeans/modules/refactoring/spi/AccessorImpl.java,v retrieving revision 1.1 diff -u -r1.1 AccessorImpl.java --- refactoring/src/org/netbeans/modules/refactoring/spi/AccessorImpl.java 26 Jan 2005 19:51:22 -0000 1.1 +++ refactoring/src/org/netbeans/modules/refactoring/spi/AccessorImpl.java 20 May 2005 07:27:27 -0000 @@ -12,6 +12,7 @@ */ package org.netbeans.modules.refactoring.spi; +import java.util.Collection; import java.util.List; import org.netbeans.modules.refactoring.SPIAccessor; import org.netbeans.modules.refactoring.api.RefactoringSession; @@ -25,5 +26,9 @@ public RefactoringElementsBag createBag(RefactoringSession session, List delegate) { assert session != null && delegate != null; return new RefactoringElementsBag(session, delegate); + } + + public Collection getReadOnlyFiles(RefactoringElementsBag bag) { + return bag.getReadOnlyFiles(); } } Index: refactoring/src/org/netbeans/modules/refactoring/spi/ProblemDetailsFactory.java =================================================================== RCS file: refactoring/src/org/netbeans/modules/refactoring/spi/ProblemDetailsFactory.java diff -N refactoring/src/org/netbeans/modules/refactoring/spi/ProblemDetailsFactory.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ refactoring/src/org/netbeans/modules/refactoring/spi/ProblemDetailsFactory.java 20 May 2005 07:27:27 -0000 @@ -0,0 +1,35 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.modules.refactoring.spi; + +import org.netbeans.modules.refactoring.APIAccessor; +import org.netbeans.modules.refactoring.api.ProblemDetails; + +/** + * Factory class for ProblemDetails + * @author Jan Becicka + * @since 1.4.0 + */ +public class ProblemDetailsFactory { + /** + * Factory method for creating API instances of ProblemDetails from SPI instances + * of ProblemDetailsImplementation + * @see ProblemDetails + * @see ProblemDetailsImplementation + */ + public static ProblemDetails createProblemDetails(ProblemDetailsImplementation pdi) { + return APIAccessor.DEFAULT.createProblemDetails(pdi); + } + +} Index: refactoring/src/org/netbeans/modules/refactoring/spi/ProblemDetailsImplementation.java =================================================================== RCS file: refactoring/src/org/netbeans/modules/refactoring/spi/ProblemDetailsImplementation.java diff -N refactoring/src/org/netbeans/modules/refactoring/spi/ProblemDetailsImplementation.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ refactoring/src/org/netbeans/modules/refactoring/spi/ProblemDetailsImplementation.java 20 May 2005 07:27:27 -0000 @@ -0,0 +1,42 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.modules.refactoring.spi; + +import javax.swing.Action; + +/** + * Typical implementation will invoke UI component on showDetails() call + * This UI component will display ProblemDetails. There will be a button, or + * similar UI control, which will be connected to rerunRefactoringAction to + * invoke refactoring again once the Problem is fixed. + * @author Jan Becicka + * @since 1.4.0 + */ +public interface ProblemDetailsImplementation { + + /** + * This method will typically invoke component with ProblemDetails. + * It is fully upon clients, how this component will be implemented. + * @param rerunRefactoringAction this action is passed to client component + * to allow clients to rerun refactoring once the Problem is fixed. + */ + void showDetails(Action rerunRefactoringAction); + + /** + * Message that will be displayed in parameters panel as a hint to suggest user, + * that there are more details available. + */ + String getDetailsHint(); + +} Index: refactoring/src/org/netbeans/modules/refactoring/spi/ReadOnlyFilesHandler.java =================================================================== RCS file: refactoring/src/org/netbeans/modules/refactoring/spi/ReadOnlyFilesHandler.java diff -N refactoring/src/org/netbeans/modules/refactoring/spi/ReadOnlyFilesHandler.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ refactoring/src/org/netbeans/modules/refactoring/spi/ReadOnlyFilesHandler.java 20 May 2005 07:27:27 -0000 @@ -0,0 +1,43 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.modules.refactoring.spi; + +import java.util.Collection; +import org.netbeans.modules.refactoring.api.Problem; + +/** + * Interface for factory classes which allows to create Problem, which ProblemDetails + * can handle read only files. Typically VCS can turn read only files into read write. + * Implementation of ReadOnlyFilesHandler is required to be registered in Lookup. + * More then one instance is not allowed to be registered. + * @author Jan Becicka + * @since 1.4.0 + */ +public interface ReadOnlyFilesHandler { + + /** + * Create a Problem, which ProblemDetails + * can handle read only files. Typically VCS can turn read only files into + * read write. + * Typical implementation will be following: + *
+     * new Problem(false,
+     *    "Some files needs to be checked out for editing",
+     *     ProblemDetailsFactory.createProblemDetails(new VCSDetailsImpl(files))
+     * );
+     * 
+ * @see ProblemDetailsImplementation + */ + public Problem createProblem(Collection files); +} Index: refactoring/src/org/netbeans/modules/refactoring/spi/RefactoringElementsBag.java =================================================================== RCS file: /cvs/refactoring/src/org/netbeans/modules/refactoring/spi/RefactoringElementsBag.java,v retrieving revision 1.2 diff -u -r1.2 RefactoringElementsBag.java --- refactoring/src/org/netbeans/modules/refactoring/spi/RefactoringElementsBag.java 23 Feb 2005 13:14:05 -0000 1.2 +++ refactoring/src/org/netbeans/modules/refactoring/spi/RefactoringElementsBag.java 20 May 2005 07:27:27 -0000 @@ -14,10 +14,13 @@ package org.netbeans.modules.refactoring.spi; import java.util.*; +import org.netbeans.jmi.javamodel.Resource; +import org.netbeans.modules.javacore.api.JavaModel; import org.netbeans.modules.refactoring.APIAccessor; import org.netbeans.modules.refactoring.CheckUtils; import org.netbeans.modules.refactoring.SPIAccessor; import org.netbeans.modules.refactoring.api.*; +import org.openide.filesystems.FileObject; /** * Container holding RefactoringElements @@ -30,6 +33,7 @@ private final List delegate; private final RefactoringSession session; + private Collection readOnlyFiles = new HashSet(); /** * Creates an instance of RefactoringElementsBag @@ -55,6 +59,14 @@ public Problem add(AbstractRefactoring refactoring, RefactoringElementImplementation el) { Problem p = null; if (CheckUtils.isRefactoringElementReadOnly(el)) { + Resource resource = el.getJavaElement().getResource(); + FileObject file; + if (resource == null) { + file = el.getParentFile(); + } else { + file = JavaModel.getFileObject(resource); + } + readOnlyFiles.add(file); el.setEnabled(false); el.setStatus(el.READ_ONLY); delegate.add(el); @@ -103,5 +115,9 @@ public RefactoringSession getSession() { return session; + } + + Collection getReadOnlyFiles() { + return readOnlyFiles; } } Index: refactoring/src/org/netbeans/modules/refactoring/api/AbstractRefactoring.java =================================================================== RCS file: /cvs/refactoring/src/org/netbeans/modules/refactoring/api/AbstractRefactoring.java,v retrieving revision 1.23 diff -u -r1.23 AbstractRefactoring.java --- refactoring/src/org/netbeans/modules/refactoring/api/AbstractRefactoring.java 7 Apr 2005 07:39:23 -0000 1.23 +++ refactoring/src/org/netbeans/modules/refactoring/api/AbstractRefactoring.java 20 May 2005 07:27:27 -0000 @@ -15,15 +15,19 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; +import java.util.List; import org.netbeans.modules.javacore.api.JavaModel; import org.netbeans.modules.javacore.JMManager; import org.netbeans.modules.refactoring.APIAccessor; import org.netbeans.modules.refactoring.ProgressSupport; +import org.netbeans.modules.refactoring.SPIAccessor; import org.netbeans.modules.refactoring.spi.GuardedBlockHandler; import org.netbeans.modules.refactoring.spi.GuardedBlockHandlerFactory; import org.netbeans.modules.refactoring.spi.ProgressProvider; +import org.netbeans.modules.refactoring.spi.ReadOnlyFilesHandler; import org.netbeans.modules.refactoring.spi.RefactoringPlugin; import org.netbeans.modules.refactoring.spi.RefactoringPluginFactory; +import org.openide.ErrorManager; import org.openide.util.Lookup; import org.netbeans.modules.refactoring.spi.RefactoringElementsBag; @@ -271,7 +275,25 @@ if (problem!=null && problem.isFatal()) return problem; } + ReadOnlyFilesHandler handler = getROHandler(); + if (handler!=null) { + Collection files = SPIAccessor.DEFAULT.getReadOnlyFiles(elements); + problem = chainProblems(handler.createProblem(files), problem); + } + return problem; + } + + private ReadOnlyFilesHandler getROHandler() { + Lookup.Result result = Lookup.getDefault().lookup(new Lookup.Template(ReadOnlyFilesHandler.class)); + List handlers = (List) result.allInstances(); + if (handlers.size() == 0) { + return null; + } + if (handlers.size() > 1) { + ErrorManager.getDefault().log(ErrorManager.WARNING, "Multiple instances of ReadOnlyFilesHandler found in Lookup; only using first one: " + handlers); //NOI18N + } + return (ReadOnlyFilesHandler) handlers.get(0); } private Problem pluginsCheckParams(Problem problem) { Index: refactoring/src/org/netbeans/modules/refactoring/api/AccessorImpl.java =================================================================== RCS file: /cvs/refactoring/src/org/netbeans/modules/refactoring/api/AccessorImpl.java,v retrieving revision 1.1 diff -u -r1.1 AccessorImpl.java --- refactoring/src/org/netbeans/modules/refactoring/api/AccessorImpl.java 26 Jan 2005 19:51:19 -0000 1.1 +++ refactoring/src/org/netbeans/modules/refactoring/api/AccessorImpl.java 20 May 2005 07:27:27 -0000 @@ -14,6 +14,7 @@ import java.util.Collection; import org.netbeans.modules.refactoring.APIAccessor; +import org.netbeans.modules.refactoring.spi.ProblemDetailsImplementation; /** * @@ -28,4 +29,10 @@ public Problem chainProblems(Problem p, Problem p1) { return AbstractRefactoring.chainProblems(p, p1); } + + public ProblemDetails createProblemDetails(ProblemDetailsImplementation pdi) { + assert pdi != null; + return new ProblemDetails(pdi); + } + } Index: refactoring/src/org/netbeans/modules/refactoring/api/Problem.java =================================================================== RCS file: /cvs/refactoring/src/org/netbeans/modules/refactoring/api/Problem.java,v retrieving revision 1.4 diff -u -r1.4 Problem.java --- refactoring/src/org/netbeans/modules/refactoring/api/Problem.java 10 Jan 2005 14:48:46 -0000 1.4 +++ refactoring/src/org/netbeans/modules/refactoring/api/Problem.java 20 May 2005 07:27:27 -0000 @@ -12,6 +12,8 @@ */ package org.netbeans.modules.refactoring.api; +import org.netbeans.modules.refactoring.spi.ui.RefactoringUI; + /** Class used to represent problems encountered when performing * various refactoring calls. Problems can be chained (using setNext method) * - every problem can point to the following problem. @@ -22,6 +24,7 @@ private final boolean fatal; private final String message; private Problem next = null; + private ProblemDetails details; /** Creates new instance of Problem class. * @param fatal Indicates whether the problem is fatal. @@ -32,6 +35,11 @@ this.message = message; } + public Problem(boolean fatal, String message, ProblemDetails details) { + this(fatal, message); + this.details = details; + } + /** Indicates whether the problem is fatal. * @return true if the problem is fatal, otherwise returns false. */ @@ -64,5 +72,13 @@ throw new IllegalStateException("Cannot change \"next\" property of Problem."); //NOI18N } this.next = next; + } + + /** + * Getter for ProblemDetails + * @return instance of ProblemDetails or null + */ + public ProblemDetails getDetails() { + return details; } } Index: refactoring/src/org/netbeans/modules/refactoring/api/ProblemDetails.java =================================================================== RCS file: refactoring/src/org/netbeans/modules/refactoring/api/ProblemDetails.java diff -N refactoring/src/org/netbeans/modules/refactoring/api/ProblemDetails.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ refactoring/src/org/netbeans/modules/refactoring/api/ProblemDetails.java 20 May 2005 07:27:27 -0000 @@ -0,0 +1,50 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.modules.refactoring.api; + +import javax.swing.Action; +import org.netbeans.modules.refactoring.spi.ProblemDetailsImplementation; + +/** + * This class holds details of a Problem + * @author Jan Becicka + * @since 1.4.0 + */ +public final class ProblemDetails { + + private ProblemDetailsImplementation pdi; + + ProblemDetails (ProblemDetailsImplementation pdi) { + this.pdi=pdi; + } + + /** + * This method will typically invoke component with ProblemDetails. + * It is fully upon clients, how this component will be implemented. + * @param rerunRefactoringAction this action is passed to client component + * to allow clients to invoke refactoring once the Problem is fixed. + * @see ProblemDetailsImplementation + */ + public void showDetails(Action rerunRefactoringAction) { + pdi.showDetails(rerunRefactoringAction); + } + + /** + * Message that will be displayed in parameters panel as a hint to suggest user, + * that there are more details available. + */ + public String getDetailsHint() { + return pdi.getDetailsHint(); + } +} Index: refactoring/arch/arch-refactoring.xml =================================================================== RCS file: /cvs/refactoring/arch/arch-refactoring.xml,v retrieving revision 1.15 diff -u -r1.15 arch-refactoring.xml --- refactoring/arch/arch-refactoring.xml 23 Mar 2005 07:26:07 -0000 1.15 +++ refactoring/arch/arch-refactoring.xml 20 May 2005 07:27:28 -0000 @@ -413,12 +413,10 @@ Yes. We search for:
  • -
  • - - to register OperationListener and allow automatic refactorings. -
  • org.openide.nodes.Node - listens to (resp. org.openide.util.Utilities.actionsGlobalContext() lookup) to look for active node in RefactoringSubMenuAction
  • all instances of
  • all instances of
  • +
  • an instance of