+ Added ProjectCustomizer.Category.setErrorMessage
and
+ ProjectCustomizer.Category.getErrorMessage
+ methods. With those methods client can set an error message
+ for individual categories.
+ Also the default implementation of a customizer dialog uses
+ these methods for showing a message on the bottom of
+ category views and to mark category nodes for invalid
+ categories (similar to the error message in wizards).
+
+ Added ProjectCustomizer.Category.setValid
and
+ ProjectCustomizer.Category.isValid
methods.
+ With those methods client can affect enability of the OK
+ button of the Customizer dialog.
+
pack()
method on the dialog. The resulting dialog will
* be non-modal. show()
on the dialog to make it visible. If you wnat the dialog to be
+ * Call show()
on the dialog to make it visible. If you want the dialog to be
* closed after user presses the "OK" button you have to call hide() and dispose() on it.
* (Usually in the actionPerformed(...)
method of the listener
* you provided as a parameter. In case of the click on the "Cancel" button
* the dialog will be closed automatically.
- * @param categories array of descriptions of categories to be shown in
- * the dialog.
+ * @param categories array of descriptions of categories to be shown in the
+ * dialog. Note that categories have the valid
+ * property. If any of the given categories is not valid cusomizer's
+ * OK button will be disabled until all categories become valid
+ * again.
* @param componentProvider creator of GUI components for categories in the
* customizer dialog.
* @param preselectedCategory name of one of the supplied categories or null.
@@ -65,8 +71,8 @@
String preselectedCategory,
ActionListener okOptionListener,
HelpCtx helpCtx ) {
- JPanel innerPane = createCustomizerPane( categories, componentProvider, preselectedCategory );
- Dialog dialog = CustomizerDialog.createDialog( okOptionListener, innerPane, helpCtx );
+ CustomizerPane innerPane = (CustomizerPane) createCustomizerPane( categories, componentProvider, preselectedCategory );
+ Dialog dialog = CustomizerDialog.createDialog( okOptionListener, innerPane, helpCtx, categories );
return dialog;
}
@@ -76,6 +82,11 @@
CategoryComponentProvider componentProvider,
String preselectedCategory ) {
+ CategoryWrapper catWrappers[] = new CategoryWrapper[categories.length];
+ for (int i = 0; i < categories.length; i++) {
+ Utilities.putCategoryWrapper(categories[i], new CategoryWrapper(categories[i]));
+ }
+
CategoryModel categoryModel = new CategoryModel( categories );
JPanel categoryView = new CategoryView( categoryModel );
JPanel customizerPane = new CustomizerPane( categoryView, categoryModel, componentProvider );
@@ -112,6 +123,8 @@
private String displayName;
private Image icon;
private Category[] subcategories;
+ private boolean valid;
+ private String errorMessage;
/** Private constructor. See the factory method.
*/
@@ -124,6 +137,7 @@
this.displayName = displayName;
this.icon = icon;
this.subcategories = subcategories;
+ this.valid = true; // default
}
/** Factory method which creates new category description.
@@ -170,6 +184,53 @@
public Category[] getSubcategories() {
return this.subcategories;
}
+
+ /**
+ * Returns an error message for this category.
+ */
+ public String getErrorMessage() {
+ return errorMessage;
+ }
+
+ /**
+ * Returns whether this category is valid or not. See {@link
+ * ProjectCustomizer#createCustomizerDialog} for more details.
+ * @return whether this category is valid or not (true by default)
+ */
+ public boolean isValid() {
+ return valid;
+ }
+
+ /**
+ * Set a validity of this category. See {@link
+ * ProjectCustomizer#createCustomizerDialog} for more details.
+ * @param valid set whether this category is valid or not
+ */
+ public void setValid(boolean valid) {
+ if (this.valid != valid) {
+ this.valid = valid;
+ Utilities.getCategoryWrapper(this).firePropertyChange(
+ CategoryWrapper.VALID_PROPERTY, Boolean.valueOf(!valid), Boolean.valueOf(valid));
+;
+ }
+ }
+
+ /**
+ * Set an errror message for this category. It can than be shown in the
+ * customizer.
+ */
+ public void setErrorMessage(String message) {
+ if (message == null) {
+ message = "";
+ }
+ if (!message.equals(this.errorMessage)) {
+ String oldMessage = this.errorMessage;
+ this.errorMessage = message;
+ Utilities.getCategoryWrapper(this).firePropertyChange(
+ CategoryWrapper.ERROR_MESSAGE_PROPERTY, oldMessage, message);
+ }
+ }
+
}
}