// $Id$
/**
-* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
+ * Copyright (C) 2007 EDIT
+ * European Distributed Institute of Taxonomy
+ * http://www.e-taxonomy.eu
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * See LICENSE.TXT at the top of this package for the full license terms.
+ */
package eu.etaxonomy.taxeditor.io.wizard;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import eu.etaxonomy.taxeditor.store.StoreUtil;
/**
- * <p>GenericConfiguratorWizardPage class.</p>
- *
+ * <p>
+ * GenericConfiguratorWizardPage class.
+ * </p>
+ *
* @author n.hoffmann
* @created 23.06.2009
* @version 1.0
*/
public class GenericConfiguratorWizardPage extends WizardPage {
-
- private IIoConfigurator configurator;
+
+ private final IIoConfigurator configurator;
+ private final ResourceBundle resourceBundle;
/**
* @param pageName
- * @param configurator
+ * @param configurator
*/
- private GenericConfiguratorWizardPage(String pageName, IIoConfigurator configurator, String title, String description) {
+ private GenericConfiguratorWizardPage(String pageName,
+ IIoConfigurator configurator, String title, String description) {
super(pageName);
this.setTitle(title);
-
+
this.setDescription(description);
-
+
this.configurator = configurator;
+
+
+ resourceBundle = getResourceBundle(configurator);
+ }
+
+ private ResourceBundle getResourceBundle(IIoConfigurator configurator){
+ try{
+ return ResourceBundle.getBundle(configurator.getClass().getName());
+ }catch(MissingResourceException e){
+ return null;
+ }
}
/**
- * <p>Import</p>
- *
- * @param pageName a {@link java.lang.String} object.
- * @param configurator a {@link eu.etaxonomy.cdm.io.common.IIoConfigurator} object.
- * @return a {@link eu.etaxonomy.taxeditor.io.wizard.GenericConfiguratorWizardPage} object.
+ * <p>
+ * Import
+ * </p>
+ *
+ * @param pageName
+ * a {@link java.lang.String} object.
+ * @param configurator
+ * a {@link eu.etaxonomy.cdm.io.common.IIoConfigurator} object.
+ * @return a
+ * {@link eu.etaxonomy.taxeditor.io.wizard.GenericConfiguratorWizardPage}
+ * object.
*/
- public static GenericConfiguratorWizardPage Import(String pageName, IIoConfigurator configurator){
- return new GenericConfiguratorWizardPage(pageName, configurator, "Import Configuration", "Configure the import mechanism.");
+ public static GenericConfiguratorWizardPage Import(String pageName,
+ IIoConfigurator configurator) {
+ return new GenericConfiguratorWizardPage(pageName, configurator,
+ "Import Configuration", "Configure the import mechanism.");
}
-
+
/**
- * <p>Export</p>
- *
- * @param pageName a {@link java.lang.String} object.
- * @param configurator a {@link eu.etaxonomy.cdm.io.common.IIoConfigurator} object.
- * @return a {@link eu.etaxonomy.taxeditor.io.wizard.GenericConfiguratorWizardPage} object.
+ * <p>
+ * Export
+ * </p>
+ *
+ * @param pageName
+ * a {@link java.lang.String} object.
+ * @param configurator
+ * a {@link eu.etaxonomy.cdm.io.common.IIoConfigurator} object.
+ * @return a
+ * {@link eu.etaxonomy.taxeditor.io.wizard.GenericConfiguratorWizardPage}
+ * object.
*/
- public static GenericConfiguratorWizardPage Export(String pageName, IIoConfigurator configurator){
- return new GenericConfiguratorWizardPage(pageName, configurator, "Export Configuration", "Configure the export mechanism.");
+ public static GenericConfiguratorWizardPage Export(String pageName,
+ IIoConfigurator configurator) {
+ return new GenericConfiguratorWizardPage(pageName, configurator,
+ "Export Configuration", "Configure the export mechanism.");
}
-
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
+ * .Composite)
*/
/** {@inheritDoc} */
public void createControl(Composite parent) {
-
-// ScrolledComposite scrolledComposite = new ScrolledComposite(parent, SWT.H_SCROLL);
-// scrolledComposite.setLayout(new GridLayout());
-
+
+ // ScrolledComposite scrolledComposite = new ScrolledComposite(parent,
+ // SWT.H_SCROLL);
+ // scrolledComposite.setLayout(new GridLayout());
+
// TODO wrap this composite in a scrolled composite
Composite composite = new Composite(parent, SWT.NULL);
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-
+
GridLayout gridLayout = new GridLayout();
- gridLayout.numColumns = 2;
composite.setLayout(gridLayout);
-
-
+
List<Method> methods = getConfiguratorsBooleanSetMethods(configurator);
-
- for(Method method : methods){
+
+ for (Method method : methods) {
createCheckbox(composite, method, configurator);
}
-
-// scrolledComposite.setContent(composite);
-
+
+ // scrolledComposite.setContent(composite);
+
setControl(composite);
}
-
- private void createCheckbox(Composite parent, Method method, final IIoConfigurator configurator){
-
- String methodName = method.getName();
-
- final String methodNameValue = methodName.substring(3);
-
- CLabel label = new CLabel(parent, SWT.NULL);
- label.setText(methodNameValue);
-
+
+ private void createCheckbox(Composite parent, Method method,
+ final IIoConfigurator configurator) {
+
+ final String methodName = method.getName();
+
final Button checkBox = new Button(parent, SWT.CHECK);
+
+ checkBox.setText(getLabel(methodName));
// retrieve the default values and set the checkbox accordingly
- boolean defaultSelection = executeBooleanGetMethod(configurator,"is" + methodNameValue);
+ boolean defaultSelection = executeBooleanGetMethod(configurator, "is"
+ + methodName.substring(3));
checkBox.setSelection(defaultSelection);
- checkBox.addSelectionListener(new SelectionAdapter(){
+ checkBox.addSelectionListener(new SelectionAdapter() {
- /* (non-Javadoc)
- * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse
+ * .swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent e) {
- executeBooleanSetMethod(configurator, "set" + methodNameValue, checkBox.getSelection());
+ executeBooleanSetMethod(configurator, methodName,
+ checkBox.getSelection());
}
-
+
});
-
+
}
-
- private boolean executeBooleanGetMethod(IIoConfigurator configurator, String methodName){
+ private String getLabel(String methodName){
- Class<? extends IIoConfigurator> configuratorClass = configurator.getClass();
+ if(resourceBundle == null){
+ return methodName;
+ }
+ try{
+ return resourceBundle.getString(methodName);
+ }catch(MissingResourceException e){
+ return methodName;
+ }
+ }
+
+ private boolean executeBooleanGetMethod(IIoConfigurator configurator,
+ String methodName) {
+
+ Class<? extends IIoConfigurator> configuratorClass = configurator
+ .getClass();
+
boolean result = false;
-
+
Method[] methods = configuratorClass.getMethods();
-
- for(Method method : methods){
- if(!method.getName().equals(methodName)){
+
+ for (Method method : methods) {
+ if (!method.getName().equals(methodName)) {
continue;
}
-
+
try {
Object returnType = method.invoke(configurator, null);
- if(returnType.getClass().equals(Boolean.class)){
+ if (returnType.getClass().equals(Boolean.class)) {
result = ((Boolean) returnType).booleanValue();
}
-
+
break;
} catch (Exception e) {
StoreUtil.warn(this.getClass(), "Could not invoke method");
- }
+ }
}
-
-
+
return result;
}
-
- private void executeBooleanSetMethod(IIoConfigurator configurator, String methodName, boolean selected){
-
- Class<? extends IIoConfigurator> configuratorClass = configurator.getClass();
-
-
+
+ private void executeBooleanSetMethod(IIoConfigurator configurator,
+ String methodName, boolean selected) {
+
+ Class<? extends IIoConfigurator> configuratorClass = configurator
+ .getClass();
+
Method[] methods = configuratorClass.getMethods();
-
- for(Method method : methods){
- if(!method.getName().equals(methodName)){
+
+ for (Method method : methods) {
+ if (!method.getName().equals(methodName)) {
continue;
}
-
+
try {
method.invoke(configurator, selected);
-
+
break;
} catch (Exception e) {
StoreUtil.warn(this.getClass(), "Could not invoke method");
- }
+ }
}
}
-
- private List<Method> getConfiguratorsBooleanSetMethods(IIoConfigurator configurator){
+
+ private List<Method> getConfiguratorsBooleanSetMethods(
+ IIoConfigurator configurator) {
List<Method> booleanMethods = new ArrayList<Method>();
-
- Class<? extends IIoConfigurator> configuratorClass = configurator.getClass();
-
+
+ Class<? extends IIoConfigurator> configuratorClass = configurator
+ .getClass();
+
Method[] allMethods = configuratorClass.getMethods();
-
- for(Method method : allMethods){
- if(method.getName().startsWith("set")){
-
+
+ for (Method method : allMethods) {
+ if (method.getName().startsWith("set")) {
+
Class<?>[] typeList = method.getParameterTypes();
-
- if(typeList.length > 1){
- new IllegalStateException("Found a setter with parameter count > 1");
+
+ if (typeList.length > 1) {
+ new IllegalStateException(
+ "Found a setter with parameter count > 1");
}
-
- if(typeList[0].getName().equals("boolean")){
+
+ if (typeList[0].getName().equals("boolean")) {
booleanMethods.add(method);
}
}
}
-
+
return booleanMethods;
}
}