[platform-dev] How to rename a custom project type?

  • From: "Ben35" < >
  • To:
  • Subject: [platform-dev] How to rename a custom project type?
  • Date: Thu, 27 Sep 2012 04:50:40 -0400

Hi All!
Could somebody explain me and better provide a code snippet of rename a 
project based on custom project type implementation, please?
I really stuck with it!

So what I have already made:

1) I've build the  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 tab 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.
         
BTW even I pass new name to Root Node, Projects tab changes it not 
automatically but after some other action needed node refresh like 'Set as 
main project' .

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






[platform-dev] How to rename a custom project type?

Ben35 09/27/2012

Project Features

Project Links

About this Project

Platform was started in November 2009, is owned by Antonin Nebuzelsky, and has 138 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close