How to rename a custom project type?

xolmc <[email protected]> Wed, 19 Oct 2011 02:18:52 -0700 (PDT)
Newsgroups gmane.comp.java.netbeans.user-interface
Message-ID <[email protected]>
Hi All!
Could somebody explain me and better provide a code snippet of subject
implementation, please?
I really stuck with it!

So what I have already made:

1) I've build the  
http://platform.netbeans.org/tutorials/nbm-projecttype.html NetBeans Project
Type Module Tutorial   by Geertjan
but there are just basic actions implementations in this great example (in 
root node of LogicalViewProvider and accordingly in Project implementation
):

        @Override
        public Action[] getActions(boolean arg0) {
            Action[] nodeActions = new Action[7];
            nodeActions[0] = CommonProjectActions.newFileAction();
            nodeActions[1] = CommonProjectActions.copyProjectAction();
            nodeActions[2] = CommonProjectActions.deleteProjectAction();
            nodeActions[5] = CommonProjectActions.setAsMainProjectAction();
            nodeActions[6] = CommonProjectActions.closeProjectAction();
            return nodeActions;
        }

and no 'Rename...' command implementation at all. 




2) OK, I  tried to extend this example by adding 
CommonProjectActions.renameProjectAction()

[ nodeActions[2] = CommonProjectActions.renameProjectAction(); ]

into LogicalViewProvider. This provide my project by 'Rename...' context
menu item of the project's root node.

Next I added rename action into ActionProvider implementation of my project
like:

      private String[] supported = new String[]{
            ActionProvider.COMMAND_DELETE,
            ActionProvider.COMMAND_COPY,
            ActionProvider.COMMAND_RENAME,
            ActionProvider.COMMAND_MOVE,};


 then


       @Override
        public void invokeAction(String string, Lookup lookup) throws
IllegalArgumentException {

              ......
              ......

            if (string.equalsIgnoreCase(ActionProvider.COMMAND_RENAME)) {
               
DefaultProjectOperations.performDefaultRenameOperation(PCProject.this,
PROJECT_FOLDER.getName());
            }

            if (string.equalsIgnoreCase(ActionProvider.COMMAND_MOVE)) {
               
DefaultProjectOperations.performDefaultRenameOperation(PCProject.this,
PROJECT_FOLDER.getName());
            }
        }


and

       @Override
        public boolean isActionEnabled(String command, Lookup lookup) throws
IllegalArgumentException {
            if ((command.equals(ActionProvider.COMMAND_RENAME))) {
                return true;
            } else if ((command.equals(ActionProvider.COMMAND_MOVE))) {
                return true;
            } else
            ....
            ....
        }

and following MoveOrRenameOperationImplementation I added into Project's
lookup:


   private final class MoveOrRenameOperation implements
MoveOrRenameOperationImplementation {

        @Override
        public List<FileObject> getMetadataFiles() {
            List<FileObject> dataFiles = new ArrayList<FileObject>();
           
dataFiles.add(PROJECT_FOLDER.getFileObject(Utils.PROJECT_INDICATOR_FOLDER));
            return dataFiles;
        }

        @Override
        public List<FileObject> getDataFiles() {
            List<FileObject> dataFiles = new ArrayList<FileObject>();
            dataFiles.add(PROJECT_FOLDER);
            return dataFiles;
        }

        @Override
        public void notifyRenaming() throws IOException {
            System.out.println("notifyRenaming");
        }

        @Override
        public void notifyRenamed(String nueName) throws IOException {
            System.out.println("Renamed");
            System.out.println(nueName);
            name = nueName;
        }

        @Override
        public void notifyMoving() throws IOException {
            System.out.println("notifyMoving");
        }

        @Override
        public void notifyMoved(Project original, File originalPath, String
nueName) throws IOException {
            System.out.println("notifyMoved");
        }
    }


    @Override
    public Lookup getLookup() {
        if (lkp == null) {
            lkp = Lookups.fixed(new Object[]{
                        state, //allow outside code to mark the project as
needing saving
                        new ActionProviderImpl(), //Provides standard
actions like Build and Clean
                        new DeleteOperation(),
                        new CopyOperation(this),
                        new MoveOrRenameOperation(),
                        new CustomizerProviderImpl(this),
                        new Info(), //Project information implementation
                        new PCProjectLogicalView(this), //Logical view of
project implementation
                        loadProperties(),});
        }
        return lkp;
    }

3) New, gotten from MoveOrRenameOperationImplementation name, I pass to
ProjectInformation class


And, here I've stuck with wrong rename action behavior:
1) I do have context menu working
2) On 'Rename...' item click I do get standard rename dialog
3) And I do can rename the project BUT:
          a) If I perform just project renaming (I mean without folder
renaming too), I see the name changes just in IDE title and in File tab AND
NOT IN Project tab.
          b) But if I also rename project's folder, I can see the new name
changed in Projects tabg immediately.
          
From this behavior I conclude that Project tab listen just project root
folder 
dataobject changing and don't listen and don't care about ProjectInformation
implementation getName() method.
          
So my question is: how can I force the Project tab to be attentive to
project.properties changes and not to project root folder dataobject?       
I tried to browse ant based project source code, but it seems to much
complicated for me. I mean in case of ant based project using I would like
to get some theory explanation about it's work flow cause there are a lot of
classes involved and my boss already pressing me to finish the project I
building at work:) 

Any help, code snipped, theoretical explanation very appreciated.
Thanks
Dima.

--
View this message in context: http://netbeans-org.1045718.n5.nabble.com/How-to-rename-a-custom-project-type-tp4917016p4917016.html
Sent from the Netbeans Project UI Design and Discussion (not for user help) mailing list archive at Nabble.com.