From: Patrick Plitzner
Date: Tue, 25 Aug 2015 06:05:51 +0000 (+0200)
Subject: Split up control creation of TextWithLabelElement
X-Git-Tag: 3.8.0^2~50
X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/commitdiff_plain/1fbf88c829bfc7c1c58f8c8b86e65e3bfe2cd1b3
Split up control creation of TextWithLabelElement
- this fixes layout problems when inserting a separate button for
opening links
---
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/TextWithLabelElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/TextWithLabelElement.java
index efe1877a2..039b54c0d 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/TextWithLabelElement.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/TextWithLabelElement.java
@@ -60,22 +60,13 @@ public class TextWithLabelElement extends AbstractCdmFormElement implements Modi
this.isMultiLine = isMultiLine;
- init(formFactory, labelString, initialText, textHeight, textLimit, isMultiLine, style, getLayoutComposite());
- }
+ initLabel(formFactory, labelString, isMultiLine, getLayoutComposite());
- protected void init(CdmFormFactory formFactory, String labelString, String initialText, Integer textHeight,
- Integer textLimit, boolean isMultiLine, int style, Composite layoutComposite) {
- if (labelString != null) {
- label = formFactory.createLabel(layoutComposite, CdmUtils.Nz(labelString), SWT.NULL);
- addControl(label);
- if(isMultiLine){
- label.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
- }
- else{
- label.setLayoutData(LayoutConstants.LEFT());
- }
- }
+ initText(formFactory, initialText, textHeight, textLimit, isMultiLine, style, getLayoutComposite());
+ }
+ protected void initText(CdmFormFactory formFactory, String initialText, Integer textHeight, Integer textLimit,
+ boolean isMultiLine, int style, Composite layoutComposite) {
int scrollStyle = textHeight == null ? SWT.NULL : (SWT.V_SCROLL | SWT.MULTI);
int combinedStyle = style | SWT.BORDER | scrollStyle;
@@ -128,6 +119,19 @@ public class TextWithLabelElement extends AbstractCdmFormElement implements Modi
setText(initialText);
}
+ protected void initLabel(CdmFormFactory formFactory, String labelString, boolean isMultiLine, Composite layoutComposite) {
+ if (labelString != null) {
+ label = formFactory.createLabel(layoutComposite, CdmUtils.Nz(labelString), SWT.NULL);
+ addControl(label);
+ if(isMultiLine){
+ label.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+ }
+ else{
+ label.setLayoutData(LayoutConstants.LEFT());
+ }
+ }
+ }
+
/**
* Get the text of this composites text composite
*
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/UriWithLabelElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/UriWithLabelElement.java
index 4f5bcde7f..a329e87ec 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/UriWithLabelElement.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/UriWithLabelElement.java
@@ -22,7 +22,6 @@ import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Layout;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.forms.widgets.TableWrapLayout;
@@ -40,27 +39,19 @@ public class UriWithLabelElement extends TextWithLabelElement {
private final Label labelException;
private final Button btnOpenBrowser;
- private static final int NUM_COLUMNS = 3;
protected UriWithLabelElement(CdmFormFactory formFactory,
ICdmFormElement parentElement, String labelString,
URI initialUri, Integer textHeight, int style) {
super(formFactory, parentElement, false);
- Layout parentLayout = getLayoutComposite().getLayout();
- int parentNumColumns = 2;
- if(parentLayout instanceof TableWrapLayout){
- parentNumColumns = ((TableWrapLayout)parentLayout).numColumns;
- }
- Composite layoutComposite = formFactory.createComposite(getLayoutComposite());
- addControl(layoutComposite);
-
- layoutComposite.setLayout(LayoutConstants.LAYOUT(3, false));
- layoutComposite.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(parentNumColumns, 1));
+ initLabel(formFactory, labelString, false, getLayoutComposite());
- init(formFactory, labelString, null, textHeight, null, false, style, layoutComposite);
+ Composite textAndButton = formFactory.createComposite(getLayoutComposite(), style);
+ textAndButton.setLayout(LayoutConstants.LAYOUT(2, false));
+ textAndButton.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
- btnOpenBrowser = formFactory.createButton(layoutComposite, "", SWT.NONE);
+ btnOpenBrowser = formFactory.createButton(textAndButton, "", SWT.NONE);
btnOpenBrowser.setImage(ImageResources.getImage(ImageResources.ADD_CHILD_TAXON_ICON));
btnOpenBrowser.setToolTipText("Open in external browser");
btnOpenBrowser.addSelectionListener(new SelectionAdapter() {
@@ -85,8 +76,14 @@ public class UriWithLabelElement extends TextWithLabelElement {
});
btnOpenBrowser.setLayoutData(LayoutConstants.RIGHT());
- labelException = formFactory.createLabel(layoutComposite, "", SWT.WRAP);
- labelException.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(NUM_COLUMNS, 1));
+ initLabel(formFactory, labelString, false, textAndButton);
+
+ labelException = formFactory.createLabel(getLayoutComposite(), "", SWT.WRAP);
+ int numColumns = AbstractFormSection.DEFAULT_NUM_COLUMNS;
+ if(getLayoutComposite().getLayout() instanceof TableWrapLayout){
+ numColumns = ((TableWrapLayout)getLayoutComposite().getLayout()).numColumns;
+ }
+ labelException.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(numColumns, 1));
addControl(labelException);
setUri(initialUri);
}