Lines 41-102
Link Here
|
41 |
* Version 2 license, then the option applies only if the new code is |
41 |
* Version 2 license, then the option applies only if the new code is |
42 |
* made subject to such option by the copyright holder. |
42 |
* made subject to such option by the copyright holder. |
43 |
*/ |
43 |
*/ |
44 |
|
|
|
45 |
package org.netbeans.modules.web.project.ui.customizer; |
44 |
package org.netbeans.modules.web.project.ui.customizer; |
46 |
|
45 |
|
|
|
46 |
import java.text.MessageFormat; |
47 |
import java.util.regex.Pattern; |
47 |
import javax.swing.JButton; |
48 |
import javax.swing.JButton; |
48 |
import javax.swing.JFileChooser; |
49 |
import javax.swing.JFileChooser; |
49 |
import javax.swing.JPanel; |
50 |
import javax.swing.JPanel; |
|
|
51 |
import javax.swing.event.DocumentEvent; |
52 |
import javax.swing.event.DocumentListener; |
50 |
import javax.swing.event.TableModelEvent; |
53 |
import javax.swing.event.TableModelEvent; |
51 |
import javax.swing.event.TableModelListener; |
54 |
import javax.swing.event.TableModelListener; |
52 |
import javax.swing.table.TableModel; |
55 |
import javax.swing.table.TableModel; |
53 |
import org.netbeans.api.java.project.JavaProjectConstants; |
56 |
import org.netbeans.api.java.project.JavaProjectConstants; |
54 |
import org.netbeans.modules.j2ee.api.ejbjar.EjbProjectConstants; |
57 |
import org.netbeans.modules.j2ee.api.ejbjar.EjbProjectConstants; |
55 |
import org.netbeans.modules.j2ee.common.Util; |
58 |
import org.netbeans.modules.j2ee.common.Util; |
|
|
59 |
import org.netbeans.modules.j2ee.common.project.ui.MessageUtils; |
56 |
import org.netbeans.modules.java.api.common.classpath.ClassPathSupport; |
60 |
import org.netbeans.modules.java.api.common.classpath.ClassPathSupport; |
57 |
import org.netbeans.modules.java.api.common.classpath.ClassPathSupport.Item; |
61 |
import org.netbeans.modules.java.api.common.classpath.ClassPathSupport.Item; |
58 |
import org.netbeans.modules.java.api.common.project.ui.ClassPathUiSupport; |
62 |
import org.netbeans.modules.java.api.common.project.ui.ClassPathUiSupport; |
59 |
import org.netbeans.modules.java.api.common.project.ui.customizer.EditMediator; |
63 |
import org.netbeans.modules.java.api.common.project.ui.customizer.EditMediator; |
60 |
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; |
64 |
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; |
61 |
import org.netbeans.modules.web.project.classpath.ClassPathSupportCallbackImpl; |
65 |
import org.netbeans.modules.web.project.classpath.ClassPathSupportCallbackImpl; |
|
|
66 |
import org.netbeans.spi.project.ui.support.ProjectCustomizer; |
62 |
import org.openide.DialogDisplayer; |
67 |
import org.openide.DialogDisplayer; |
63 |
import org.openide.NotifyDescriptor; |
68 |
import org.openide.NotifyDescriptor; |
|
|
69 |
import org.openide.WizardValidationException; |
64 |
import org.openide.util.HelpCtx; |
70 |
import org.openide.util.HelpCtx; |
65 |
import org.openide.util.NbBundle; |
71 |
import org.openide.util.NbBundle; |
|
|
72 |
import org.openide.util.Utilities; |
66 |
|
73 |
|
67 |
/** Customizer for WAR packaging. |
74 |
/** Customizer for WAR packaging. |
68 |
*/ |
75 |
*/ |
69 |
public class CustomizerWar extends JPanel implements HelpCtx.Provider, TableModelListener { |
76 |
public class CustomizerWar extends JPanel implements HelpCtx.Provider, TableModelListener { |
70 |
|
77 |
|
71 |
WebProjectProperties uiProperties; |
78 |
WebProjectProperties uiProperties; |
72 |
|
79 |
ProjectCustomizer.Category category; |
|
|
80 |
|
73 |
/** Creates new form CustomizerCompile */ |
81 |
/** Creates new form CustomizerCompile */ |
74 |
public CustomizerWar(WebProjectProperties uiProperties) { |
82 |
public CustomizerWar(ProjectCustomizer.Category category, WebProjectProperties uiProperties) { |
|
|
83 |
this.category=category; |
75 |
this.uiProperties = uiProperties; |
84 |
this.uiProperties = uiProperties; |
76 |
initComponents(); |
85 |
initComponents(); |
77 |
this.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CustomizerWar.class, "ACS_CustomizeWAR_A11YDesc")); //NOI18N |
86 |
this.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CustomizerWar.class, "ACS_CustomizeWAR_A11YDesc")); //NOI18N |
78 |
|
87 |
|
79 |
jTextFieldFileName.setDocument( uiProperties.WAR_NAME_MODEL ); |
88 |
jTextFieldFileName.setDocument(uiProperties.WAR_NAME_MODEL); |
80 |
jTextFieldExContent.setDocument( uiProperties.BUILD_CLASSES_EXCLUDES_MODEL ); |
89 |
jTextFieldFileName.getDocument().addDocumentListener(new DocumentListener() { |
81 |
uiProperties.WAR_COMPRESS_MODEL.setMnemonic( jCheckBoxCompress.getMnemonic() ); |
90 |
|
82 |
jCheckBoxCompress.setModel( uiProperties.WAR_COMPRESS_MODEL ); |
91 |
@Override |
|
|
92 |
public void insertUpdate(DocumentEvent e) { |
93 |
checkValidWarFilename(); |
94 |
} |
95 |
|
96 |
@Override |
97 |
public void removeUpdate(DocumentEvent e) { |
98 |
checkValidWarFilename(); |
99 |
} |
100 |
|
101 |
@Override |
102 |
public void changedUpdate(DocumentEvent e) { |
103 |
checkValidWarFilename(); |
104 |
} |
105 |
|
106 |
}); |
107 |
jTextFieldExContent.setDocument(uiProperties.BUILD_CLASSES_EXCLUDES_MODEL); |
108 |
uiProperties.WAR_COMPRESS_MODEL.setMnemonic(jCheckBoxCompress.getMnemonic()); |
109 |
jCheckBoxCompress.setModel(uiProperties.WAR_COMPRESS_MODEL); |
83 |
ClassPathUiSupport.Callback callback = new ClassPathUiSupport.Callback() { |
110 |
ClassPathUiSupport.Callback callback = new ClassPathUiSupport.Callback() { |
|
|
111 |
|
84 |
public void initItem(Item item) { |
112 |
public void initItem(Item item) { |
85 |
if (item.getType() != ClassPathSupport.Item.TYPE_LIBRARY || !item.getLibrary().getType().equals(J2eePlatform.LIBRARY_TYPE)) { |
113 |
if (item.getType() != ClassPathSupport.Item.TYPE_LIBRARY || !item.getLibrary().getType().equals(J2eePlatform.LIBRARY_TYPE)) { |
86 |
item.setAdditionalProperty(ClassPathSupportCallbackImpl.PATH_IN_DEPLOYMENT, "/"); //NOI18N |
114 |
item.setAdditionalProperty(ClassPathSupportCallbackImpl.PATH_IN_DEPLOYMENT, "/"); //NOI18N |
87 |
} |
115 |
} |
88 |
} |
116 |
} |
89 |
}; |
117 |
}; |
90 |
|
118 |
|
91 |
jTableAddContent.setModel( uiProperties.WAR_CONTENT_ADDITIONAL_MODEL); |
119 |
jTableAddContent.setModel(uiProperties.WAR_CONTENT_ADDITIONAL_MODEL); |
92 |
jTableAddContent.setDefaultRenderer(ClassPathSupport.Item.class, uiProperties.CLASS_PATH_TABLE_ITEM_RENDERER); |
120 |
jTableAddContent.setDefaultRenderer(ClassPathSupport.Item.class, uiProperties.CLASS_PATH_TABLE_ITEM_RENDERER); |
93 |
Util.initTwoColumnTableVisualProperties(this, jTableAddContent); |
121 |
Util.initTwoColumnTableVisualProperties(this, jTableAddContent); |
94 |
jTableAddContent.setRowHeight(jTableAddContent.getRowHeight() + 4); |
122 |
jTableAddContent.setRowHeight(jTableAddContent.getRowHeight() + 4); |
95 |
|
123 |
|
96 |
EditMediator.register( uiProperties.getProject(), |
124 |
EditMediator.register(uiProperties.getProject(), |
97 |
uiProperties.getProject().getAntProjectHelper(), |
125 |
uiProperties.getProject().getAntProjectHelper(), |
98 |
uiProperties.getProject().getReferenceHelper(), |
126 |
uiProperties.getProject().getReferenceHelper(), |
99 |
EditMediator.createListComponent(jTableAddContent, uiProperties.WAR_CONTENT_ADDITIONAL_MODEL.getDefaultListModel()) , |
127 |
EditMediator.createListComponent(jTableAddContent, uiProperties.WAR_CONTENT_ADDITIONAL_MODEL.getDefaultListModel()), |
100 |
jButtonAddJar.getModel(), |
128 |
jButtonAddJar.getModel(), |
101 |
jButtonAddLib.getModel(), |
129 |
jButtonAddLib.getModel(), |
102 |
jButtonAddProject.getModel(), |
130 |
jButtonAddProject.getModel(), |
Lines 110-116
Link Here
|
110 |
null, JFileChooser.FILES_AND_DIRECTORIES); |
138 |
null, JFileChooser.FILES_AND_DIRECTORIES); |
111 |
uiProperties.WAR_CONTENT_ADDITIONAL_MODEL.addTableModelListener(this); |
139 |
uiProperties.WAR_CONTENT_ADDITIONAL_MODEL.addTableModelListener(this); |
112 |
} |
140 |
} |
113 |
|
141 |
|
114 |
/** This method is called from within the constructor to |
142 |
/** This method is called from within the constructor to |
115 |
* initialize the form. |
143 |
* initialize the form. |
116 |
* WARNING: Do NOT modify this code. The content of this method is |
144 |
* WARNING: Do NOT modify this code. The content of this method is |
Lines 134-139
Link Here
|
134 |
jButtonAddLib = new javax.swing.JButton(); |
162 |
jButtonAddLib = new javax.swing.JButton(); |
135 |
jButtonAddJar = new javax.swing.JButton(); |
163 |
jButtonAddJar = new javax.swing.JButton(); |
136 |
jButtonRemove = new javax.swing.JButton(); |
164 |
jButtonRemove = new javax.swing.JButton(); |
|
|
165 |
errorLabel = new javax.swing.JLabel(); |
137 |
|
166 |
|
138 |
setLayout(new java.awt.GridBagLayout()); |
167 |
setLayout(new java.awt.GridBagLayout()); |
139 |
|
168 |
|
Lines 227-233
Link Here
|
227 |
gridBagConstraints = new java.awt.GridBagConstraints(); |
256 |
gridBagConstraints = new java.awt.GridBagConstraints(); |
228 |
gridBagConstraints.gridx = 0; |
257 |
gridBagConstraints.gridx = 0; |
229 |
gridBagConstraints.gridy = 4; |
258 |
gridBagConstraints.gridy = 4; |
230 |
gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; |
259 |
gridBagConstraints.gridheight = 6; |
231 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
260 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
232 |
gridBagConstraints.weightx = 1.0; |
261 |
gridBagConstraints.weightx = 1.0; |
233 |
gridBagConstraints.weighty = 1.0; |
262 |
gridBagConstraints.weighty = 1.0; |
Lines 278-286
Link Here
|
278 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; |
307 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; |
279 |
add(jButtonRemove, gridBagConstraints); |
308 |
add(jButtonRemove, gridBagConstraints); |
280 |
jButtonRemove.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_CustomizeWAR_AdditionalRemove_A11YDesc")); // NOI18N |
309 |
jButtonRemove.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_CustomizeWAR_AdditionalRemove_A11YDesc")); // NOI18N |
|
|
310 |
|
311 |
gridBagConstraints = new java.awt.GridBagConstraints(); |
312 |
gridBagConstraints.gridx = 0; |
313 |
gridBagConstraints.gridy = 10; |
314 |
gridBagConstraints.gridwidth = 2; |
315 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
316 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH; |
317 |
gridBagConstraints.weightx = 1.0; |
318 |
add(errorLabel, gridBagConstraints); |
281 |
}// </editor-fold>//GEN-END:initComponents |
319 |
}// </editor-fold>//GEN-END:initComponents |
282 |
|
|
|
283 |
// Variables declaration - do not modify//GEN-BEGIN:variables |
320 |
// Variables declaration - do not modify//GEN-BEGIN:variables |
|
|
321 |
private javax.swing.JLabel errorLabel; |
284 |
private javax.swing.JLabel excludeMessage; |
322 |
private javax.swing.JLabel excludeMessage; |
285 |
private javax.swing.JButton jButtonAddJar; |
323 |
private javax.swing.JButton jButtonAddJar; |
286 |
private javax.swing.JButton jButtonAddLib; |
324 |
private javax.swing.JButton jButtonAddLib; |
Lines 296-308
Link Here
|
296 |
private javax.swing.JTextField jTextFieldExContent; |
334 |
private javax.swing.JTextField jTextFieldExContent; |
297 |
private javax.swing.JTextField jTextFieldFileName; |
335 |
private javax.swing.JTextField jTextFieldFileName; |
298 |
// End of variables declaration//GEN-END:variables |
336 |
// End of variables declaration//GEN-END:variables |
299 |
|
337 |
|
300 |
/** Help context where to find more about the paste type action. |
338 |
/** Help context where to find more about the paste type action. |
301 |
* @return the help context for this action |
339 |
* @return the help context for this action |
302 |
*/ |
340 |
*/ |
303 |
public HelpCtx getHelpCtx() { |
341 |
public HelpCtx getHelpCtx() { |
304 |
return new HelpCtx(CustomizerWar.class); |
342 |
return new HelpCtx(CustomizerWar.class); |
305 |
} |
343 |
} |
|
|
344 |
|
345 |
private void checkValidWarFilename(){ |
346 |
MessageUtils.clear(errorLabel); |
347 |
category.setValid(true); |
348 |
|
349 |
String filename=jTextFieldFileName.getText(); |
350 |
String pattern; |
351 |
String forbiddenChars; |
352 |
if (Utilities.isWindows()) { |
353 |
pattern = ".*[\\/:*?\"<>|].*"; // NOI18N |
354 |
forbiddenChars = "\\ / : * ? \" < > |"; // NOI18N |
355 |
} else { |
356 |
pattern = ".*[\\/].*"; // NOI18N |
357 |
forbiddenChars = "\\ /"; // NOI18N |
358 |
} |
359 |
String message=null; |
360 |
if (filename.trim().length() == 0) { |
361 |
message = NbBundle.getMessage(CustomizerWar.class, "MSG_EmptyWarName"); |
362 |
}else if (Pattern.matches(pattern, filename)) { |
363 |
message = NbBundle.getMessage(CustomizerWar.class, "MSG_ForbiddenCharactersInWarName"); |
364 |
message=MessageFormat.format(message, forbiddenChars); |
365 |
} |
366 |
if(message != null){ |
367 |
category.setValid(false); |
368 |
MessageUtils.setMessage(errorLabel, MessageUtils.MessageType.ERROR, "<html>"+message+"</html>"); // NOI18N |
369 |
} |
370 |
} |
306 |
|
371 |
|
307 |
public void tableChanged(TableModelEvent e) { |
372 |
public void tableChanged(TableModelEvent e) { |
308 |
if (e.getColumn() != 1) { |
373 |
if (e.getColumn() != 1) { |
Lines 316-334
Link Here
|
316 |
if (newPathInWar.equals("WEB-INF\\lib") || newPathInWar.equals("WEB-INF/lib")) { //NOI18N |
381 |
if (newPathInWar.equals("WEB-INF\\lib") || newPathInWar.equals("WEB-INF/lib")) { //NOI18N |
317 |
if (cpItem.getResolvedFile().isDirectory()) { |
382 |
if (cpItem.getResolvedFile().isDirectory()) { |
318 |
message = NbBundle.getMessage(CustomizerWar.class, |
383 |
message = NbBundle.getMessage(CustomizerWar.class, |
319 |
"MSG_NO_FOLDER_IN_WEBINF_LIB", newPathInWar); // NOI18N |
384 |
"MSG_NO_FOLDER_IN_WEBINF_LIB", newPathInWar); // NOI18N |
320 |
} else { |
385 |
} else { |
321 |
message = NbBundle.getMessage(CustomizerWar.class, |
386 |
message = NbBundle.getMessage(CustomizerWar.class, |
322 |
"MSG_NO_FILE_IN_WEBINF_LIB", newPathInWar); // NOI18N |
387 |
"MSG_NO_FILE_IN_WEBINF_LIB", newPathInWar); // NOI18N |
323 |
} |
388 |
} |
324 |
} else if (newPathInWar.equals("WEB-INF\\classes") || newPathInWar.equals("WEB-INF/classes")) { //NOI18N |
389 |
} else if (newPathInWar.equals("WEB-INF\\classes") || newPathInWar.equals("WEB-INF/classes")) { //NOI18N |
325 |
message = NbBundle.getMessage(CustomizerWar.class, |
390 |
message = NbBundle.getMessage(CustomizerWar.class, |
326 |
"MSG_NO_FOLDER_IN_WEBINF_CLASSES", newPathInWar); // NOI18N |
391 |
"MSG_NO_FOLDER_IN_WEBINF_CLASSES", newPathInWar); // NOI18N |
327 |
} |
392 |
} |
328 |
} |
393 |
} |
329 |
if (message != null) { |
394 |
if (message != null) { |
330 |
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message (message, NotifyDescriptor.WARNING_MESSAGE)); |
395 |
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(message, NotifyDescriptor.WARNING_MESSAGE)); |
331 |
} |
396 |
} |
332 |
} |
397 |
} |
333 |
|
|
|
334 |
} |
398 |
} |