eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/AbstractCdmFormElement.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/AbstractCdmFormElementComposite.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/AbstractCdmFormElementWithErrors.java -text
-eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/AbstractEntityCollectionElementComposite.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/AbstractFormSection.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/BrowserElement.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmElementFactory.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/AbstractCdmDetailElementComposite.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/AbstractCdmDetailSection.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/AbstractEntityCollectionElement.java -text
+eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/AbstractEntityCollectionElementComposite.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/AbstractEntityCollectionSection.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/AbstractIdentifiableEntityDetailElement.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/EmptyElement.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/TypeDesignationSection.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/AbstractDeterminationEventDetailSection.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/AbstractEventDetailElement.java -text
+eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/AbstractEventDetailElementComposite.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/CollectingAreasDetailSection.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/CollectionDetailElement.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/CollectionWizardPage.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/DeterminationDetailElement.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/DeterminationDetailSection.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/DeterminationEventDetailElement.java -text
+eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/DeterminationEventDetailElementComposite.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/DeterminationHistoryDetailSection.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/FieldObservationDetailElement.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/FieldObservationDetailSection.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/TermVocabularyDetailSection.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/selection/EditFromSelectionWizard.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/selection/EntitySelectionElement.java -text
+eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/selection/EntitySelectionElementComposite.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/selection/NomenclaturalAuthorTeamSelectionElement.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/selection/TaxonNodeSelectionElement.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/translation/GoogleLanguageApiWrapper.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/reporting/ReportingViewPart.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/supplementaldata/SupplementalDataViewPart.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/supplementaldata/SupplementalDataViewer.java -text
+eu.etaxonomy.taxeditor.store/src/main/java/org/eclipse/wb/swt/ResourceManager.java -text
eu.etaxonomy.taxeditor.store/src/main/java/org/eclipse/wb/swt/SWTResourceManager.java -text
eu.etaxonomy.taxeditor.store/src/main/resources/eu/etaxonomy/cdm/editorApplicationContext.xml -text
eu.etaxonomy.taxeditor.store/src/main/resources/log4j.properties -text
import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.forms.widgets.TableWrapLayout;
+import org.eclipse.wb.swt.SWTResourceManager;
import eu.etaxonomy.taxeditor.model.AbstractUtility;
*/
public AbstractCdmFormElementComposite(Composite parent, final FormToolkit formFactory, ICdmFormElement parentFormElement, int style) {
super(parent, style);
+ setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
this.parentElement = parentFormElement;
if(formFactory instanceof CdmFormFactory){
this.formFactory = (CdmFormFactory) formFactory;
}
+ //TODO what to do when not instance of CdmFormFactory
TableWrapLayout twl_layoutComposite = new TableWrapLayout();
twl_layoutComposite.numColumns = 2;
+++ /dev/null
-package eu.etaxonomy.taxeditor.ui.element;
-
-import org.eclipse.jface.resource.ResourceManager;
-import org.eclipse.jface.util.PropertyChangeEvent;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Layout;
-import org.eclipse.ui.forms.widgets.FormToolkit;
-import org.eclipse.ui.forms.widgets.TableWrapLayout;
-
-import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
-import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
-import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
-
-public abstract class AbstractEntityCollectionElementComposite<ENTITY>
- extends AbstractCdmFormElementComposite
- implements IEntityElement<ENTITY>, SelectionListener, IConversationEnabled {
-
- protected ENTITY entity;
-
- private final Composite container;
-
- private final Composite box;
-
- private final Button button_remove;
-
- private Color backgroundColor;
-
- /**
- * Create the composite.
- *
- * @param parent
- * @param style
- */
- public AbstractEntityCollectionElementComposite(Composite parent, ICdmFormElement parentFormElement, FormToolkit formFactory, ENTITY entity, SelectionListener removeListener, int style) {
- super(parent, parentFormElement, style);
-
- box = formFactory.createComposite(parent);
- box.setBackgroundMode(SWT.INHERIT_DEFAULT);
- addControl(box);
-
- TableWrapLayout boxLayout = LayoutConstants.LAYOUT(2, false);
- boxLayout.topMargin = 4;
- boxLayout.bottomMargin = 4;
- box.setLayout(boxLayout);
-
- box.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
-
- container = formFactory.createComposite(box);
- container.setBackgroundMode(SWT.INHERIT_DEFAULT);
-
- setLayoutComposite(container);
-
- addControl(container);
- Layout containerLayout = LayoutConstants.LAYOUT(2, false);
-
- container.setLayout(containerLayout);
- container.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
-
- // if (removeListener != null) {
- button_remove = formFactory.createButton(box, null, SWT.PUSH);
- addControl(button_remove);
- button_remove.setLayoutData(LayoutConstants.RIGHT());
- button_remove.setImage(ResourceManager.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/trash.gif"));
- button_remove.setToolTipText("Remove");
-// button_remove.addSelectionListener(removeListener);
- // }
-
- createControls(this, style);
- setEntity(entity);
-
- }
-
- /**
- * Init gets executed before any other setup of the section takes place
- *
- * Implement this if you want to configure the section
- */
- public void init() {
- // default implementation is empty
- }
-
- /**
- * <p>
- * Setter for the field <code>entity</code>.
- * </p>
- *
- * @param entity
- * a ENTITY object.
- */
- public abstract void setEntity(ENTITY entity);
-
- /**
- * <p>
- * Getter for the field <code>entity</code>.
- * </p>
- *
- * @return a ENTITY object.
- */
- @Override
- public ENTITY getEntity() {
- return entity;
- }
-
- /**
- * <p>
- * createControls
- * </p>
- *
- * @param element
- * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
- * object.
- * @param style
- * a int.
- */
- public abstract void createControls(ICdmFormElement element, int style);
-
- /**
- * Mark <code>this</code> element as selected.
- */
- @Override
- public void setSelected(boolean selected) {
-
- for (ICdmFormElement element : getElements()) {
- if (element instanceof ISelectable) {
- ((ISelectable) element).setSelected(selected);
- }
- }
- setBackground(selected ? SELECTED : getPersistentBackground());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#propertyChange(org
- * .eclipse.jface.util.PropertyChangeEvent)
- */
- /** {@inheritDoc} */
- @Override
- public void propertyChange(PropertyChangeEvent event) {
- if (event == null) {
- return;
- }
- Object eventSource = event.getSource();
- if (getElements().contains(eventSource)) {
- handleEvent(eventSource);
- }
- }
-
- /**
- * <p>
- * handleEvent
- * </p>
- *
- * @param eventSource
- * a {@link java.lang.Object} object.
- */
- public abstract void handleEvent(Object eventSource);
-
- /** {@inheritDoc} */
- @Override
- public void setBackground(Color color) {
- backgroundColor = color;
- super.setBackground(backgroundColor);
- box.setBackground(backgroundColor);
- container.setBackground(backgroundColor);
- }
-
- /**
- * {@inheritDoc}
- *
- * React when selection occurs
- */
- @Override
- public void widgetSelected(SelectionEvent e) {
-
- }
-
- /** {@inheritDoc} */
- @Override
- public void widgetDefaultSelected(SelectionEvent e) {
- }
-
- /** {@inheritDoc} */
- @Override
- public Composite getLayoutComposite() {
- return container;
- }
-
- /**
- * <p>
- * Getter for the field <code>backgroundColor</code>.
- * </p>
- *
- * @return the backgroundColor
- */
- public Color getBackgroundColor() {
- return backgroundColor;
- }
-
- /**
- * <p>
- * getConversationHolder
- * </p>
- *
- * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
- * object.
- */
- @Override
- public ConversationHolder getConversationHolder() {
- if (getParentElement() instanceof IConversationEnabled) {
- return ((IConversationEnabled) getParentElement())
- .getConversationHolder();
- }
- throw new IllegalArgumentException(
- "Parent element should be IConversationEnabled");
- }
-
- /** {@inheritDoc} */
- @Override
- public void update(CdmDataChangeMap changeEvents) {
- }
-
-}
package eu.etaxonomy.taxeditor.ui.element;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.forms.widgets.FormToolkit;
+import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElementComposite;
+import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.model.common.ICdmBase;
public final class CdmElementFactory {
/**
CdmTextField cdmNumberField = new CdmTextField(parent, formFactory, parentFormElement, initialText, textHeight, style);
return cdmNumberField;
}
+ /**
+ * @wbp.factory
+ * @wbp.factory.parameter.source formFactory formFactory
+ * @wbp.factory.parameter.source conversation getConversationHolder()
+ * @wbp.factory.parameter.source parentElement element
+ * @wbp.factory.parameter.source clazz eu.etaxonomy.cdm.model.taxon.TaxonBase.class
+ * @wbp.factory.parameter.source labelString "Taxon"
+ * @wbp.factory.parameter.source entity (eu.etaxonomy.cdm.model.taxon.TaxonBase) null
+ * @wbp.factory.parameter.source mode eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElementComposite.NOTHING
+ * @wbp.factory.parameter.source style style
+ */
+ public static EntitySelectionElementComposite createEntitySelectionElementComposite(Composite parent, FormToolkit formFactory, ConversationHolder conversation, ICdmFormElement parentElement, Class clazz, String labelString, ICdmBase entity, int mode, int style) {
+ EntitySelectionElementComposite entitySelectionElementComposite = new EntitySelectionElementComposite(parent, formFactory, conversation, parentElement, clazz, labelString, entity, mode, style);
+ return entitySelectionElementComposite;
+ }
}
\ No newline at end of file
import eu.etaxonomy.taxeditor.ui.section.occurrence.DeterminationDetailElement;
import eu.etaxonomy.taxeditor.ui.section.occurrence.DeterminationDetailSection;
import eu.etaxonomy.taxeditor.ui.section.occurrence.DeterminationEventDetailElement;
+import eu.etaxonomy.taxeditor.ui.section.occurrence.DeterminationEventDetailElementComposite;
import eu.etaxonomy.taxeditor.ui.section.occurrence.DeterminationHistoryDetailSection;
import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldObservationDetailElement;
import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldObservationDetailSection;
} else if (entity instanceof NamedArea) {
element = new NamedAreaDetailElement(this, parentElement, (NamedArea) entity, removeListener, style);
} else if (entity instanceof DeterminationEvent) {
- element = new DeterminationEventDetailElement(this, parentElement, (DeterminationEvent) entity,
- removeListener, style);
+ element = new DeterminationEventDetailElement(this, parentElement, (DeterminationEvent) entity, removeListener, style);
} else if (entity instanceof Specimen) {
element = new SpecimenCollectionDetailElement(this, parentElement, (Specimen) entity, removeListener, style);
} else if (entity instanceof User) {
else if (backgroundColor != null && !backgroundColor.isDisposed()) {
element.setPersistentBackground(backgroundColor);
+ adapt(element);
+ parentElement.addElement(element);
}
+ return element;
+ }
+
+ public DeterminationEventDetailElementComposite createDeterminationEventDetailElementComposite(AbstractFormSection parentElement,
+ Object versionableEntity, SelectionListener removeListener, Color backgroundColor, int style){
+ Object entity = HibernateProxyHelper.deproxy(versionableEntity);
+ DeterminationEventDetailElementComposite element = new DeterminationEventDetailElementComposite(parentElement.getLayoutComposite(), this, parentElement, (DeterminationEvent) entity,
+ removeListener, style);
adapt(element);
parentElement.addElement(element);
return element;
// $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.
*/
* <p>
* Abstract AbstractEntityCollectionElement class.
* </p>
- *
+ *
* @author n.hoffmann
* @created Nov 16, 2009
* @version 1.0
protected ENTITY entity;
- private Composite container;
+ private final Composite container;
- private Composite box;
+ private final Composite box;
private Button button_remove;
* <p>
* Constructor for AbstractEntityCollectionElement.
* </p>
- *
+ *
* @param style
* a int.
* @param formFactory
/**
* Init gets executed before any other setup of the section takes place
- *
+ *
* Implement this if you want to configure the section
*/
public void init() {
* <p>
* Setter for the field <code>entity</code>.
* </p>
- *
+ *
* @param entity
* a ENTITY object.
*/
* <p>
* Getter for the field <code>entity</code>.
* </p>
- *
+ *
* @return a ENTITY object.
*/
- public ENTITY getEntity() {
+ @Override
+ public ENTITY getEntity() {
return entity;
}
* <p>
* createControls
* </p>
- *
+ *
* @param element
* a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
* object.
/**
* Mark <code>this</code> element as selected.
*/
- public void setSelected(boolean selected) {
+ @Override
+ public void setSelected(boolean selected) {
for (ICdmFormElement element : getElements()) {
if (element instanceof ISelectable) {
/*
* (non-Javadoc)
- *
+ *
* @see
* eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#propertyChange(org
* .eclipse.jface.util.PropertyChangeEvent)
* <p>
* handleEvent
* </p>
- *
+ *
* @param eventSource
* a {@link java.lang.Object} object.
*/
public abstract void handleEvent(Object eventSource);
/** {@inheritDoc} */
- public void setBackground(Color color) {
+ @Override
+ public void setBackground(Color color) {
backgroundColor = color;
super.setBackground(color);
box.setBackground(color);
/**
* {@inheritDoc}
- *
+ *
* React when selection occurs
*/
- public void widgetSelected(SelectionEvent e) {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
}
/** {@inheritDoc} */
- public void widgetDefaultSelected(SelectionEvent e) {
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
}
/** {@inheritDoc} */
* <p>
* Getter for the field <code>backgroundColor</code>.
* </p>
- *
+ *
* @return the backgroundColor
*/
public Color getBackgroundColor() {
* <p>
* getConversationHolder
* </p>
- *
+ *
* @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
* object.
*/
- public ConversationHolder getConversationHolder() {
+ @Override
+ public ConversationHolder getConversationHolder() {
if (getParentElement() instanceof IConversationEnabled) {
return ((IConversationEnabled) getParentElement())
.getConversationHolder();
}
/** {@inheritDoc} */
- public void update(CdmDataChangeMap changeEvents) {
+ @Override
+ public void update(CdmDataChangeMap changeEvents) {
}
}
--- /dev/null
+// $Id$
+/**
+ * Copyright (C) 2013 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.ui.section;
+
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Layout;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.TableWrapLayout;
+import org.eclipse.wb.swt.ResourceManager;
+import org.eclipse.wb.swt.SWTResourceManager;
+
+import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
+import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
+import eu.etaxonomy.taxeditor.ui.element.AbstractCdmFormElementComposite;
+import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
+import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.element.IEntityElement;
+import eu.etaxonomy.taxeditor.ui.element.ISelectable;
+import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
+
+/**
+ * @author pplitzner
+ * @date 02.08.2013
+ *
+ */
+public abstract class AbstractEntityCollectionElementComposite<ENTITY> extends AbstractCdmFormElementComposite implements IEntityElement<ENTITY>, SelectionListener, IConversationEnabled {
+
+ protected ENTITY entity;
+
+ private final Composite container;
+
+// private final Composite box;
+
+ private final Button btnRstre;
+
+ private Color backgroundColor;
+
+ /**
+ * <p>
+ * Constructor for AbstractEntityCollectionElement.
+ * </p>
+ *
+ * @param style
+ * a int.
+ * @param formFactory
+ * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
+ * object.
+ * @param section
+ * a
+ * {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
+ * object.
+ * @param entity
+ * a ENTITY object.
+ * @param removeListener
+ * a {@link org.eclipse.swt.events.SelectionListener} object.
+ * @param <ENTITY>
+ * a ENTITY object.
+ */
+ public AbstractEntityCollectionElementComposite(Composite parent, FormToolkit formFactory, ICdmFormElement parentFormElement, ENTITY entity, SelectionListener removeListener, Color backgroundColor, int style) {
+ super(parent, formFactory, parentFormElement, style);
+ setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
+
+ init();
+
+ if(formFactory instanceof CdmFormFactory){
+ ((CdmFormFactory) formFactory).addPropertyChangeListener(this);
+ }
+
+ // section.getLayoutComposite().setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_CYAN));
+
+// box = formFactory.createComposite(this);
+ this.setBackgroundMode(SWT.INHERIT_DEFAULT);
+ addControl(this);
+
+ TableWrapLayout boxLayout = LayoutConstants.LAYOUT(2, false);
+ boxLayout.topMargin = 4;
+ boxLayout.bottomMargin = 4;
+ this.setLayout(boxLayout);
+
+ this.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
+
+ // box.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
+
+ container = formFactory.createComposite(this);
+ container.setBackgroundMode(SWT.INHERIT_DEFAULT);
+
+ // container.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
+ setLayoutComposite(container);
+
+ addControl(container);
+ Layout containerLayout = LayoutConstants.LAYOUT(2, false);
+
+ container.setLayout(containerLayout);
+ container.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
+
+ btnRstre = formFactory.createButton(this, null, SWT.PUSH);
+ addControl(btnRstre);
+ btnRstre.setLayoutData(LayoutConstants.RIGHT());
+ btnRstre.setImage(ResourceManager.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/trash.gif"));
+ btnRstre.setToolTipText("Remove");
+
+ if (removeListener != null) {
+ btnRstre.addSelectionListener(removeListener);
+ }
+
+ createControls(this, style);
+
+ setEntity(entity);
+ }
+
+ /**
+ * Init gets executed before any other setup of the section takes place
+ *
+ * Implement this if you want to configure the section
+ */
+ public void init() {
+ // default implementation is empty
+ }
+
+ /**
+ * <p>
+ * Setter for the field <code>entity</code>.
+ * </p>
+ *
+ * @param entity
+ * a ENTITY object.
+ */
+ public abstract void setEntity(ENTITY entity);
+
+ /**
+ * <p>
+ * Getter for the field <code>entity</code>.
+ * </p>
+ *
+ * @return a ENTITY object.
+ */
+ @Override
+ public ENTITY getEntity() {
+ return entity;
+ }
+
+ /**
+ * <p>
+ * createControls
+ * </p>
+ *
+ * @param element
+ * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
+ * object.
+ * @param style
+ * a int.
+ */
+ public abstract void createControls(ICdmFormElement element, int style);
+
+ /**
+ * Mark <code>this</code> element as selected.
+ */
+ @Override
+ public void setSelected(boolean selected) {
+
+ for (ICdmFormElement element : getElements()) {
+ if (element instanceof ISelectable) {
+ ((ISelectable) element).setSelected(selected);
+ }
+ }
+ setBackground(selected ? SELECTED : getPersistentBackground());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#propertyChange(org
+ * .eclipse.jface.util.PropertyChangeEvent)
+ */
+ /** {@inheritDoc} */
+ @Override
+ public void propertyChange(PropertyChangeEvent event) {
+ if (event == null) {
+ return;
+ }
+ Object eventSource = event.getSource();
+ if (getElements().contains(eventSource)) {
+ handleEvent(eventSource);
+ }
+ }
+
+ /**
+ * <p>
+ * handleEvent
+ * </p>
+ *
+ * @param eventSource
+ * a {@link java.lang.Object} object.
+ */
+ public abstract void handleEvent(Object eventSource);
+
+ /** {@inheritDoc} */
+ @Override
+ public void setBackground(Color color) {
+ if(color!=null){
+ backgroundColor = color;
+ super.setBackground(color);
+// box.setBackground(color);
+// container.setBackground(color);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * React when selection occurs
+ */
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public Composite getLayoutComposite() {
+ return container;
+ }
+
+ /**
+ * <p>
+ * Getter for the field <code>backgroundColor</code>.
+ * </p>
+ *
+ * @return the backgroundColor
+ */
+ public Color getBackgroundColor() {
+ return backgroundColor;
+ }
+
+ /**
+ * <p>
+ * getConversationHolder
+ * </p>
+ *
+ * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
+ * object.
+ */
+ @Override
+ public ConversationHolder getConversationHolder() {
+ if (getParentElement() instanceof IConversationEnabled) {
+ return ((IConversationEnabled) getParentElement()).getConversationHolder();
+ }
+ throw new IllegalArgumentException("Parent element should be IConversationEnabled");
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void update(CdmDataChangeMap changeEvents) {
+ }
+}
}
/**
- * Remove an element from the entities collection and update the section
+ * Remove an element from the entities collection and update the section
*
* @param element a ELEMENT object.
*/
removeElement(element);
internalUpdateSection(true);
}
-
+
/**
* Get the specific collection of this entity
*
// $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.
*/
package eu.etaxonomy.taxeditor.ui.section.occurrence;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Color;
+
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
return "No determinations yet.";
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#createElementComposite(java.lang.Object, org.eclipse.swt.events.SelectionListener, org.eclipse.swt.graphics.Color)
+ */
+ @Override
+ protected void createElementComposite(DeterminationEvent element, SelectionListener removeListener, Color backgroundColor) {
+ formFactory.createDeterminationEventDetailElementComposite(this, element, removeListener, backgroundColor, SWT.NULL);
+ }
+
}
--- /dev/null
+// $Id$
+/**
+ * Copyright (C) 2013 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.ui.section.occurrence;
+
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+
+import eu.etaxonomy.cdm.model.agent.AgentBase;
+import eu.etaxonomy.cdm.model.common.EventBase;
+import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
+import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
+import eu.etaxonomy.taxeditor.ui.element.TimePeriodElement;
+import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElementComposite;
+import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
+
+/**
+ * @author pplitzner
+ * @date 02.08.2013
+ *
+ */
+public abstract class AbstractEventDetailElementComposite<T extends EventBase> extends AbstractEntityCollectionElementComposite<T> {
+
+ protected EntitySelectionElement<AgentBase> selection_agent;
+ protected TextWithLabelElement text_description;
+ protected TimePeriodElement element_timePeriod;
+
+ /**
+ * <p>
+ * Constructor for AbstractEventDetailElement.
+ * </p>
+ *
+ * @param formFactory
+ * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
+ * object.
+ * @param section
+ * a
+ * {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
+ * object.
+ * @param entity
+ * a T object.
+ * @param removeListener
+ * a {@link org.eclipse.swt.events.SelectionListener} object.
+ * @param style
+ * a int.
+ * @param <T>
+ * a T object.
+ */
+ public AbstractEventDetailElementComposite(Composite parent, FormToolkit formFactory, AbstractFormSection section, T entity, SelectionListener removeListener, int style) {
+ super(parent, formFactory, section, entity, removeListener, null, style);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * eu.etaxonomy.taxeditor.section.AbstractEntityCollectionElement#setEntity
+ * (java.lang.Object)
+ */
+ /** {@inheritDoc} */
+ @Override
+ public void setEntity(T entity) {
+ if(entity!=null){
+ selection_agent.setEntity(entity.getActor());
+ text_description.setText(entity.getDescription());
+ element_timePeriod.setEntity(entity.getTimeperiod());
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * eu.etaxonomy.taxeditor.section.AbstractEntityCollectionElement#createControls
+ * (eu.etaxonomy.taxeditor.forms.ICdmFormElement, int)
+ */
+ /** {@inheritDoc} */
+ @Override
+ public void createControls(ICdmFormElement element, int style) {
+ selection_agent = formFactory.createSelectionElement(AgentBase.class, getConversationHolder(), element, "Actor", null, EntitySelectionElement.ALL, style);
+ element_timePeriod = formFactory.createTimePeriodElement(element, "Time Period", null, style);
+ text_description = formFactory.createTextWithLabelElement(element, "Description", null, style);
+ }
+
+}
// $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.
*/
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
/**
- * <p>CollectingAreasDetailSection class.</p>
+ * <p>
+ * CollectingAreasDetailSection class.
+ * </p>
*
* @author n.hoffmann
* @created Oct 14, 2010
* @version 1.0
*/
-public class CollectingAreasDetailSection extends
- AbstractEntityCollectionSection<DerivedUnitFacade, NamedArea> {
+public class CollectingAreasDetailSection extends AbstractEntityCollectionSection<DerivedUnitFacade, NamedArea> {
/**
* <p>Constructor for CollectingAreasDetailSection.</p>
@Override
public NamedArea createNewElement() {
NamedArea selection = NamedAreaSelectionDialog.select(getLayoutComposite().getShell(), getConversationHolder(), null);
-
+
return selection;
}
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
-import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
+import eu.etaxonomy.taxeditor.ui.section.ICdmDetailElement;
/**
* @author n.hoffmann
* @see eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection#createCdmDetailElement(eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection, int)
*/
@Override
- protected AbstractCdmDetailElement<DerivedUnitFacade> createCdmDetailElement(AbstractCdmDetailSection<DerivedUnitFacade> parentElement, int style) {
+ protected ICdmDetailElement<DerivedUnitFacade> createCdmDetailElement(AbstractCdmDetailSection<DerivedUnitFacade> parentElement, int style) {
return formFactory.createDeterminationDetailElement(parentElement);
}
--- /dev/null
+// $Id$
+/**
+ * Copyright (C) 2013 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.ui.section.occurrence;
+
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+
+import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
+import eu.etaxonomy.cdm.model.occurrence.DeterminationModifier;
+import eu.etaxonomy.cdm.model.taxon.TaxonBase;
+import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
+import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
+import eu.etaxonomy.taxeditor.ui.element.CdmElementFactory;
+import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
+import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElementComposite;
+
+/**
+ * @author pplitzner
+ * @date 02.08.2013
+ *
+ */
+public class DeterminationEventDetailElementComposite extends AbstractEventDetailElementComposite<DeterminationEvent> {
+
+ private TermComboElement<DeterminationModifier> combo_determinationModifier;
+ private CheckboxElement checkbox_preferredFlag;
+ private EntitySelectionElementComposite<TaxonBase> selection_taxonBase;
+
+ // private TODO a set of references
+
+ /**
+ * <p>
+ * Constructor for DeterminationEventDetailElement.
+ * </p>
+ *
+ * @param formFactory
+ * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
+ * object.
+ * @param section
+ * a
+ * {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
+ * object.
+ * @param entity
+ * a {@link eu.etaxonomy.cdm.model.occurrence.DeterminationEvent}
+ * object.
+ * @param removeListener
+ * a {@link org.eclipse.swt.events.SelectionListener} object.
+ * @param style
+ * a int.
+ */
+ public DeterminationEventDetailElementComposite(Composite parent, FormToolkit formFactory, AbstractFormSection section, DeterminationEvent entity, SelectionListener removeListener, int style) {
+ super(parent, formFactory, section, entity, removeListener, style);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * eu.etaxonomy.taxeditor.section.AbstractEntityCollectionElement#setEntity
+ * (eu.etaxonomy.cdm.model.common.IVersionableEntity)
+ */
+ /** {@inheritDoc} */
+ @Override
+ public void setEntity(DeterminationEvent entity) {
+ this.entity = entity;
+ combo_determinationModifier.setSelection(entity.getModifier());
+ selection_taxonBase.setEntity(entity.getTaxon());
+ super.setEntity(entity);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * eu.etaxonomy.taxeditor.section.AbstractEntityCollectionElement#createControls
+ * (eu.etaxonomy.taxeditor.forms.ICdmFormElement, int)
+ */
+ /** {@inheritDoc} */
+ @Override
+ public void createControls(ICdmFormElement element, int style) {
+ // TODO set of references
+
+ // WindowBuilder does not support generics!! That's why they are missing here
+ selection_taxonBase = CdmElementFactory.createEntitySelectionElementComposite(this, formFactory, getConversationHolder(), element, TaxonBase.class, "Taxon", (TaxonBase) null, EntitySelectionElementComposite.NOTHING, style);
+// this.addElement(selection_taxonBase);// TODO use factory method to create and add selection_taxonBase
+
+ super.createControls(element, style);
+
+ element_timePeriod.setLabel("Determined When");
+ selection_agent.setLabel("Determined by");
+
+ combo_determinationModifier = formFactory.createTermComboElement(DeterminationModifier.class, element, "Modifier", null, style);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * eu.etaxonomy.taxeditor.section.AbstractEntityCollectionElement#handleEvent
+ * (java.lang.Object)
+ */
+ /** {@inheritDoc} */
+ @Override
+ public void handleEvent(Object eventSource) {
+ if (eventSource == combo_determinationModifier) {
+ getEntity().setModifier(combo_determinationModifier.getSelection());
+ } else if (eventSource == checkbox_preferredFlag) {
+ getEntity().setPreferredFlag(checkbox_preferredFlag.getSelection());
+ } else if (eventSource == selection_taxonBase) {
+ getEntity().setTaxon(selection_taxonBase.getSelection());
+ }
+ // else if(eventSource == TODO set of references){
+ //
+ // }
+ else if (eventSource == selection_agent) {
+ getEntity().setDeterminer(selection_agent.getSelection());
+ } else if (eventSource == text_description) {
+ getEntity().setDescription(text_description.getText());
+ } else if (eventSource == element_timePeriod) {
+ getEntity().setTimeperiod(element_timePeriod.getTimePeriod());
+ }
+ }
+
+}
- private final CdmNumberField absoluteElevationError;
- private final CdmNumberField number_absoluteElevationMinimum;
- private final CdmNumberField number_absoluteElevationMaximum;
- private final CdmTextField collectingMethod;
- private final CdmNumberField number_distanceToGround;
- private final CdmNumberField number_distanceToWaterSurface;
- private final CdmTextField gatheringEventDescription;
-// private CollectingAreasDetailSection section_collectingAreas;
+ private final CdmNumberField absoluteElevationError;
+ private final CdmNumberField number_absoluteElevationMinimum;
+ private final CdmNumberField number_absoluteElevationMaximum;
+ private final CdmTextField collectingMethod;
+ private final CdmNumberField number_distanceToGround;
+ private final CdmNumberField number_distanceToWaterSurface;
+ private final CdmTextField gatheringEventDescription;
+ private CollectingAreasDetailSection section_collectingAreas;
/**
* <p>
formFactory.adapt(lblNewLabel_4, true, true);
lblNewLabel_4.setText("Elevation Error");
- absoluteElevationError = CdmElementFactory.createCdmNumberField(this, formFactory, this, (Integer) null, 0);
+ absoluteElevationError = CdmElementFactory.createCdmNumberField(getLayoutComposite(), formFactory, this, (Integer) null, 0);
((TableWrapData) absoluteElevationError.getMainControl().getLayoutData()).grabVertical = false;
TableWrapData twd_cdmNumberField = new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP, 1, 1);
twd_cdmNumberField.grabHorizontal = true;
formFactory.adapt(lblNewLabel_3, true, true);
lblNewLabel_3.setText("Elevation Error Minumum (m)");
- number_absoluteElevationMinimum = CdmElementFactory.createCdmNumberField(this, formFactory, this, (Integer) null, 0);
+ number_absoluteElevationMinimum = CdmElementFactory.createCdmNumberField(getLayoutComposite(), formFactory, this, (Integer) null, 0);
TableWrapData tableWrapData = (TableWrapData) number_absoluteElevationMinimum.getMainControl().getLayoutData();
tableWrapData.valign = TableWrapData.TOP;
tableWrapData.grabVertical = false;
formFactory.adapt(lblNewLabel_2, true, true);
lblNewLabel_2.setText("Elevation Maximum (m)");
- number_absoluteElevationMaximum = CdmElementFactory.createCdmNumberField(this, formFactory, this, (Integer) null, 0);
+ number_absoluteElevationMaximum = CdmElementFactory.createCdmNumberField(getLayoutComposite(), formFactory, this, (Integer) null, 0);
TableWrapData twd_cdmNumberField_2 = new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP, 1, 1);
twd_cdmNumberField_2.grabHorizontal = true;
number_absoluteElevationMaximum.setLayoutData(twd_cdmNumberField_2);
formFactory.adapt(lblTestLabel, true, true);
lblTestLabel.setText("Collecting Method");
- collectingMethod = CdmElementFactory.createCdmTextField(this, formFactory, this, (String) null, (Integer) null, 0);
+ collectingMethod = CdmElementFactory.createCdmTextField(getLayoutComposite(), formFactory, this, (String) null, (Integer) null, 0);
TableWrapData twd_cdmTextField_1 = new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP, 1, 1);
twd_cdmTextField_1.grabHorizontal = true;
collectingMethod.setLayoutData(twd_cdmTextField_1);
formFactory.adapt(lblNewLabel_5, true, true);
lblNewLabel_5.setText("Distance To Ground (m)");
- number_distanceToGround = CdmElementFactory.createCdmNumberField(this, formFactory, this, (Integer) null, 0);
+ number_distanceToGround = CdmElementFactory.createCdmNumberField(getLayoutComposite(), formFactory, this, (Integer) null, 0);
TableWrapData twd_cdmNumberField_3 = new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP, 1, 1);
twd_cdmNumberField_3.grabHorizontal = true;
number_distanceToGround.setLayoutData(twd_cdmNumberField_3);
formFactory.adapt(lblNewLabel_6, true, true);
lblNewLabel_6.setText("Distance To Water Surface");
- number_distanceToWaterSurface = CdmElementFactory.createCdmNumberField(this, formFactory, this, (Integer) null, 0);
+ number_distanceToWaterSurface = CdmElementFactory.createCdmNumberField(getLayoutComposite(), formFactory, this, (Integer) null, 0);
TableWrapData twd_cdmNumberField_4 = new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP, 1, 1);
twd_cdmNumberField_4.grabHorizontal = true;
number_distanceToWaterSurface.setLayoutData(twd_cdmNumberField_4);
formFactory.adapt(lblNewLabel, true, true);
lblNewLabel.setText("Gathering Event Description");
- gatheringEventDescription = CdmElementFactory.createCdmTextField(this, formFactory, this, (String) null, (Integer) null, 0);
+ gatheringEventDescription = CdmElementFactory.createCdmTextField(getLayoutComposite(), formFactory, this, (String) null, (Integer) null, 0);
TableWrapData twd_cdmTextField_2 = new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP, 1, 1);
twd_cdmTextField_2.grabHorizontal = true;
gatheringEventDescription.setLayoutData(twd_cdmTextField_2);
number_distanceToWaterSurface.setText(String.valueOf(entity.getDistanceToWaterSurface()));
gatheringEventDescription.setText(entity.getGatheringEventDescription());
- // collectingArea
-// number_absoluteElevationError = formFactory.createIntegerTextWithLabelElement(formElement, "Elevation Error", entity.getAbsoluteElevationError(), style);
-// number_absoluteElevationMinimum = formFactory.createIntegerTextWithLabelElement(formElement, "Elevation Minimum (m)", entity.getAbsoluteElevationMinimum(), style);
-// number_absoluteElevationMaximum = formFactory.createIntegerTextWithLabelElement(formElement, "Elevation Maximum (m)", entity.getAbsoluteElevationMaximum(), style);
-
-// text_collectingMethod = formFactory.createTextWithLabelElement(formElement, "Collecting Method", entity.getCollectingMethod(), style);
-
-// number_distanceToGround = formFactory.createIntegerTextWithLabelElement(formElement, "Distance To Ground (m)", entity.getDistanceToGround(), style);
-// number_distanceToWaterSurface = formFactory.createIntegerTextWithLabelElement(formElement, "Distance To Water Surface (m)", entity.getDistanceToWaterSurface(), style);
- // exactLocation
-// text_gatheringEventDescription = formFactory.createTextWithLabelElement(formElement, "Gathering Event Description", entity.getGatheringEventDescription(), style);
-
// section_collectingAreas = formFactory.createCollectingAreasDetailSection(getConversationHolder(), formElement, ExpandableComposite.TWISTIE);
// section_collectingAreas.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
// section_collectingAreas.setEntity(entity);
--- /dev/null
+package eu.etaxonomy.taxeditor.ui.selection;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.wb.swt.ResourceManager;
+import org.eclipse.wb.swt.SWTResourceManager;
+import org.springframework.security.core.GrantedAuthority;
+
+import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
+import eu.etaxonomy.cdm.common.CdmUtils;
+import eu.etaxonomy.cdm.model.common.Group;
+import eu.etaxonomy.cdm.model.common.ICdmBase;
+import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;
+import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
+import eu.etaxonomy.taxeditor.preference.Resources;
+import eu.etaxonomy.taxeditor.ui.dialog.selection.SelectionDialogFactory;
+import eu.etaxonomy.taxeditor.ui.element.AbstractCdmFormElementComposite;
+import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
+import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
+import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement;
+import eu.etaxonomy.taxeditor.ui.element.IEntityElement;
+import eu.etaxonomy.taxeditor.ui.element.ILabeledElement;
+import eu.etaxonomy.taxeditor.ui.element.ISelectableElement;
+import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
+import eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator;
+
+/**
+ * package eu.etaxonomy.taxeditor.ui.selection;
+ *
+ * import org.eclipse.core.runtime.IStatus;
+ *
+ * /**
+ * <p>
+ * Abstract AbstractSelectionElement class.
+ * </p>
+ *
+ * @author n.hoffmann
+ * @created Nov 17, 2009
+ * @version 1.0
+ * @param <T>
+ */
+public class EntitySelectionElementComposite<T extends ICdmBase> extends AbstractCdmFormElementComposite implements SelectionListener, IEnableableFormElement, ISelectableElement, IEntityElement<T>, ILabeledElement, IConversationEnabled {
+
+ /**
+ * Bitmask for configuring functionality of selection element
+ */
+ public static final int NOTHING = 0; // 000
+ public static final int EDITABLE = 1 << 0; // 001
+ public static final int DELETABLE = 1 << 1; // 010
+ public static final int SELECTABLE = 1 << 2; // 100
+ public static final int ALL = EDITABLE | DELETABLE | SELECTABLE; // 111
+
+ protected T entity;
+
+ protected Label label;
+ protected Label text;
+ protected Button button_selection;
+
+ private SelectionArbitrator selectionArbitrator;
+
+ protected Button button_edit;
+
+ private final String labelString;
+
+ private final Composite selectableComposite;
+
+ private Button button_remove;
+
+ private final boolean isEditable;
+
+ private final boolean isDeletable;
+
+ private final ConversationHolder conversation;
+ private Class<T> clazz;
+
+ /**
+ * <p>
+ * Constructor for AbstractSelectionElement.
+ * </p>
+ *
+ * @param formFactory
+ * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
+ * object.
+ * @param conversation
+ * TODO
+ * @param parentElement
+ * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
+ * object.
+ * @param labelString
+ * a {@link java.lang.String} object.
+ * @param entity
+ * a T object.
+ * @param isEditable
+ * a boolean.
+ * @param isSelectable
+ * a boolean.
+ * @param isDeletable
+ * a boolean.
+ * @param style
+ * a int.
+ * @param <T>
+ * a T object.
+ */
+ public EntitySelectionElementComposite(Composite parent, FormToolkit formFactory, ConversationHolder conversation, ICdmFormElement parentElement, String labelString, T entity, int mode, int style) {
+ super(parent, formFactory, parentElement, style);
+
+ this.isEditable = (mode & EDITABLE) == EDITABLE;
+ this.isDeletable = (mode & DELETABLE) == DELETABLE;
+ boolean isSelectable = (mode & SELECTABLE) == SELECTABLE;
+
+ this.labelString = labelString;
+
+ this.conversation = conversation;
+
+ if (isSelectable && formFactory instanceof CdmFormFactory && ((CdmFormFactory) formFactory).getSelectionProvider() != null) {
+ selectionArbitrator = ((CdmFormFactory) formFactory).createSelectionArbitrator(this);
+ }
+
+ //only for WindowBuilder
+ Composite parentComposite = this;
+ if(parentElement!=null){
+ parentComposite = parentElement.getLayoutComposite();
+ }
+
+ label = formFactory.createLabel(parentComposite, labelString, SWT.NULL);
+
+ addControl(label);
+
+ selectableComposite = formFactory.createComposite(parentComposite, style);
+
+ int columns = 2;
+ if (isEditable) {
+ columns += 1;
+ }
+ if (isDeletable) {
+ columns += 1;
+ }
+
+ selectableComposite.setLayout(LayoutConstants.LAYOUT(columns, false));
+ selectableComposite.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
+
+ addControl(selectableComposite);
+
+ text = formFactory.createLabel(selectableComposite, null, SWT.WRAP);
+ addControl(text);
+
+ text.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
+
+ button_selection = formFactory.createButton(selectableComposite, null, SWT.PUSH);
+ button_selection.setImage(ResourceManager.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/prj_obj.gif"));
+ button_selection.setToolTipText("Browse existing");
+
+ addControl(button_selection);
+ button_selection.addSelectionListener(this);
+
+ if (isEditable) {
+ button_edit = formFactory.createButton(selectableComposite, null, SWT.PUSH);
+ button_edit.setImage(ResourceManager.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/text.gif"));
+ button_edit.setToolTipText("Edit");
+ addControl(button_edit);
+ button_edit.addSelectionListener(new EditListener(this));
+ }
+
+ if (isDeletable) {
+ button_remove = formFactory.createButton(selectableComposite, null, SWT.PUSH);
+ button_remove.setImage(ResourceManager.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/trash.gif"));
+ button_remove.setToolTipText("Remove");
+ addControl(button_remove);
+ button_remove.addSelectionListener(new DeleteListener(this));
+ }
+
+ setEntity(entity);
+ }
+
+ /**
+ *
+ * @param parent
+ * @param formFactory
+ * @param conversation
+ * @param parentElement
+ * @param clazz
+ * @param labelString
+ * @param entity
+ * @param mode
+ * @param style
+ * @wbp.parser.constructor
+ */
+ public EntitySelectionElementComposite(Composite parent, FormToolkit formFactory, ConversationHolder conversation, ICdmFormElement parentElement, Class<T> clazz, String labelString, T entity, int mode, int style) {
+ this(parent, formFactory, conversation, parentElement, labelString, entity, mode, style);
+ setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
+ this.clazz = clazz;
+ }
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ T selection = SelectionDialogFactory.getSelectionFromDialog(clazz, getShell(), getConversationHolder(), getEntity());
+ setSelectionInternal(selection);
+ }
+
+ /**
+ * Return the selected object
+ *
+ * @return a T object.
+ */
+ public T getSelection() {
+ return entity;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * eu.etaxonomy.taxeditor.forms.IEnableableFormElement#setEnabled(boolean)
+ */
+ /** {@inheritDoc} */
+ @Override
+ public void setEnabled(boolean enabled) {
+ button_selection.setEnabled(enabled);
+ if (isEditable) {
+ button_edit.setEnabled(enabled && entity != null);
+ }
+ }
+
+ /**
+ * <p>
+ * setSelectionInternal
+ * </p>
+ *
+ * @param selection
+ * a T object.
+ */
+ protected void setSelectionInternal(T selection) {
+ if (selection != null && !selection.equals(this.entity)) {
+ setEntity(selection);
+ firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
+ }
+ }
+
+ /**
+ * <p>
+ * Setter for the field <code>entity</code>.
+ * </p>
+ *
+ * @param selection
+ * a T object.
+ */
+ public void setEntity(T selection) {
+ this.entity = selection;
+ updateElement();
+ }
+
+ /**
+ * Updates this elements view
+ */
+ protected void updateElement() {
+ String title = CdmUtils.Nz(getTitle());
+ // we have to duplicate ampersands otherwise they are treated as
+ // mnenomic (see Label.setText() documentation)
+ title = title.replace("&", "&&");
+ text.setText(title); // title can be null
+ if (isEditable) {
+ button_edit.setEnabled(entity != null);
+ }
+ }
+
+ /**
+ * <p>
+ * updateFromWizard
+ * </p>
+ */
+ protected void updateFromWizard() {
+ updateElement();
+ firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
+ }
+
+ /**
+ * <p>
+ * getTitle
+ * </p>
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ protected String getTitle() {
+ if (entity != null) {
+ if (entity instanceof IIdentifiableEntity) {
+ return ((IIdentifiableEntity) entity).getTitleCache();
+ } else if (entity instanceof Group) {
+ return ((Group) entity).getName();
+ } else if (entity instanceof GrantedAuthority) {
+ return ((GrantedAuthority) entity).getAuthority();
+ }
+ }
+ return "";
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void setSelected(boolean selected) {
+ setBackground(selected ? SELECTED : getPersistentBackground());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see eu.etaxonomy.taxeditor.forms.IEntityElement#getEntity()
+ */
+ /**
+ * <p>
+ * Getter for the field <code>entity</code>.
+ * </p>
+ *
+ * @return a T object.
+ */
+ @Override
+ public T getEntity() {
+ return entity;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see eu.etaxonomy.taxeditor.forms.section.cdmdetail.ISelectableElement#
+ * getSelectionArbitrator()
+ */
+ /**
+ * <p>
+ * Getter for the field <code>selectionArbitrator</code>.
+ * </p>
+ *
+ * @return a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator}
+ * object.
+ */
+ @Override
+ public SelectionArbitrator getSelectionArbitrator() {
+ return selectionArbitrator;
+ }
+
+ // TODO is method necessary
+ // /**
+ // * Convenient access to current shell
+ // *
+ // * @return a {@link org.eclipse.swt.widgets.Shell} object.
+ // */
+ // @Override
+ // public Shell getShell() {
+ // return getLayoutComposite().getShell();
+ // }
+
+ /** {@inheritDoc} */
+ @Override
+ public void setIrrelevant(boolean irrelevant) {
+ String colorId = irrelevant ? Resources.COLOR_COMPOSITE_IRRELEVANT : Resources.COLOR_TEXT_DISABLED_BACKGROUND;
+
+ Color color = AbstractUtility.getColor(colorId);
+ text.setBackground(color);
+ }
+
+ private class DeleteListener extends SelectionAdapter {
+
+ private final EntitySelectionElementComposite<T> selectionElement;
+
+ public DeleteListener(EntitySelectionElementComposite<T> selectionElement) {
+ this.selectionElement = selectionElement;
+ }
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ setEntity(null);
+ firePropertyChangeEvent(new CdmPropertyChangeEvent(selectionElement, null));
+ }
+ }
+
+ private class EditListener extends SelectionAdapter {
+
+ private final EntitySelectionElementComposite<T> selectionElement;
+
+ public EditListener(EntitySelectionElementComposite<T> selectionElement) {
+ this.selectionElement = selectionElement;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ //TODO uncomment
+// WizardDialog dialog = new WizardDialog(selectionElement.getShell(), new EditFromSelectionWizard(selectionElement));
+// if (dialog.open() == IStatus.OK) {
+// selectionElement.updateFromWizard();
+// }
+ }
+ }
+
+ // not used
+ /** {@inheritDoc} */
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+
+ /**
+ * <p>
+ * getConversationHolder
+ * </p>
+ *
+ * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
+ * object.
+ */
+ @Override
+ public ConversationHolder getConversationHolder() {
+ return conversation;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void setBackground(Color color) {
+ if(label !=null && color!=null){
+ label.setBackground(color);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void setLabel(String labelString) {
+ if (label != null) {
+ label.setText(labelString);
+ }
+ }
+
+ /**
+ * <p>
+ * Getter for the field <code>label</code>.
+ * </p>
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ @Override
+ public String getLabel() {
+ if (label != null) {
+ return label.getText();
+ }
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void update(CdmDataChangeMap changeEvents) {
+ }
+}
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2011 Google, Inc.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * Google, Inc. - initial API and implementation\r
+ *******************************************************************************/\r
+package org.eclipse.wb.swt;
+
+import java.io.File;
+import java.io.InputStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.resource.CompositeImageDescriptor;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.osgi.framework.Bundle;
+
+/**
+ * Utility class for managing OS resources associated with SWT/JFace controls such as colors, fonts, images,
+ * etc.
+ *
+ * !!! IMPORTANT !!! Application code must explicitly invoke the <code>dispose()</code> method to release the
+ * operating system resources managed by cached objects when those objects and OS resources are no longer
+ * needed (e.g. on application shutdown)
+ *
+ * This class may be freely distributed as part of any application or plugin.
+ * <p>
+ *
+ * @author scheglov_ke
+ * @author Dan Rubel
+ */
+public class ResourceManager extends SWTResourceManager {
+ ////////////////////////////////////////////////////////////////////////////
+ //
+ // Image
+ //
+ ////////////////////////////////////////////////////////////////////////////
+ private static Map<ImageDescriptor, Image> m_descriptorImageMap = new HashMap<ImageDescriptor, Image>();
+ /**
+ * Returns an {@link ImageDescriptor} stored in the file at the specified path relative to the specified
+ * class.
+ *
+ * @param clazz
+ * the {@link Class} relative to which to find the image descriptor.
+ * @param path
+ * the path to the image file.
+ * @return the {@link ImageDescriptor} stored in the file at the specified path.
+ */
+ public static ImageDescriptor getImageDescriptor(Class<?> clazz, String path) {
+ return ImageDescriptor.createFromFile(clazz, path);
+ }
+ /**
+ * Returns an {@link ImageDescriptor} stored in the file at the specified path.
+ *
+ * @param path
+ * the path to the image file.
+ * @return the {@link ImageDescriptor} stored in the file at the specified path.
+ */
+ public static ImageDescriptor getImageDescriptor(String path) {
+ try {
+ return ImageDescriptor.createFromURL(new File(path).toURI().toURL());
+ } catch (MalformedURLException e) {
+ return null;
+ }
+ }
+ /**
+ * Returns an {@link Image} based on the specified {@link ImageDescriptor}.
+ *
+ * @param descriptor
+ * the {@link ImageDescriptor} for the {@link Image}.
+ * @return the {@link Image} based on the specified {@link ImageDescriptor}.
+ */
+ public static Image getImage(ImageDescriptor descriptor) {
+ if (descriptor == null) {
+ return null;
+ }
+ Image image = m_descriptorImageMap.get(descriptor);
+ if (image == null) {
+ image = descriptor.createImage();
+ m_descriptorImageMap.put(descriptor, image);
+ }
+ return image;
+ }
+ /**
+ * Maps images to decorated images.
+ */
+ @SuppressWarnings("unchecked")
+ private static Map<Image, Map<Image, Image>>[] m_decoratedImageMap = new Map[LAST_CORNER_KEY];
+ /**
+ * Returns an {@link Image} composed of a base image decorated by another image.
+ *
+ * @param baseImage
+ * the base {@link Image} that should be decorated.
+ * @param decorator
+ * the {@link Image} to decorate the base image.
+ * @return {@link Image} The resulting decorated image.
+ */
+ public static Image decorateImage(Image baseImage, Image decorator) {
+ return decorateImage(baseImage, decorator, BOTTOM_RIGHT);
+ }
+ /**
+ * Returns an {@link Image} composed of a base image decorated by another image.
+ *
+ * @param baseImage
+ * the base {@link Image} that should be decorated.
+ * @param decorator
+ * the {@link Image} to decorate the base image.
+ * @param corner
+ * the corner to place decorator image.
+ * @return the resulting decorated {@link Image}.
+ */
+ public static Image decorateImage(final Image baseImage, final Image decorator, final int corner) {
+ if (corner <= 0 || corner >= LAST_CORNER_KEY) {
+ throw new IllegalArgumentException("Wrong decorate corner");
+ }
+ Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[corner];
+ if (cornerDecoratedImageMap == null) {
+ cornerDecoratedImageMap = new HashMap<Image, Map<Image, Image>>();
+ m_decoratedImageMap[corner] = cornerDecoratedImageMap;
+ }
+ Map<Image, Image> decoratedMap = cornerDecoratedImageMap.get(baseImage);
+ if (decoratedMap == null) {
+ decoratedMap = new HashMap<Image, Image>();
+ cornerDecoratedImageMap.put(baseImage, decoratedMap);
+ }
+ //
+ Image result = decoratedMap.get(decorator);
+ if (result == null) {
+ final Rectangle bib = baseImage.getBounds();
+ final Rectangle dib = decorator.getBounds();
+ final Point baseImageSize = new Point(bib.width, bib.height);
+ CompositeImageDescriptor compositImageDesc = new CompositeImageDescriptor() {
+ @Override
+ protected void drawCompositeImage(int width, int height) {
+ drawImage(baseImage.getImageData(), 0, 0);
+ if (corner == TOP_LEFT) {
+ drawImage(decorator.getImageData(), 0, 0);
+ } else if (corner == TOP_RIGHT) {
+ drawImage(decorator.getImageData(), bib.width - dib.width, 0);
+ } else if (corner == BOTTOM_LEFT) {
+ drawImage(decorator.getImageData(), 0, bib.height - dib.height);
+ } else if (corner == BOTTOM_RIGHT) {
+ drawImage(decorator.getImageData(), bib.width - dib.width, bib.height - dib.height);
+ }
+ }
+ @Override
+ protected Point getSize() {
+ return baseImageSize;
+ }
+ };
+ //
+ result = compositImageDesc.createImage();
+ decoratedMap.put(decorator, result);
+ }
+ return result;
+ }
+ /**
+ * Dispose all of the cached images.
+ */
+ public static void disposeImages() {
+ SWTResourceManager.disposeImages();
+ // dispose ImageDescriptor images
+ {
+ for (Iterator<Image> I = m_descriptorImageMap.values().iterator(); I.hasNext();) {
+ I.next().dispose();
+ }
+ m_descriptorImageMap.clear();
+ }
+ // dispose decorated images
+ for (int i = 0; i < m_decoratedImageMap.length; i++) {
+ Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[i];
+ if (cornerDecoratedImageMap != null) {
+ for (Map<Image, Image> decoratedMap : cornerDecoratedImageMap.values()) {
+ for (Image image : decoratedMap.values()) {
+ image.dispose();
+ }
+ decoratedMap.clear();
+ }
+ cornerDecoratedImageMap.clear();
+ }
+ }
+ // dispose plugin images
+ {
+ for (Iterator<Image> I = m_URLImageMap.values().iterator(); I.hasNext();) {
+ I.next().dispose();
+ }
+ m_URLImageMap.clear();
+ }
+ }
+ ////////////////////////////////////////////////////////////////////////////
+ //
+ // Plugin images support
+ //
+ ////////////////////////////////////////////////////////////////////////////
+ /**
+ * Maps URL to images.
+ */
+ private static Map<String, Image> m_URLImageMap = new HashMap<String, Image>();
+ /**
+ * Provider for plugin resources, used by WindowBuilder at design time.
+ */
+ public interface PluginResourceProvider {
+ URL getEntry(String symbolicName, String path);
+ }
+ /**
+ * Instance of {@link PluginResourceProvider}, used by WindowBuilder at design time.
+ */
+ private static PluginResourceProvider m_designTimePluginResourceProvider = null;
+ /**
+ * Returns an {@link Image} based on a plugin and file path.
+ *
+ * @param plugin
+ * the plugin {@link Object} containing the image
+ * @param name
+ * the path to the image within the plugin
+ * @return the {@link Image} stored in the file at the specified path
+ *
+ * @deprecated Use {@link #getPluginImage(String, String)} instead.
+ */
+ @Deprecated
+ public static Image getPluginImage(Object plugin, String name) {
+ try {
+ URL url = getPluginImageURL(plugin, name);
+ if (url != null) {
+ return getPluginImageFromUrl(url);
+ }
+ } catch (Throwable e) {
+ // Ignore any exceptions
+ }
+ return null;
+ }
+ /**
+ * Returns an {@link Image} based on a {@link Bundle} and resource entry path.
+ *
+ * @param symbolicName
+ * the symbolic name of the {@link Bundle}.
+ * @param path
+ * the path of the resource entry.
+ * @return the {@link Image} stored in the file at the specified path.
+ */
+ public static Image getPluginImage(String symbolicName, String path) {
+ try {
+ URL url = getPluginImageURL(symbolicName, path);
+ if (url != null) {
+ return getPluginImageFromUrl(url);
+ }
+ } catch (Throwable e) {
+ // Ignore any exceptions
+ }
+ return null;
+ }
+ /**
+ * Returns an {@link Image} based on given {@link URL}.
+ */
+ private static Image getPluginImageFromUrl(URL url) {
+ try {
+ try {
+ String key = url.toExternalForm();
+ Image image = m_URLImageMap.get(key);
+ if (image == null) {
+ InputStream stream = url.openStream();
+ try {
+ image = getImage(stream);
+ m_URLImageMap.put(key, image);
+ } finally {
+ stream.close();
+ }
+ }
+ return image;
+ } catch (Throwable e) {
+ // Ignore any exceptions
+ }
+ } catch (Throwable e) {
+ // Ignore any exceptions
+ }
+ return null;
+ }
+ /**
+ * Returns an {@link ImageDescriptor} based on a plugin and file path.
+ *
+ * @param plugin
+ * the plugin {@link Object} containing the image.
+ * @param name
+ * the path to th eimage within the plugin.
+ * @return the {@link ImageDescriptor} stored in the file at the specified path.
+ *
+ * @deprecated Use {@link #getPluginImageDescriptor(String, String)} instead.
+ */
+ @Deprecated
+ public static ImageDescriptor getPluginImageDescriptor(Object plugin, String name) {
+ try {
+ try {
+ URL url = getPluginImageURL(plugin, name);
+ return ImageDescriptor.createFromURL(url);
+ } catch (Throwable e) {
+ // Ignore any exceptions
+ }
+ } catch (Throwable e) {
+ // Ignore any exceptions
+ }
+ return null;
+ }
+ /**
+ * Returns an {@link ImageDescriptor} based on a {@link Bundle} and resource entry path.
+ *
+ * @param symbolicName
+ * the symbolic name of the {@link Bundle}.
+ * @param path
+ * the path of the resource entry.
+ * @return the {@link ImageDescriptor} based on a {@link Bundle} and resource entry path.
+ */
+ public static ImageDescriptor getPluginImageDescriptor(String symbolicName, String path) {
+ try {
+ URL url = getPluginImageURL(symbolicName, path);
+ if (url != null) {
+ return ImageDescriptor.createFromURL(url);
+ }
+ } catch (Throwable e) {
+ // Ignore any exceptions
+ }
+ return null;
+ }
+ /**
+ * Returns an {@link URL} based on a {@link Bundle} and resource entry path.
+ */
+ private static URL getPluginImageURL(String symbolicName, String path) {
+ // try runtime plugins
+ {
+ Bundle bundle = Platform.getBundle(symbolicName);
+ if (bundle != null) {
+ return bundle.getEntry(path);
+ }
+ }
+ // try design time provider
+ if (m_designTimePluginResourceProvider != null) {
+ return m_designTimePluginResourceProvider.getEntry(symbolicName, path);
+ }
+ // no such resource
+ return null;
+ }
+ /**
+ * Returns an {@link URL} based on a plugin and file path.
+ *
+ * @param plugin
+ * the plugin {@link Object} containing the file path.
+ * @param name
+ * the file path.
+ * @return the {@link URL} representing the file at the specified path.
+ * @throws Exception
+ */
+ private static URL getPluginImageURL(Object plugin, String name) throws Exception {
+ // try to work with 'plugin' as with OSGI BundleContext
+ try {
+ Class<?> BundleClass = Class.forName("org.osgi.framework.Bundle"); //$NON-NLS-1$
+ Class<?> BundleContextClass = Class.forName("org.osgi.framework.BundleContext"); //$NON-NLS-1$
+ if (BundleContextClass.isAssignableFrom(plugin.getClass())) {
+ Method getBundleMethod = BundleContextClass.getMethod("getBundle", new Class[0]); //$NON-NLS-1$
+ Object bundle = getBundleMethod.invoke(plugin, new Object[0]);
+ //
+ Class<?> PathClass = Class.forName("org.eclipse.core.runtime.Path"); //$NON-NLS-1$
+ Constructor<?> pathConstructor = PathClass.getConstructor(new Class[]{String.class});
+ Object path = pathConstructor.newInstance(new Object[]{name});
+ //
+ Class<?> IPathClass = Class.forName("org.eclipse.core.runtime.IPath"); //$NON-NLS-1$
+ Class<?> PlatformClass = Class.forName("org.eclipse.core.runtime.Platform"); //$NON-NLS-1$
+ Method findMethod = PlatformClass.getMethod("find", new Class[]{BundleClass, IPathClass}); //$NON-NLS-1$
+ return (URL) findMethod.invoke(null, new Object[]{bundle, path});
+ }
+ } catch (Throwable e) {
+ // Ignore any exceptions
+ }
+ // else work with 'plugin' as with usual Eclipse plugin
+ {
+ Class<?> PluginClass = Class.forName("org.eclipse.core.runtime.Plugin"); //$NON-NLS-1$
+ if (PluginClass.isAssignableFrom(plugin.getClass())) {
+ //
+ Class<?> PathClass = Class.forName("org.eclipse.core.runtime.Path"); //$NON-NLS-1$
+ Constructor<?> pathConstructor = PathClass.getConstructor(new Class[]{String.class});
+ Object path = pathConstructor.newInstance(new Object[]{name});
+ //
+ Class<?> IPathClass = Class.forName("org.eclipse.core.runtime.IPath"); //$NON-NLS-1$
+ Method findMethod = PluginClass.getMethod("find", new Class[]{IPathClass}); //$NON-NLS-1$
+ return (URL) findMethod.invoke(plugin, new Object[]{path});
+ }
+ }
+ return null;
+ }
+ ////////////////////////////////////////////////////////////////////////////
+ //
+ // General
+ //
+ ////////////////////////////////////////////////////////////////////////////
+ /**
+ * Dispose of cached objects and their underlying OS resources. This should only be called when the cached
+ * objects are no longer needed (e.g. on application shutdown).
+ */
+ public static void dispose() {
+ disposeColors();
+ disposeFonts();
+ disposeImages();
+ }
+}
\ No newline at end of file