1 19 20 package org.netbeans.modules.project.ui.actions; 21 22 import java.io.IOException ; 23 import java.util.HashSet ; 24 import java.util.List ; 25 import java.util.Set ; 26 import javax.swing.Action ; 27 import javax.swing.JMenuItem ; 28 import org.netbeans.api.project.FileOwnerQuery; 29 import org.netbeans.api.project.Project; 30 import org.netbeans.modules.project.ui.ExitDialog; 31 import org.netbeans.spi.project.support.ProjectOperations; 32 import org.netbeans.spi.project.ui.CustomizerProvider; 33 import org.openide.DialogDisplayer; 34 import org.openide.NotifyDescriptor; 35 import org.openide.cookies.SaveCookie; 36 import org.openide.loaders.DataObject; 37 import org.openide.util.Lookup; 38 import org.openide.util.NbBundle; 39 import org.openide.util.actions.Presenter; 40 import org.openide.filesystems.FileObject; 41 import org.openide.filesystems.FileUtil; 42 43 45 public class CustomizeProject extends ProjectAction implements Presenter.Popup { 46 47 private static final String namePattern = NbBundle.getMessage( CustomizeProject.class, "LBL_CustomizeProjectAction_Name" ); private static final String namePatternPopup = NbBundle.getMessage( CustomizeProject.class, "LBL_CustomizeProjectAction_Popup_Name" ); 50 public CustomizeProject() { 51 this( null ); 52 } 53 54 public CustomizeProject( Lookup context ) { 55 super( (String )null, namePattern, null, context ); 56 refresh( getLookup() ); 57 } 58 59 60 61 protected void refresh( Lookup context ) { 62 63 super.refresh( context ); 64 65 Project[] projects = ActionsUtil.getProjectsFromLookup( context, null ); 66 67 if ( projects.length != 1 || projects[0].getLookup().lookup( CustomizerProvider.class ) == null ) { 68 setEnabled( false ); 69 } 71 else { 72 setEnabled( true ); 73 } 75 76 77 } 78 79 public void actionPerformed( Lookup context ) { 80 81 Project[] projects = ActionsUtil.getProjectsFromLookup( context, null ); 82 83 if ( projects.length == 1 ) { 84 CustomizerProvider cp = projects[0].getLookup().lookup( CustomizerProvider.class ); 85 if ( cp != null ) { 86 if (!DataObject.getRegistry().getModifiedSet().isEmpty()) { 87 89 Set <DataObject> candidates = new HashSet <DataObject>(); 91 List <FileObject> dataFiles = ProjectOperations.getDataFiles(projects[0]); 92 boolean opSupported = ProjectOperations.isCopyOperationSupported(projects[0]) || 93 ProjectOperations.isMoveOperationSupported(projects[0]) || 94 ProjectOperations.isDeleteOperationSupported(projects[0]); 95 96 for (DataObject dobj : DataObject.getRegistry().getModifiedSet()) { 97 if (projects[0] == FileOwnerQuery.getOwner(dobj.getPrimaryFile())) { 99 boolean found = false; 101 for (FileObject df : dataFiles) { 102 if (df.equals(dobj.getPrimaryFile()) || 103 (df.isFolder() && FileUtil.isParentOf(df, dobj.getPrimaryFile()))) { 104 found = true; 105 break; 106 } 107 } 108 if (!found || !opSupported) { 109 candidates.add(dobj); 110 } 111 } 112 } 113 if (!candidates.isEmpty()) { 114 String saveAll = NbBundle.getMessage(CustomizeProject.class, "CustomizeProject.saveAll"); 115 Object ret = DialogDisplayer.getDefault().notify(new NotifyDescriptor( 116 NbBundle.getMessage(CustomizeProject.class, "CustomizeProject.save_modified_files"), 117 NbBundle.getMessage(CustomizeProject.class, "CustomizeProject.save_modified_title"), 118 NotifyDescriptor.OK_CANCEL_OPTION, 119 NotifyDescriptor.WARNING_MESSAGE, 120 new Object [] { 121 saveAll, 122 NotifyDescriptor.CANCEL_OPTION 123 }, 124 saveAll)); 125 if (ret != saveAll) { 126 return; 127 } else { 128 for (DataObject dobj : candidates) { 129 ExitDialog.doSave(dobj); 130 } 131 } 132 } 133 } 134 cp.showCustomizer(); 135 } 136 } 137 138 } 139 140 public Action createContextAwareInstance( Lookup actionContext ) { 141 return new CustomizeProject( actionContext ); 142 } 143 144 145 147 public JMenuItem getPopupPresenter() { 148 JMenuItem popupPresenter = new JMenuItem ( this ); 149 popupPresenter.setText( namePatternPopup ); 150 popupPresenter.setIcon( null ); 151 152 return popupPresenter; 153 } 154 155 } 156 | Popular Tags |