Revision 46c38373
Added by Patrick Plitzner almost 9 years ago
- Added browse button to media section which allows to choose the media from existing ones (#2385)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/AbstractEntityCollectionElement.java | ||
---|---|---|
17 | 17 |
import org.eclipse.swt.graphics.Color; |
18 | 18 |
import org.eclipse.swt.widgets.Button; |
19 | 19 |
import org.eclipse.swt.widgets.Composite; |
20 |
import org.eclipse.swt.widgets.Event; |
|
20 | 21 |
import org.eclipse.swt.widgets.Layout; |
22 |
import org.eclipse.swt.widgets.Listener; |
|
21 | 23 |
import org.eclipse.ui.forms.widgets.TableWrapLayout; |
22 | 24 |
|
23 | 25 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
... | ... | |
52 | 54 |
|
53 | 55 |
private final Composite box; |
54 | 56 |
|
55 |
private Button button_remove; |
|
57 |
private Button btnRemove; |
|
58 |
private Button btnChooseEntity; |
|
56 | 59 |
|
57 | 60 |
private Color backgroundColor; |
58 | 61 |
|
... | ... | |
77 | 80 |
* a ENTITY object. |
78 | 81 |
*/ |
79 | 82 |
public AbstractEntityCollectionElement(CdmFormFactory formFactory, |
80 |
AbstractFormSection section, ENTITY entity, |
|
81 |
SelectionListener removeListener, Color backgroundColor, int style) { |
|
83 |
AbstractFormSection section, ENTITY entity, |
|
84 |
SelectionListener removeListener, Color backgroundColor, int style) { |
|
85 |
this(formFactory, section, entity, removeListener, false, backgroundColor, style); |
|
86 |
} |
|
87 |
public AbstractEntityCollectionElement(CdmFormFactory formFactory, |
|
88 |
AbstractFormSection section, ENTITY entity, SelectionListener removeListener, |
|
89 |
boolean isChoosableEntity, Color backgroundColor, int style) { |
|
82 | 90 |
super(formFactory, (ICdmFormElement) section); |
83 | 91 |
|
84 | 92 |
init(); |
85 | 93 |
|
86 | 94 |
formFactory.addPropertyChangeListener(this); |
87 | 95 |
|
88 |
// section.getLayoutComposite().setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_CYAN)); |
|
89 |
|
|
90 | 96 |
box = formFactory.createComposite(section.getLayoutComposite()); |
91 | 97 |
box.setBackgroundMode(SWT.INHERIT_DEFAULT); |
92 | 98 |
addControl(box); |
93 | 99 |
|
94 |
TableWrapLayout boxLayout = LayoutConstants.LAYOUT(2, false);
|
|
100 |
TableWrapLayout boxLayout = LayoutConstants.LAYOUT(3, false);
|
|
95 | 101 |
boxLayout.topMargin = 4; |
96 | 102 |
boxLayout.bottomMargin = 4; |
97 | 103 |
box.setLayout(boxLayout); |
98 | 104 |
|
99 | 105 |
box.setLayoutData(LayoutConstants.FILL_HORIZONTALLY()); |
100 | 106 |
|
101 |
// box.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE)); |
|
102 |
|
|
103 | 107 |
container = formFactory.createComposite(box); |
104 | 108 |
container.setBackgroundMode(SWT.INHERIT_DEFAULT); |
105 | 109 |
|
106 |
// container.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED)); |
|
107 | 110 |
setLayoutComposite(container); |
108 | 111 |
|
109 | 112 |
addControl(container); |
... | ... | |
112 | 115 |
container.setLayout(containerLayout); |
113 | 116 |
container.setLayoutData(LayoutConstants.FILL_HORIZONTALLY()); |
114 | 117 |
|
118 |
if(isChoosableEntity){ |
|
119 |
btnChooseEntity = formFactory.createButton(box, null, SWT.PUSH); |
|
120 |
addControl(btnChooseEntity); |
|
121 |
btnChooseEntity.setLayoutData(LayoutConstants.RIGHT()); |
|
122 |
btnChooseEntity.setImage(ImageResources.getImage(ImageResources.BROWSE_ICON)); |
|
123 |
btnChooseEntity.setToolTipText("Browse"); |
|
124 |
btnChooseEntity.addListener(SWT.Selection, new Listener() { |
|
125 |
|
|
126 |
@Override |
|
127 |
public void handleEvent(Event event) { |
|
128 |
ENTITY entity = selectFromDialog(); |
|
129 |
if(entity!=null){ |
|
130 |
if(getParentElement() instanceof AbstractEntityCollectionSection){ |
|
131 |
((AbstractEntityCollectionSection)getParentElement()).removeElement(getEntity()); |
|
132 |
setEntity(entity); |
|
133 |
((AbstractEntityCollectionSection)getParentElement()).addElement(entity); |
|
134 |
((AbstractEntityCollectionSection)getParentElement()).firePropertyChangeEvent(getParentElement()); |
|
135 |
} |
|
136 |
} |
|
137 |
} |
|
138 |
}); |
|
139 |
} |
|
140 |
|
|
115 | 141 |
if (removeListener != null) { |
116 |
button_remove = formFactory.createButton(box, null, SWT.PUSH);
|
|
117 |
addControl(button_remove);
|
|
118 |
button_remove.setLayoutData(LayoutConstants.RIGHT());
|
|
119 |
button_remove.setImage(ImageResources
|
|
142 |
btnRemove = formFactory.createButton(box, null, SWT.PUSH);
|
|
143 |
addControl(btnRemove);
|
|
144 |
btnRemove.setLayoutData(LayoutConstants.RIGHT());
|
|
145 |
btnRemove.setImage(ImageResources
|
|
120 | 146 |
.getImage(ImageResources.TRASH_ICON)); |
121 |
button_remove.setToolTipText("Remove");
|
|
147 |
btnRemove.setToolTipText("Remove");
|
|
122 | 148 |
|
123 |
button_remove.addSelectionListener(removeListener);
|
|
149 |
btnRemove.addSelectionListener(removeListener);
|
|
124 | 150 |
} |
125 | 151 |
|
126 | 152 |
createControls(this, style); |
... | ... | |
159 | 185 |
return entity; |
160 | 186 |
} |
161 | 187 |
|
188 |
/** |
|
189 |
* Sub classes should override to provide the functionality to choose the |
|
190 |
* entity from existing ones from the data source.<br> |
|
191 |
* <b>Note:</b> to enable this functionality sub classes have to set |
|
192 |
* the corresponding flag in the super constructor |
|
193 |
* @return an existing entity from the data source |
|
194 |
*/ |
|
195 |
protected ENTITY selectFromDialog(){ |
|
196 |
return null; |
|
197 |
} |
|
198 |
|
|
162 | 199 |
/** |
163 | 200 |
* <p> |
164 | 201 |
* createControls |
Also available in: Unified diff