From: Patric Plitzner Date: Thu, 11 Jul 2013 12:17:29 +0000 (+0000) Subject: merge-update from trunk X-Git-Tag: 3.6.0~968^2~11 X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/commitdiff_plain/c8b2e7f8160ec6aa56c959fb1928ea7d6ccbb285 merge-update from trunk --- diff --git a/eu.etaxonomy.taxeditor.cdmlib/.classpath b/eu.etaxonomy.taxeditor.cdmlib/.classpath index 4e06f1f76..0cb8793aa 100644 --- a/eu.etaxonomy.taxeditor.cdmlib/.classpath +++ b/eu.etaxonomy.taxeditor.cdmlib/.classpath @@ -25,23 +25,22 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/GenericConfiguratorWizardPage.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/GenericConfiguratorWizardPage.java index e796f5482..9505f4d00 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/GenericConfiguratorWizardPage.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/GenericConfiguratorWizardPage.java @@ -1,9 +1,9 @@ // $Id$ /** * Copyright (C) 2007 EDIT - * European Distributed Institute of Taxonomy + * 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. */ @@ -16,6 +16,7 @@ import java.util.List; import java.util.MissingResourceException; import java.util.ResourceBundle; +import org.apache.commons.lang.StringUtils; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; @@ -26,239 +27,246 @@ import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import eu.etaxonomy.cdm.io.common.IIoConfigurator; +import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator; import eu.etaxonomy.taxeditor.store.StoreUtil; /** *

* GenericConfiguratorWizardPage class. *

- * + * * @author n.hoffmann * @created 23.06.2009 * @version 1.0 */ public class GenericConfiguratorWizardPage extends WizardPage { - private final IIoConfigurator configurator; - private final ResourceBundle resourceBundle; - - /** - * @param pageName - * @param configurator - */ - 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; - } - } - - /** - *

- * Import - *

- * - * @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."); - } - - /** - *

- * Export - *

- * - * @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."); - } - - /* - * (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()); - - // 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(); - composite.setLayout(gridLayout); - - List methods = getConfiguratorsBooleanSetMethods(configurator); - - for (Method method : methods) { - createCheckbox(composite, method, configurator); - } - - // scrolledComposite.setContent(composite); - - setControl(composite); - } - - 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" - + methodName.substring(3)); - checkBox.setSelection(defaultSelection); - checkBox.addSelectionListener(new SelectionAdapter() { - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse - * .swt.events.SelectionEvent) - */ - @Override - public void widgetSelected(SelectionEvent e) { - executeBooleanSetMethod(configurator, methodName, - checkBox.getSelection()); - } - - }); - - } - - private String getLabel(String methodName){ - - if(resourceBundle == null){ - return methodName; - } - - try{ - return resourceBundle.getString(methodName); - }catch(MissingResourceException e){ - return methodName; - } - } - - private boolean executeBooleanGetMethod(IIoConfigurator configurator, - String methodName) { - - Class configuratorClass = configurator - .getClass(); - - boolean result = false; - - Method[] methods = configuratorClass.getMethods(); - - for (Method method : methods) { - if (!method.getName().equals(methodName)) { - continue; - } - - try { - Object returnType = method.invoke(configurator, null); - 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 configuratorClass = configurator - .getClass(); - - Method[] methods = configuratorClass.getMethods(); - - 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 getConfiguratorsBooleanSetMethods( - IIoConfigurator configurator) { - List booleanMethods = new ArrayList(); - - Class configuratorClass = configurator - .getClass(); - - Method[] allMethods = configuratorClass.getMethods(); - - 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[0].getName().equals("boolean")) { - booleanMethods.add(method); - } - } - } - - return booleanMethods; - } + private final IIoConfigurator configurator; + private final ResourceBundle resourceBundle; + + /** + * @param pageName + * @param configurator + */ + 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; + } + } + + /** + *

+ * Import + *

+ * + * @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."); + } + + /** + *

+ * Export + *

+ * + * @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."); + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets + * .Composite) + */ + /** {@inheritDoc} */ + @Override + public void createControl(Composite parent) { + + // 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(); + composite.setLayout(gridLayout); + + List methods = getConfiguratorsBooleanSetMethods(configurator); + + for (Method method : methods) { + createCheckbox(composite, method, configurator); + } + + // scrolledComposite.setContent(composite); + + setControl(composite); + } + + private void createCheckbox(Composite parent, Method method, + final IIoConfigurator configurator) { + + final String methodName = method.getName(); + final Button checkBox = new Button(parent, SWT.CHECK); + + if(configurator.getClass().equals(Abcd206ImportConfigurator.class)){ + String[] r = methodName.split("set")[1].split("(?=\\p{Upper})"); + checkBox.setText(getLabel(StringUtils.join(r," "))); + } + else{ + checkBox.setText(getLabel(methodName)); + } + // retrieve the default values and set the checkbox accordingly + boolean defaultSelection = executeBooleanGetMethod(configurator, "is" + + methodName.substring(3)); + checkBox.setSelection(defaultSelection); + checkBox.addSelectionListener(new SelectionAdapter() { + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse + * .swt.events.SelectionEvent) + */ + @Override + public void widgetSelected(SelectionEvent e) { + executeBooleanSetMethod(configurator, methodName, + checkBox.getSelection()); + } + + }); + + } + + private String getLabel(String methodName){ + + if(resourceBundle == null){ + return methodName; + } + + try{ + return resourceBundle.getString(methodName); + }catch(MissingResourceException e){ + return methodName; + } + } + + private boolean executeBooleanGetMethod(IIoConfigurator configurator, + String methodName) { + + Class configuratorClass = configurator + .getClass(); + + boolean result = false; + + Method[] methods = configuratorClass.getMethods(); + + for (Method method : methods) { + if (!method.getName().equals(methodName)) { + continue; + } + + try { + Object returnType = method.invoke(configurator, null); + 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 configuratorClass = configurator + .getClass(); + + Method[] methods = configuratorClass.getMethods(); + + 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 getConfiguratorsBooleanSetMethods( + IIoConfigurator configurator) { + List booleanMethods = new ArrayList(); + + Class configuratorClass = configurator + .getClass(); + + Method[] allMethods = configuratorClass.getMethods(); + + 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[0].getName().equals("boolean")) { + booleanMethods.add(method); + } + } + } + + return booleanMethods; + } }