Revision 24f5f2e8
Added by Patrick Plitzner over 8 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/UriWithLabelElement.java | ||
---|---|---|
13 | 13 |
import java.net.MalformedURLException; |
14 | 14 |
import java.net.URI; |
15 | 15 |
|
16 |
import org.eclipse.core.runtime.IStatus; |
|
17 |
import org.eclipse.core.runtime.Status; |
|
16 | 18 |
import org.eclipse.swt.SWT; |
17 | 19 |
import org.eclipse.swt.events.SelectionAdapter; |
18 | 20 |
import org.eclipse.swt.events.SelectionEvent; |
... | ... | |
20 | 22 |
import org.eclipse.swt.widgets.Composite; |
21 | 23 |
import org.eclipse.swt.widgets.Display; |
22 | 24 |
import org.eclipse.swt.widgets.Label; |
25 |
import org.eclipse.swt.widgets.Layout; |
|
23 | 26 |
import org.eclipse.ui.PartInitException; |
24 | 27 |
import org.eclipse.ui.PlatformUI; |
25 | 28 |
import org.eclipse.ui.forms.widgets.TableWrapData; |
29 |
import org.eclipse.ui.forms.widgets.TableWrapLayout; |
|
26 | 30 |
|
27 | 31 |
import eu.etaxonomy.taxeditor.model.ImageResources; |
32 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
|
33 |
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin; |
|
28 | 34 |
|
29 | 35 |
/** |
30 | 36 |
* @author n.hoffmann |
... | ... | |
35 | 41 |
|
36 | 42 |
private final Label labelException; |
37 | 43 |
private final Button btnOpenBrowser; |
44 |
private static final int NUM_COLUMNS = 3; |
|
38 | 45 |
|
39 | 46 |
protected UriWithLabelElement(CdmFormFactory formFactory, |
40 | 47 |
ICdmFormElement parentElement, String labelString, |
41 | 48 |
URI initialUri, Integer textHeight, int style) { |
42 | 49 |
super(formFactory, parentElement, false); |
43 | 50 |
|
51 |
Layout parentLayout = getLayoutComposite().getLayout(); |
|
52 |
int parentNumColumns = 2; |
|
53 |
if(parentLayout instanceof TableWrapLayout){ |
|
54 |
parentNumColumns = ((TableWrapLayout)parentLayout).numColumns; |
|
55 |
} |
|
44 | 56 |
Composite layoutComposite = formFactory.createComposite(getLayoutComposite()); |
45 |
layoutComposite.setLayout(LayoutConstants.LAYOUT(3, false)); |
|
46 |
layoutComposite.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2,1)); |
|
47 |
init(formFactory, labelString, null, textHeight, null, false, style, layoutComposite); |
|
57 |
addControl(layoutComposite); |
|
48 | 58 |
|
59 |
layoutComposite.setLayout(LayoutConstants.LAYOUT(3, true)); |
|
60 |
layoutComposite.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(parentNumColumns, 1)); |
|
61 |
|
|
62 |
init(formFactory, labelString, null, textHeight, null, false, style, layoutComposite); |
|
49 | 63 |
|
50 | 64 |
btnOpenBrowser = formFactory.createButton(layoutComposite, "", SWT.NONE); |
51 | 65 |
btnOpenBrowser.setImage(ImageResources.getImage(ImageResources.ADD_CHILD_TAXON_ICON)); |
52 |
TableWrapData layoutData = LayoutConstants.RIGHT(); |
|
53 |
layoutData.grabHorizontal = false; |
|
54 |
btnOpenBrowser.setLayoutData(layoutData); |
|
66 |
btnOpenBrowser.setToolTipText("Open in external browser"); |
|
55 | 67 |
btnOpenBrowser.addSelectionListener(new SelectionAdapter() { |
56 | 68 |
@Override |
57 | 69 |
public void widgetSelected(SelectionEvent e) { |
70 |
String errorTitle = "Invalid URL"; |
|
71 |
String errorText = "Could not open external browser. URL is invalid"; |
|
72 |
|
|
58 | 73 |
URI uri = getUri(); |
59 | 74 |
if(uri!=null){ |
60 | 75 |
try { |
61 | 76 |
PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(uri.toURL()); |
62 |
} catch (PartInitException e1) {
|
|
63 |
// TODO Auto-generated catch block
|
|
64 |
e1.printStackTrace();
|
|
65 |
} catch (MalformedURLException e1) {
|
|
66 |
// TODO Auto-generated catch block
|
|
67 |
e1.printStackTrace();
|
|
77 |
} catch (PartInitException pie) {
|
|
78 |
MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, pie));
|
|
79 |
} catch (MalformedURLException mue) {
|
|
80 |
MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, mue));
|
|
81 |
} catch (IllegalArgumentException iae) {
|
|
82 |
MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, iae));
|
|
68 | 83 |
} |
69 | 84 |
} |
70 | 85 |
} |
71 | 86 |
}); |
87 |
btnOpenBrowser.setLayoutData(LayoutConstants.RIGHT()); |
|
72 | 88 |
|
73 | 89 |
labelException = formFactory.createLabel(layoutComposite, "", SWT.WRAP); |
74 |
labelException.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(3, 1));
|
|
90 |
labelException.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(NUM_COLUMNS, 1));
|
|
75 | 91 |
addControl(labelException); |
76 | 92 |
setUri(initialUri); |
77 | 93 |
} |
Also available in: Unified diff
some layout changes