Skip to main content
summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorBrian Vosburgh2013-04-11 17:45:40 +0000
committerBrian Vosburgh2013-04-16 20:05:26 +0000
commit914293ab2a46228a93b0d450cc4d1ce10813afb6 (patch)
tree4828dea35aafd1a57c28edd9ff90e2b233039634 /common
parentb560d825c446f26712e348f45a12823f1d7f242e (diff)
downloadwebtools.dali-914293ab2a46228a93b0d450cc4d1ce10813afb6.tar.gz
webtools.dali-914293ab2a46228a93b0d450cc4d1ce10813afb6.tar.xz
webtools.dali-914293ab2a46228a93b0d450cc4d1ce10813afb6.zip
rework LabeledControlUpdater -> LabelModelBinding
Diffstat (limited to 'common')
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/META-INF/MANIFEST.MF4
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/draw2d/MultiLineLabelLabelAdapter.java36
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/ControlDecorationLabelAdapter.java51
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/ViewerCellLabelAdapter.java51
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/ButtonLabelAdapter.java35
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/CLabelLabelAdapter.java35
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/CaretLabelAdapter.java49
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/ControlLabelAdapter.java56
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/FormLabelAdapter.java35
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/GroupLabelAdapter.java35
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/HyperlinkLabelAdapter.java35
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/ImageHyperlinkLabelAdapter.java35
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/ItemLabelAdapter.java49
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/LabelLabelAdapter.java35
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/LabelModelBinding.java166
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/LinkLabelAdapter.java35
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/SWTBindTools.java247
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/ScrolledFormLabelAdapter.java35
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/ShellLabelAdapter.java49
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/WidgetLabelAdapter.java37
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/util/LabeledButton.java73
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/util/LabeledControl.java49
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/util/LabeledControlUpdater.java174
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/util/LabeledLabel.java73
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/Pane.java50
-rw-r--r--common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/util/JptUiUtilTests.java4
-rw-r--r--common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/util/LabelModelBindingTest.java92
-rw-r--r--common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/util/LabeledButtonTest.java122
-rw-r--r--common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/util/LabeledControlUpdaterTest.java124
-rw-r--r--common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/util/LabeledLabelTest.java122
30 files changed, 1224 insertions, 769 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.ui/META-INF/MANIFEST.MF b/common/plugins/org.eclipse.jpt.common.ui/META-INF/MANIFEST.MF
index fae37a260e..16874363e4 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/META-INF/MANIFEST.MF
+++ b/common/plugins/org.eclipse.jpt.common.ui/META-INF/MANIFEST.MF
@@ -37,6 +37,10 @@ Export-Package: org.eclipse.jpt.common.ui,
x-friends:="org.eclipse.jpt.jaxb.ui,
org.eclipse.jpt.jpa.db.ui,
org.eclipse.jpt.jpa.ui",
+ org.eclipse.jpt.common.ui.internal.draw2d;
+ x-friends:="org.eclipse.jpt.jaxb.ui,
+ org.eclipse.jpt.jpa.db.ui,
+ org.eclipse.jpt.jpa.ui",
org.eclipse.jpt.common.ui.internal.jface;
x-friends:="org.eclipse.jpt.jaxb.ui,
org.eclipse.jpt.jpa.db.ui,
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/draw2d/MultiLineLabelLabelAdapter.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/draw2d/MultiLineLabelLabelAdapter.java
new file mode 100644
index 0000000000..2860c8d58c
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/draw2d/MultiLineLabelLabelAdapter.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.draw2d;
+
+import org.eclipse.draw2d.widgets.MultiLineLabel;
+import org.eclipse.jpt.common.ui.internal.swt.bind.ControlLabelAdapter;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * Adapt a button to the <em>label</em> interface.
+ * @see MultiLineLabel
+ */
+public final class MultiLineLabelLabelAdapter
+ extends ControlLabelAdapter<MultiLineLabel>
+{
+ public MultiLineLabelLabelAdapter(MultiLineLabel label) {
+ super(label);
+ }
+
+ @Override
+ protected void setImage_(Image image) {
+ this.control.setImage(image);
+ }
+
+ @Override
+ protected void setText_(String text) {
+ this.control.setText(text);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/ControlDecorationLabelAdapter.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/ControlDecorationLabelAdapter.java
new file mode 100644
index 0000000000..110be53049
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/ControlDecorationLabelAdapter.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.jface;
+
+import org.eclipse.jface.fieldassist.ControlDecoration;
+import org.eclipse.jpt.common.ui.internal.swt.bind.WidgetLabelAdapter;
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Control;
+
+/**
+ * Adapt a JFace control decoration to the <em>label</em> interface.
+ * @see ControlDecoration
+ */
+public final class ControlDecorationLabelAdapter
+ implements WidgetLabelAdapter
+{
+ private final ControlDecoration controlDecoration;
+
+ public ControlDecorationLabelAdapter(ControlDecoration controlDecoration) {
+ super();
+ if (controlDecoration == null) {
+ throw new NullPointerException();
+ }
+ this.controlDecoration = controlDecoration;
+ }
+
+ public void setImage(Image image) {
+ this.controlDecoration.setImage(image);
+ }
+
+ public void setText(String text) {
+ this.controlDecoration.setDescriptionText(text);
+ }
+
+ public Control getWidget() {
+ return this.controlDecoration.getControl();
+ }
+
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this, this.controlDecoration);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/ViewerCellLabelAdapter.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/ViewerCellLabelAdapter.java
new file mode 100644
index 0000000000..b39986d726
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/ViewerCellLabelAdapter.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.jface;
+
+import org.eclipse.jface.viewers.ViewerCell;
+import org.eclipse.jpt.common.ui.internal.swt.bind.WidgetLabelAdapter;
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Control;
+
+/**
+ * Adapt a JFace viewer cell to the <em>label</em> interface.
+ * @see ViewerCell
+ */
+public final class ViewerCellLabelAdapter
+ implements WidgetLabelAdapter
+{
+ private final ViewerCell viewerCell;
+
+ public ViewerCellLabelAdapter(ViewerCell viewerCell) {
+ super();
+ if (viewerCell == null) {
+ throw new NullPointerException();
+ }
+ this.viewerCell = viewerCell;
+ }
+
+ public void setImage(Image image) {
+ this.viewerCell.setImage(image);
+ }
+
+ public void setText(String text) {
+ this.viewerCell.setText(text);
+ }
+
+ public Control getWidget() {
+ return this.viewerCell.getControl();
+ }
+
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this, this.viewerCell);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/ButtonLabelAdapter.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/ButtonLabelAdapter.java
new file mode 100644
index 0000000000..28cec05132
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/ButtonLabelAdapter.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.swt.bind;
+
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Button;
+
+/**
+ * Adapt a button to the <em>label</em> interface.
+ * @see Button
+ */
+final class ButtonLabelAdapter
+ extends ControlLabelAdapter<Button>
+{
+ public ButtonLabelAdapter(Button button) {
+ super(button);
+ }
+
+ @Override
+ protected void setImage_(Image image) {
+ this.control.setImage(image);
+ }
+
+ @Override
+ protected void setText_(String text) {
+ this.control.setText(text);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/CLabelLabelAdapter.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/CLabelLabelAdapter.java
new file mode 100644
index 0000000000..1ae5197551
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/CLabelLabelAdapter.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.swt.bind;
+
+import org.eclipse.swt.custom.CLabel;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * Adapt a "custom" label to the <em>label</em> interface.
+ * @see CLabel
+ */
+final class CLabelLabelAdapter
+ extends ControlLabelAdapter<CLabel>
+{
+ public CLabelLabelAdapter(CLabel label) {
+ super(label);
+ }
+
+ @Override
+ protected void setImage_(Image image) {
+ this.control.setImage(image);
+ }
+
+ @Override
+ protected void setText_(String text) {
+ this.control.setText(text);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/CaretLabelAdapter.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/CaretLabelAdapter.java
new file mode 100644
index 0000000000..482a213560
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/CaretLabelAdapter.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.swt.bind;
+
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Caret;
+
+/**
+ * Adapt a caret to the <em>label</em> interface (image-only support).
+ * @see Caret
+ */
+final class CaretLabelAdapter
+ implements WidgetLabelAdapter
+{
+ private final Caret caret;
+
+ public CaretLabelAdapter(Caret caret) {
+ super();
+ if (caret == null) {
+ throw new NullPointerException();
+ }
+ this.caret = caret;
+ }
+
+ public void setImage(Image image) {
+ this.caret.setImage(image);
+ }
+
+ public void setText(String text) {
+ // NOP
+ }
+
+ public Caret getWidget() {
+ return this.caret;
+ }
+
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this, this.caret);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/ControlLabelAdapter.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/ControlLabelAdapter.java
new file mode 100644
index 0000000000..251b49878d
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/ControlLabelAdapter.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.swt.bind;
+
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Control;
+
+/**
+ * Adapt a control to the <em>label</em> interface (text-only support).
+ * @param <C> the type of control to be adapted
+ * @see Control
+ */
+public abstract class ControlLabelAdapter<C extends Control>
+ implements WidgetLabelAdapter
+{
+ protected final C control;
+
+ protected ControlLabelAdapter(C control) {
+ super();
+ if (control == null) {
+ throw new NullPointerException();
+ }
+ this.control = control;
+ }
+
+ public final void setImage(Image image) {
+ this.setImage_(image);
+ this.control.getParent().layout(true);
+ }
+
+ protected abstract void setImage_(Image image);
+
+ public final void setText(String text) {
+ this.setText_(text);
+ this.control.getParent().layout(true);
+ }
+
+ protected abstract void setText_(String text);
+
+ public C getWidget() {
+ return this.control;
+ }
+
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this, this.control);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/FormLabelAdapter.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/FormLabelAdapter.java
new file mode 100644
index 0000000000..29d15c2e80
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/FormLabelAdapter.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.swt.bind;
+
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.forms.widgets.Form;
+
+/**
+ * Adapt a form to the <em>label</em> interface.
+ * @see Form
+ */
+final class FormLabelAdapter
+ extends ControlLabelAdapter<Form>
+{
+ public FormLabelAdapter(Form form) {
+ super(form);
+ }
+
+ @Override
+ protected void setImage_(Image image) {
+ this.control.setImage(image);
+ }
+
+ @Override
+ protected void setText_(String text) {
+ this.control.setText(text);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/GroupLabelAdapter.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/GroupLabelAdapter.java
new file mode 100644
index 0000000000..4b8f14aafb
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/GroupLabelAdapter.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.swt.bind;
+
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Group;
+
+/**
+ * Adapt a group to the <em>label</em> interface (text-only support).
+ * @see Group
+ */
+final class GroupLabelAdapter
+ extends ControlLabelAdapter<Group>
+{
+ public GroupLabelAdapter(Group group) {
+ super(group);
+ }
+
+ @Override
+ protected void setImage_(Image image) {
+ // NOP
+ }
+
+ @Override
+ protected void setText_(String text) {
+ this.control.setText(text);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/HyperlinkLabelAdapter.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/HyperlinkLabelAdapter.java
new file mode 100644
index 0000000000..6275e13387
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/HyperlinkLabelAdapter.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.swt.bind;
+
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.forms.widgets.Hyperlink;
+
+/**
+ * Adapt a hyperlink to the <em>label</em> interface (text-only support).
+ * @see Hyperlink
+ */
+final class HyperlinkLabelAdapter
+ extends ControlLabelAdapter<Hyperlink>
+{
+ public HyperlinkLabelAdapter(Hyperlink hyperlink) {
+ super(hyperlink);
+ }
+
+ @Override
+ public void setImage_(Image image) {
+ // NOP
+ }
+
+ @Override
+ protected void setText_(String text) {
+ this.control.setText(text);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/ImageHyperlinkLabelAdapter.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/ImageHyperlinkLabelAdapter.java
new file mode 100644
index 0000000000..58324166b3
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/ImageHyperlinkLabelAdapter.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.swt.bind;
+
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.forms.widgets.ImageHyperlink;
+
+/**
+ * Adapt an image hyperlink to the <em>label</em> interface.
+ * @see ImageHyperlink
+ */
+final class ImageHyperlinkLabelAdapter
+ extends ControlLabelAdapter<ImageHyperlink>
+{
+ public ImageHyperlinkLabelAdapter(ImageHyperlink hyperlink) {
+ super(hyperlink);
+ }
+
+ @Override
+ protected void setImage_(Image image) {
+ this.control.setImage(image);
+ }
+
+ @Override
+ protected void setText_(String text) {
+ this.control.setText(text);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/ItemLabelAdapter.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/ItemLabelAdapter.java
new file mode 100644
index 0000000000..0a02be6e61
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/ItemLabelAdapter.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.swt.bind;
+
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Item;
+
+/**
+ * Adapt an item to the <em>label</em> interface.
+ * @see Item
+ */
+final class ItemLabelAdapter
+ implements WidgetLabelAdapter
+{
+ private final Item item;
+
+ public ItemLabelAdapter(Item item) {
+ super();
+ if (item == null) {
+ throw new NullPointerException();
+ }
+ this.item = item;
+ }
+
+ public void setImage(Image image) {
+ this.item.setImage(image);
+ }
+
+ public void setText(String text) {
+ this.item.setText(text);
+ }
+
+ public Item getWidget() {
+ return this.item;
+ }
+
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this, this.item);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/LabelLabelAdapter.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/LabelLabelAdapter.java
new file mode 100644
index 0000000000..9695a88a13
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/LabelLabelAdapter.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.swt.bind;
+
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Label;
+
+/**
+ * Adapt a label to the <em>label</em> interface.
+ * @see Label
+ */
+final class LabelLabelAdapter
+ extends ControlLabelAdapter<Label>
+{
+ public LabelLabelAdapter(Label label) {
+ super(label);
+ }
+
+ @Override
+ protected void setImage_(Image image) {
+ this.control.setImage(image);
+ }
+
+ @Override
+ protected void setText_(String text) {
+ this.control.setText(text);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/LabelModelBinding.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/LabelModelBinding.java
new file mode 100644
index 0000000000..9600966115
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/LabelModelBinding.java
@@ -0,0 +1,166 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.swt.bind;
+
+import org.eclipse.jpt.common.ui.internal.listeners.SWTPropertyChangeListenerWrapper;
+import org.eclipse.jpt.common.ui.internal.swt.events.DisposeAdapter;
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.common.utility.model.listener.PropertyChangeAdapter;
+import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Widget;
+
+/**
+ * This binding can be used to keep a <em>label</em>
+ * synchronized with a image and text models.
+ *
+ * @see PropertyValueModel
+ * @see WidgetLabelAdapter
+ */
+class LabelModelBinding {
+
+ // ***** model
+ /** A value model on the underlying model image. */
+ private final PropertyValueModel<Image> imageModel;
+
+ /**
+ * A listener that allows us to synchronize the label's image with
+ * the model image.
+ */
+ private final PropertyChangeListener imageListener;
+
+ /** A value model on the underlying model text. */
+ private final PropertyValueModel<String> textModel;
+
+ /**
+ * A listener that allows us to synchronize the label's text with
+ * the model text.
+ */
+ private final PropertyChangeListener textListener;
+
+ // ***** UI
+ /** The <em>label</em> we synchronize with the image and text models. */
+ private final WidgetLabelAdapter labelAdapter;
+
+ /**
+ * A listener that allows us to stop listening to stuff when the widget
+ * is disposed. (Critical for preventing memory leaks.)
+ */
+ private final DisposeListener widgetDisposeListener;
+
+
+ // ********** construction **********
+
+ /**
+ * Constructor - the models and label adapter are required.
+ */
+ LabelModelBinding(PropertyValueModel<Image> imageModel, PropertyValueModel<String> textModel, WidgetLabelAdapter labelAdapter) {
+ super();
+ if ((imageModel == null) || (textModel == null) || (labelAdapter == null)) {
+ throw new NullPointerException();
+ }
+ this.imageModel = imageModel;
+ this.textModel = textModel;
+ this.labelAdapter = labelAdapter;
+
+ this.imageListener = this.buildImageListener();
+ this.imageModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.imageListener);
+
+ this.textListener = this.buildTextListener();
+ this.textModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.textListener);
+
+ this.widgetDisposeListener = this.buildWidgetDisposeListener();
+ this.getWidget().addDisposeListener(this.widgetDisposeListener);
+
+ this.setImage(this.imageModel.getValue());
+ this.setText(this.textModel.getValue());
+ }
+
+ private PropertyChangeListener buildImageListener() {
+ return new SWTPropertyChangeListenerWrapper(new ImageListener());
+ }
+
+ /* CU private */ class ImageListener
+ extends PropertyChangeAdapter
+ {
+ @Override
+ public void propertyChanged(PropertyChangeEvent event) {
+ LabelModelBinding.this.setImage((Image) event.getNewValue());
+ }
+ }
+
+ private PropertyChangeListener buildTextListener() {
+ return new SWTPropertyChangeListenerWrapper(new TextListener());
+ }
+
+ /* CU private */ class TextListener
+ extends PropertyChangeAdapter
+ {
+ @Override
+ public void propertyChanged(PropertyChangeEvent event) {
+ LabelModelBinding.this.setText((String) event.getNewValue());
+ }
+ }
+
+ private DisposeListener buildWidgetDisposeListener() {
+ return new WidgetDisposeListener();
+ }
+
+ /* CU private */ class WidgetDisposeListener
+ extends DisposeAdapter
+ {
+ @Override
+ public void widgetDisposed(DisposeEvent event) {
+ LabelModelBinding.this.widgetDisposed();
+ }
+ }
+
+
+ // ********** model events **********
+
+ /* CU private */ void setImage(Image image) {
+ if ( ! this.getWidget().isDisposed()) {
+ this.labelAdapter.setImage(image);
+ }
+ }
+
+ /* CU private */ void setText(String text) {
+ if ( ! this.getWidget().isDisposed()) {
+ this.labelAdapter.setText(text);
+ }
+ }
+
+ private Widget getWidget() {
+ return this.labelAdapter.getWidget();
+ }
+
+
+ // ********** UI events **********
+
+ /* CU private */ void widgetDisposed() {
+ // the widget is not yet "disposed" when we receive this event
+ // so we can still remove our listener
+ this.getWidget().removeDisposeListener(this.widgetDisposeListener);
+ this.imageModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.imageListener);
+ this.textModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.imageListener);
+ }
+
+
+ // ********** misc **********
+
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this, this.textModel);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/LinkLabelAdapter.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/LinkLabelAdapter.java
new file mode 100644
index 0000000000..9b8cc80b54
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/LinkLabelAdapter.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.swt.bind;
+
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Link;
+
+/**
+ * Adapt a link to the <em>label</em> interface (text-only support).
+ * @see Link
+ */
+final class LinkLabelAdapter
+ extends ControlLabelAdapter<Link>
+{
+ public LinkLabelAdapter(Link link) {
+ super(link);
+ }
+
+ @Override
+ public void setImage_(Image image) {
+ // NOP
+ }
+
+ @Override
+ protected void setText_(String text) {
+ this.control.setText(text);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/SWTBindTools.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/SWTBindTools.java
index 5dcbc7054d..89bbfff567 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/SWTBindTools.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/SWTBindTools.java
@@ -12,6 +12,7 @@ package org.eclipse.jpt.common.ui.internal.swt.bind;
import java.util.Arrays;
import org.eclipse.jpt.common.utility.internal.BitTools;
import org.eclipse.jpt.common.utility.internal.model.value.ModifiablePropertyCollectionValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.NullPropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.StaticCollectionValueModel;
import org.eclipse.jpt.common.utility.internal.transformer.TransformerTools;
import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
@@ -21,12 +22,24 @@ import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.common.utility.transformer.Transformer;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CLabel;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Caret;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Item;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.List;
+import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Widget;
+import org.eclipse.ui.forms.widgets.Form;
+import org.eclipse.ui.forms.widgets.Hyperlink;
+import org.eclipse.ui.forms.widgets.ImageHyperlink;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.part.PageBook;
@@ -36,6 +49,240 @@ import org.eclipse.ui.part.PageBook;
@SuppressWarnings("nls")
public final class SWTBindTools {
+ // ********** "label" **********
+
+ /**
+ * Bind the specified button's label to the specified image model.
+ */
+ public static void bindImageLabel(PropertyValueModel<Image> imageModel, Button button) {
+ bindImage(imageModel, new ButtonLabelAdapter(button));
+ }
+
+ /**
+ * Bind the specified button's label to the specified text model.
+ */
+ public static void bindTextLabel(PropertyValueModel<String> textModel, Button button) {
+ bindText(textModel, new ButtonLabelAdapter(button));
+ }
+
+ /**
+ * Bind the specified button's label to the specified image and
+ * text models.
+ */
+ public static void bindLabel(PropertyValueModel<Image> imageModel, PropertyValueModel<String> textModel, Button button) {
+ bind(imageModel, textModel, new ButtonLabelAdapter(button));
+ }
+
+ /**
+ * Bind the specified "custom" label to the specified image model.
+ */
+ public static void bindImageLabel(PropertyValueModel<Image> imageModel, CLabel label) {
+ bindImage(imageModel, new CLabelLabelAdapter(label));
+ }
+
+ /**
+ * Bind the specified "custom" label to the specified text model.
+ */
+ public static void bindTextLabel(PropertyValueModel<String> textModel, CLabel label) {
+ bindText(textModel, new CLabelLabelAdapter(label));
+ }
+
+ /**
+ * Bind the specified "custom" label to the specified image and
+ * text models.
+ */
+ public static void bindLabel(PropertyValueModel<Image> imageModel, PropertyValueModel<String> textModel, CLabel label) {
+ bind(imageModel, textModel, new CLabelLabelAdapter(label));
+ }
+
+ /**
+ * Bind the specified form's label to the specified image model.
+ */
+ public static void bindImageLabel(PropertyValueModel<Image> imageModel, Form form) {
+ bindImage(imageModel, new FormLabelAdapter(form));
+ }
+
+ /**
+ * Bind the specified form's label to the specified text model.
+ */
+ public static void bindTextLabel(PropertyValueModel<String> textModel, Form form) {
+ bindText(textModel, new FormLabelAdapter(form));
+ }
+
+ /**
+ * Bind the specified form's label to the specified image and
+ * text models.
+ */
+ public static void bindLabel(PropertyValueModel<Image> imageModel, PropertyValueModel<String> textModel, Form form) {
+ bind(imageModel, textModel, new FormLabelAdapter(form));
+ }
+
+ /**
+ * Bind the specified hyperlink's label to the specified image model.
+ */
+ public static void bindImageLabel(PropertyValueModel<Image> imageModel, ImageHyperlink hyperlink) {
+ bindImage(imageModel, new ImageHyperlinkLabelAdapter(hyperlink));
+ }
+
+ /**
+ * Bind the specified hyperlink's label to the specified text model.
+ */
+ public static void bindTextLabel(PropertyValueModel<String> textModel, ImageHyperlink hyperlink) {
+ bindText(textModel, new ImageHyperlinkLabelAdapter(hyperlink));
+ }
+
+ /**
+ * Bind the specified hyperlink's label to the specified image and
+ * text models.
+ */
+ public static void bindLabel(PropertyValueModel<Image> imageModel, PropertyValueModel<String> textModel, ImageHyperlink hyperlink) {
+ bind(imageModel, textModel, new ImageHyperlinkLabelAdapter(hyperlink));
+ }
+
+ /**
+ * Bind the specified label to the specified image model.
+ */
+ public static void bindImageLabel(PropertyValueModel<Image> imageModel, Label label) {
+ bindImage(imageModel, new LabelLabelAdapter(label));
+ }
+
+ /**
+ * Bind the specified label to the specified text model.
+ */
+ public static void bindTextLabel(PropertyValueModel<String> textModel, Label label) {
+ bindText(textModel, new LabelLabelAdapter(label));
+ }
+
+ /**
+ * Bind the specified label to the specified image and
+ * text models.
+ */
+ public static void bindLabel(PropertyValueModel<Image> imageModel, PropertyValueModel<String> textModel, Label label) {
+ bind(imageModel, textModel, new LabelLabelAdapter(label));
+ }
+
+ /**
+ * Bind the specified form's label to the specified image model.
+ */
+ public static void bindImageLabel(PropertyValueModel<Image> imageModel, ScrolledForm form) {
+ bindImage(imageModel, new ScrolledFormLabelAdapter(form));
+ }
+
+ /**
+ * Bind the specified form's label to the specified text models.
+ */
+ public static void bindTextLabel(PropertyValueModel<String> textModel, ScrolledForm form) {
+ bindText(textModel, new ScrolledFormLabelAdapter(form));
+ }
+
+ /**
+ * Bind the specified form's label to the specified image and
+ * text models.
+ */
+ public static void bindLabel(PropertyValueModel<Image> imageModel, PropertyValueModel<String> textModel, ScrolledForm form) {
+ bind(imageModel, textModel, new ScrolledFormLabelAdapter(form));
+ }
+
+ /**
+ * Bind the specified item's label to the specified image model.
+ */
+ public static void bindImageLabel(PropertyValueModel<Image> imageModel, Item item) {
+ bindImage(imageModel, new ItemLabelAdapter(item));
+ }
+
+ /**
+ * Bind the specified item's label to the specified text model.
+ */
+ public static void bindTextLabel(PropertyValueModel<String> textModel, Item item) {
+ bindText(textModel, new ItemLabelAdapter(item));
+ }
+
+ /**
+ * Bind the specified item's label to the specified image and
+ * text models.
+ */
+ public static void bindLabel(PropertyValueModel<Image> imageModel, PropertyValueModel<String> textModel, Item item) {
+ bind(imageModel, textModel, new ItemLabelAdapter(item));
+ }
+
+ /**
+ * Bind the specified window's label to the specified image model.
+ */
+ public static void bindImageLabel(PropertyValueModel<Image> imageModel, Shell window) {
+ bindImage(imageModel, new ShellLabelAdapter(window));
+ }
+
+ /**
+ * Bind the specified window's label to the specified text model.
+ */
+ public static void bindLabel(PropertyValueModel<String> textModel, Shell window) {
+ bindText(textModel, new ShellLabelAdapter(window));
+ }
+
+ /**
+ * Bind the specified window's label to the specified image and
+ * text models.
+ */
+ public static void bindLabel(PropertyValueModel<Image> imageModel, PropertyValueModel<String> textModel, Shell window) {
+ bind(imageModel, textModel, new ShellLabelAdapter(window));
+ }
+
+ /**
+ * Bind the specified caret to the specified image model.
+ */
+ public static void bindLabel(PropertyValueModel<Image> imageModel, Caret caret) {
+ bindImage(imageModel, new CaretLabelAdapter(caret));
+ }
+
+ /**
+ * Bind the specified group's text to the specified text model.
+ */
+ public static void bindLabel(PropertyValueModel<String> textModel, Group group) {
+ bindText(textModel, new GroupLabelAdapter(group));
+ }
+
+ /**
+ * Bind the specified hyperlink's text to the specified text model.
+ */
+ public static void bindLabel(PropertyValueModel<String> textModel, Hyperlink hyperlink) {
+ bindText(textModel, new HyperlinkLabelAdapter(hyperlink));
+ }
+
+ /**
+ * Bind the specified link's text to the specified text model.
+ */
+ public static void bindLabel(PropertyValueModel<String> textModel, Link link) {
+ bindText(textModel, new LinkLabelAdapter(link));
+ }
+
+ /**
+ * Bind the specified label adapter's widget's label to the specified
+ * image model.
+ */
+ @SuppressWarnings("unused")
+ public static void bindImage(PropertyValueModel<Image> imageModel, WidgetLabelAdapter labelAdapter) {
+ new LabelModelBinding(imageModel, new NullPropertyValueModel<String>(), labelAdapter);
+ }
+
+ /**
+ * Bind the specified label adapter's widget's label to the specified
+ * text model.
+ */
+ @SuppressWarnings("unused")
+ public static void bindText(PropertyValueModel<String> textModel, WidgetLabelAdapter labelAdapter) {
+ new LabelModelBinding(new NullPropertyValueModel<Image>(), textModel, labelAdapter);
+ }
+
+ /**
+ * Bind the specified label adapter's widget's label to the specified
+ * image and text models.
+ */
+ @SuppressWarnings("unused")
+ public static void bind(PropertyValueModel<Image> imageModel, PropertyValueModel<String> textModel, WidgetLabelAdapter labelAdapter) {
+ new LabelModelBinding(imageModel, textModel, labelAdapter);
+ }
+
+
// ********** check-box/radio button/toggle button **********
/**
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/ScrolledFormLabelAdapter.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/ScrolledFormLabelAdapter.java
new file mode 100644
index 0000000000..1467887ecd
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/ScrolledFormLabelAdapter.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.swt.bind;
+
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
+
+/**
+ * Adapt a scrolled form to the <em>label</em> interface.
+ * @see ScrolledForm
+ */
+final class ScrolledFormLabelAdapter
+ extends ControlLabelAdapter<ScrolledForm>
+{
+ public ScrolledFormLabelAdapter(ScrolledForm form) {
+ super(form);
+ }
+
+ @Override
+ protected void setImage_(Image image) {
+ this.control.setImage(image);
+ }
+
+ @Override
+ protected void setText_(String text) {
+ this.control.setText(text);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/ShellLabelAdapter.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/ShellLabelAdapter.java
new file mode 100644
index 0000000000..a4f6051fe2
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/ShellLabelAdapter.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.swt.bind;
+
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * Adapt a shell (window) to the <em>label</em> interface.
+ * @see Shell
+ */
+final class ShellLabelAdapter
+ implements WidgetLabelAdapter
+{
+ private final Shell shell;
+
+ public ShellLabelAdapter(Shell shell) {
+ super();
+ if (shell == null) {
+ throw new NullPointerException();
+ }
+ this.shell = shell;
+ }
+
+ public void setImage(Image image) {
+ this.shell.setImage(image);
+ }
+
+ public void setText(String text) {
+ this.shell.setText(text);
+ }
+
+ public Shell getWidget() {
+ return this.shell;
+ }
+
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this, this.shell);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/WidgetLabelAdapter.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/WidgetLabelAdapter.java
new file mode 100644
index 0000000000..4aed15d77d
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/WidgetLabelAdapter.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.swt.bind;
+
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Widget;
+
+/**
+ * A interface used to bind all the various <em>label</em> implementations to
+ * models.
+ * @see SWTBindTools#bind(org.eclipse.jpt.common.utility.model.value.PropertyValueModel, org.eclipse.jpt.common.utility.model.value.PropertyValueModel, WidgetLabelAdapter)
+ */
+public interface WidgetLabelAdapter {
+ /**
+ * Set the widget's image.
+ * Pre-condition: The adapter's widget is not disposed.
+ */
+ void setImage(Image image);
+
+ /**
+ * Set the widget's text.
+ * Pre-condition: The adapter's widget is not disposed.
+ */
+ void setText(String text);
+
+ /**
+ * Return the adapted widget.
+ */
+ Widget getWidget();
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/util/LabeledButton.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/util/LabeledButton.java
deleted file mode 100644
index 260fe25b3f..0000000000
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/util/LabeledButton.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2012 Oracle. All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: Oracle. - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.common.ui.internal.util;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Button;
-
-/**
- * A default implementation of <code>LabeledControl</code> that updates a
- * <code>Button</code> when required.
- *
- * @version 3.3
- * @since 2.0
- */
-@SuppressWarnings("nls")
-public final class LabeledButton implements LabeledControl
-{
- /**
- * The button to be updated with a different icon and text.
- */
- private final Button button;
-
- /**
- * Creates a new <code>LabeledButton</code>.
- *
- * @param button The button that will have its text and icon updated when
- * required
- * @exception AssertionFailedException If the given <code>Button</code> is
- * <code>null</code>
- */
- public LabeledButton(Button button) {
- super();
-
- Assert.isNotNull(button, "The button cannot be null");
- this.button = button;
- }
-
- public void addDisposeListener(DisposeListener disposeListener) {
- this.button.addDisposeListener(disposeListener);
- }
-
- public void removeDisposeListener(DisposeListener disposeListener) {
- this.button.removeDisposeListener(disposeListener);
- }
-
- /*
- * (non-Javadoc)
- */
- public void setImage(Image image) {
- if (!this.button.isDisposed()) {
- this.button.setImage(image);
- this.button.getParent().layout(true);
- }
- }
-
- /*
- * (non-Javadoc)
- */
- public void setText(String text) {
- if (!this.button.isDisposed()) {
- this.button.setText(text);
- this.button.getParent().layout(true);
- }
- }
-}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/util/LabeledControl.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/util/LabeledControl.java
deleted file mode 100644
index 07d6e76acd..0000000000
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/util/LabeledControl.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2012 Oracle. All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: Oracle. - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.common.ui.internal.util;
-
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.graphics.Image;
-
-/**
- * This <code>LabeledControl</code> is used to encapsulate a widget and update
- * its properties (icon and text).
- *
- * @see LabeledButton
- * @see LabeledLabel
- *
- * @version 3.3
- * @since 2.0
- */
-public interface LabeledControl {
- /**
- * Passes the image so the wrapped component can receive it.
- *
- * @param image The new <code>Image</code>
- */
- void setImage(Image image);
-
- /**
- * Passes the text so the wrapped component can receive it.
- *
- * @param text The new text
- */
- void setText(String text);
-
- /**
- * Convenience method: Adds a dispose listener to the check box.
- * The source of any events sent to the listener will be the wrapped control.
- */
- void addDisposeListener(DisposeListener disposeListener);
-
- /**
- * Convenience method: Removes a dispose listener from the wrapped control.
- */
- void removeDisposeListener(DisposeListener disposeListener);
-}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/util/LabeledControlUpdater.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/util/LabeledControlUpdater.java
deleted file mode 100644
index 62bba80842..0000000000
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/util/LabeledControlUpdater.java
+++ /dev/null
@@ -1,174 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2012 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.ui.internal.util;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.jpt.common.ui.internal.listeners.SWTPropertyChangeListenerWrapper;
-import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
-import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.graphics.Image;
-
-/**
- * This updater is responsible to update the <code>LabeledControl</code> when
- * the text and the icon need to change.
- *
- * @version 3.3
- * @since 2.0
- */
-@SuppressWarnings("nls")
-public final class LabeledControlUpdater {
-
- /**
- * The wrapper around a control that has text and icon.
- */
- private LabeledControl labeledControl;
-
- /**
- * A listener that allows us to stop listening to stuff when the control
- * is disposed. (Critical for preventing memory leaks.)
- */
- protected DisposeListener disposeListener;
-
- /** A value model on the underlying model text. */
- protected final PropertyValueModel<String> textModel;
-
- protected PropertyChangeListener textListener;
-
- /** A value model on the underlying model image. */
- protected final PropertyValueModel<Image> imageModel;
-
- protected PropertyChangeListener imageListener;
-
- /**
- * Creates a new <code>LabeledControlUpdater</code>.
- *
- * @param labeledControl The wrapper around the control that needs to
- * have its text updated
- * @param textModel The holder this class will listen for changes
- */
- public LabeledControlUpdater(LabeledControl labeledControl,
- PropertyValueModel<String> textModel)
- {
- this(labeledControl, textModel, null);
- }
-
- /**
- * Creates a new <code>LabeledControlUpdater</code>.
- *
- * @param labeledControl The wrapper around the control that needs to
- * have its image and text updated
- * @param imageModel The holder this class will listen for changes or
- * <code>null</code> if the text never changes
- * @param textModel The holder this class will listen for changes or
- * <code>null</code> if the image never changes
- */
- public LabeledControlUpdater(LabeledControl labeledControl,
- PropertyValueModel<String> textModel,
- PropertyValueModel<Image> imageModel)
- {
- super();
- Assert.isNotNull(labeledControl, "The LabeledControl cannot be null");
- this.labeledControl = labeledControl;
- this.textModel = textModel;
- this.imageModel = imageModel;
-
- if (this.textModel != null) {
- this.textListener = this.buildTextListener();
- this.textModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.textListener);
- this.setText(this.textModel.getValue());
- }
-
- if (this.imageModel != null) {
- this.imageListener = this.buildImageListener();
- this.imageModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.imageListener);
- this.setImage(this.imageModel.getValue());
- }
-
- this.disposeListener = this.buildDisposeListener();
- this.labeledControl.addDisposeListener(this.disposeListener);
- }
-
- private PropertyChangeListener buildImageListener() {
- return new SWTPropertyChangeListenerWrapper(this.buildImageListener_());
- }
-
- private PropertyChangeListener buildImageListener_() {
- return new PropertyChangeListener() {
- public void propertyChanged(PropertyChangeEvent e) {
- LabeledControlUpdater.this.setImage((Image) e.getNewValue());
- }
-
- @Override
- public String toString() {
- return "LabeledControlUpdater.imageListener";
- }
- };
- }
-
- private PropertyChangeListener buildTextListener() {
- return new SWTPropertyChangeListenerWrapper(buildTextListener_());
- }
-
- private PropertyChangeListener buildTextListener_() {
- return new PropertyChangeListener() {
- public void propertyChanged(PropertyChangeEvent e) {
- LabeledControlUpdater.this.setText((String) e.getNewValue());
- }
-
- @Override
- public String toString() {
- return "LabeledControlUpdater.textListener";
- }
- };
- }
-
- private void setImage(Image image) {
- this.labeledControl.setImage(image);
- }
-
- private void setText(String text) {
- if (text == null) {
- text = "";
- }
-
- this.labeledControl.setText(text);
- }
-
- // ********** dispose **********
-
- private void controlDisposed(@SuppressWarnings("unused") DisposeEvent event) {
- // the control is not yet "disposed" when we receive this event
- // so we can still remove our listeners
- this.labeledControl.removeDisposeListener(this.disposeListener);
-
- if (this.imageModel != null) {
- this.imageModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.imageListener);
- }
-
- if (this.textModel != null) {
- this.textModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.textListener);
- }
- }
-
- private DisposeListener buildDisposeListener() {
- return new DisposeListener() {
- public void widgetDisposed(DisposeEvent event) {
- LabeledControlUpdater.this.controlDisposed(event);
- }
- @Override
- public String toString() {
- return "LabeledControlUpdater.disposeListener";
- }
- };
- }
-} \ No newline at end of file
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/util/LabeledLabel.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/util/LabeledLabel.java
deleted file mode 100644
index 32a7d014db..0000000000
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/util/LabeledLabel.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2012 Oracle. All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: Oracle. - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.common.ui.internal.util;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Label;
-
-/**
- * A default implementation of <code>LabeledControl</code> that updates an
- * <code>Label</code> when required.
- *
- * @version 3.3
- * @since 2.0
- */
-@SuppressWarnings("nls")
-public final class LabeledLabel implements LabeledControl
-{
- /**
- * The label to be updated with a different icon and text.
- */
- private final Label label;
-
- /**
- * Creates a new <code>LabeledButton</code>.
- *
- * @param label The label that will have its text and icon updated when
- * required
- * @exception AssertionFailedException If the given <code>Label</code> is
- * <code>null</code>
- */
- public LabeledLabel(Label label) {
- super();
-
- Assert.isNotNull(label, "The label cannot be null");
- this.label = label;
- }
-
- public void addDisposeListener(DisposeListener disposeListener) {
- this.label.addDisposeListener(disposeListener);
- }
-
- public void removeDisposeListener(DisposeListener disposeListener) {
- this.label.removeDisposeListener(disposeListener);
- }
-
- /*
- * (non-Javadoc)
- */
- public void setImage(Image image) {
- if (!this.label.isDisposed()) {
- this.label.setImage(image);
- this.label.getParent().layout(true);
- }
- }
-
- /*
- * (non-Javadoc)
- */
- public void setText(String text) {
- if (!this.label.isDisposed()) {
- this.label.setText(text);
- this.label.getParent().layout(true);
- }
- }
-}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/Pane.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/Pane.java
index bd4706bc67..b46a942bcf 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/Pane.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/Pane.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2013 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -27,8 +27,6 @@ import org.eclipse.jpt.common.ui.internal.swt.SpinnerModelAdapter;
import org.eclipse.jpt.common.ui.internal.swt.TriStateCheckBoxModelAdapter;
import org.eclipse.jpt.common.ui.internal.swt.bind.SWTBindTools;
import org.eclipse.jpt.common.ui.internal.swt.events.DisposeAdapter;
-import org.eclipse.jpt.common.ui.internal.util.LabeledButton;
-import org.eclipse.jpt.common.ui.internal.util.LabeledControlUpdater;
import org.eclipse.jpt.common.utility.internal.model.value.CompositeBooleanPropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.StaticPropertyValueModel;
@@ -1292,19 +1290,19 @@ public abstract class Pane<T extends Model> {
* Creates a new <code>Text</code> widget that has multiple lines.
*
* @param container The parent container
- * @param textHolder The holder of the text field's input
+ * @param textModel The holder of the text field's input
* @param helpId The topic help ID to be registered for the new text
* @return The newly created <code>Text</code> widget
*
* @category Layout
*/
protected final Text addMultiLineText(Composite container,
- ModifiablePropertyValueModel<String> textHolder,
+ ModifiablePropertyValueModel<String> textModel,
int lineCount,
String helpId) {
Text text = this.addMultiLineText(container, lineCount, helpId);
- SWTBindTools.bind(textHolder, text);
+ SWTBindTools.bind(textModel, text);
return text;
}
@@ -1373,16 +1371,16 @@ public abstract class Pane<T extends Model> {
* Creates a new <code>Text</code> widget.
*
* @param container The parent container
- * @param textHolder The holder of the text field's input
+ * @param textModel The holder of the text field's input
* @return The newly created <code>Text</code> widget
*
* @category Layout
*/
protected final Text addPasswordText(Composite container,
- ModifiablePropertyValueModel<String> textHolder) {
+ ModifiablePropertyValueModel<String> textModel) {
Text text = this.addPasswordText(container);
- SWTBindTools.bind(textHolder, text);
+ SWTBindTools.bind(textModel, text);
return text;
}
@@ -1840,18 +1838,18 @@ public abstract class Pane<T extends Model> {
* Creates a new <code>Text</code> widget.
*
* @param container The parent container
- * @param textHolder The holder of the text field's input
+ * @param textModel The holder of the text field's input
* @param helpId The topic help ID to be registered for the new text
* @return The newly created <code>Text</code> widget
*
* @category Layout
*/
protected final Text addText(Composite container,
- ModifiablePropertyValueModel<String> textHolder,
+ ModifiablePropertyValueModel<String> textModel,
String helpId) {
Text text = this.addText(container, helpId);
- SWTBindTools.bind(textHolder, text);
+ SWTBindTools.bind(textModel, text);
return text;
}
@@ -1873,18 +1871,18 @@ public abstract class Pane<T extends Model> {
* The owning object will handle it with its own PaneEnabler or ControlEnabler.
*
* @param container The parent container
- * @param textHolder The holder of the text field's input
+ * @param textModel The holder of the text field's input
* @param helpId The topic help ID to be registered for the new text
* @return The newly created <code>Text</code> widget
*
* @category Layout
*/
private Text addUnmanagedText(Composite container,
- ModifiablePropertyValueModel<String> textHolder,
+ ModifiablePropertyValueModel<String> textModel,
String helpId) {
Text text = this.addUnmanagedText(container, helpId);
- SWTBindTools.bind(textHolder, text);
+ SWTBindTools.bind(textModel, text);
return text;
}
@@ -1963,7 +1961,7 @@ public abstract class Pane<T extends Model> {
*
* @param parent The parent container
* @param buttonText The button's text
- * @param booleanHolder The holder of the selection state
+ * @param booleanModel The holder of the selection state
* @param helpId The topic help ID to be registered for the new button
* @return The newly created <code>Button</code>
*
@@ -1972,7 +1970,7 @@ public abstract class Pane<T extends Model> {
private Button addUnmanagedToggleButton(
Composite parent,
String buttonText,
- ModifiablePropertyValueModel<Boolean> booleanHolder,
+ ModifiablePropertyValueModel<Boolean> booleanModel,
String helpId,
int toggleButtonType) {
@@ -1992,7 +1990,7 @@ public abstract class Pane<T extends Model> {
}
button.setLayoutData(new GridData());
- SWTBindTools.bind(booleanHolder, button);
+ SWTBindTools.bind(booleanModel, button);
if (helpId != null) {
this.setHelp(button, helpId);
@@ -2086,7 +2084,7 @@ public abstract class Pane<T extends Model> {
* @param text The button's text
* @param booleanHolder The holder of the boolean value where <code>null</code>
* means partially selected
- * @param stringHolder The holder of the string to put in parenthesis after
+ * @param textModel The holder of the string to put in parenthesis after
* the check box's text when it is partially selected
* @param helpId The topic help ID to be registered for the new check box
* @return The newly created <code>TriStateCheckBox</code>
@@ -2096,7 +2094,7 @@ public abstract class Pane<T extends Model> {
protected final TriStateCheckBox addTriStateCheckBoxWithDefault(Composite parent,
String text,
ModifiablePropertyValueModel<Boolean> booleanHolder,
- PropertyValueModel<String> stringHolder,
+ PropertyValueModel<String> textModel,
String helpId) {
TriStateCheckBox checkBox = this.addTriStateCheckBox(
@@ -2106,10 +2104,7 @@ public abstract class Pane<T extends Model> {
helpId
);
- new LabeledControlUpdater(
- new LabeledButton(checkBox.getCheckBox()),
- stringHolder
- );
+ SWTBindTools.bindTextLabel(textModel, checkBox.getCheckBox());
return checkBox;
}
@@ -2117,7 +2112,7 @@ public abstract class Pane<T extends Model> {
protected final TriStateCheckBox addTriStateCheckBoxWithDefault(Composite parent,
String text,
ModifiablePropertyValueModel<Boolean> booleanHolder,
- PropertyValueModel<String> stringHolder,
+ PropertyValueModel<String> textModel,
PropertyValueModel<Boolean> enabledModel,
String helpId) {
@@ -2125,10 +2120,7 @@ public abstract class Pane<T extends Model> {
this.controlEnabledState(enabledModel, checkBox.getCheckBox());
- new LabeledControlUpdater(
- new LabeledButton(checkBox.getCheckBox()),
- stringHolder
- );
+ SWTBindTools.bindTextLabel(textModel, checkBox.getCheckBox());
return checkBox;
}
diff --git a/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/util/JptUiUtilTests.java b/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/util/JptUiUtilTests.java
index 2ff34bdc83..433b398569 100644
--- a/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/util/JptUiUtilTests.java
+++ b/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/util/JptUiUtilTests.java
@@ -21,9 +21,7 @@ import org.junit.runners.Suite.SuiteClasses;
ControlSwitcherTest.class,
ControlEnablerTest.class,
ControlVisibilityEnablerTest.class,
- LabeledButtonTest.class,
- LabeledLabelTest.class,
- LabeledControlUpdaterTest.class,
+ LabelModelBindingTest.class,
SectionExpanderTest.class,
})
@RunWith(Suite.class)
diff --git a/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/util/LabelModelBindingTest.java b/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/util/LabelModelBindingTest.java
new file mode 100644
index 0000000000..6ace7c1777
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/util/LabelModelBindingTest.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.tests.internal.util;
+
+import static org.junit.Assert.assertEquals;
+import org.eclipse.jpt.common.ui.internal.swt.bind.SWTBindTools;
+import org.eclipse.jpt.common.ui.internal.swt.widgets.DisplayTools;
+import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
+import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+@SuppressWarnings("nls")
+public final class LabelModelBindingTest {
+
+ private Composite composite;
+
+ @Before
+ public void setUp() {
+ this.composite = new Composite(DisplayTools.getShell(), SWT.NONE);
+ this.composite.setLayout(new GridLayout());
+ }
+
+ @After
+ public void tearDown() {
+ if (this.composite != null) {
+ this.composite.dispose();
+ this.composite = null;
+ }
+ }
+
+ @Test
+ public void testSetImage() {
+ Image expectedImage = new Image(this.composite.getDisplay(), 16, 16);
+ try {
+ Label label = new Label(this.composite, SWT.NULL);
+ ModifiablePropertyValueModel<Image> imageModel = new SimplePropertyValueModel<Image>();
+ SWTBindTools.bindImageLabel(imageModel, label);
+ imageModel.setValue(expectedImage);
+ assertEquals(expectedImage, label.getImage());
+ } finally {
+ expectedImage.dispose();
+ }
+ }
+
+ @Test
+ public void testSetImageDispose() {
+ Image expectedImage = new Image(this.composite.getDisplay(), 16, 16);
+ try {
+ Label label = new Label(this.composite, SWT.NULL);
+ ModifiablePropertyValueModel<Image> imageModel = new SimplePropertyValueModel<Image>();
+ SWTBindTools.bindImageLabel(imageModel, label);
+ label.dispose();
+ imageModel.setValue(expectedImage);
+ } finally {
+ expectedImage.dispose();
+ }
+ }
+
+ @Test
+ public void testSetText() {
+ Label label = new Label(this.composite, SWT.NULL);
+ ModifiablePropertyValueModel<String> textModel = new SimplePropertyValueModel<String>();
+ SWTBindTools.bindTextLabel(textModel, label);
+ String expectedText = "This is a test";
+ textModel.setValue(expectedText);
+ assertEquals(expectedText, label.getText());
+ }
+
+ @Test
+ public void testSetTextDispose() {
+ Label label = new Label(this.composite, SWT.NULL);
+ ModifiablePropertyValueModel<String> textModel = new SimplePropertyValueModel<String>();
+ SWTBindTools.bindTextLabel(textModel, label);
+ label.dispose();
+ String expectedString = "This is a test";
+ textModel.setValue(expectedString);
+ }
+}
diff --git a/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/util/LabeledButtonTest.java b/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/util/LabeledButtonTest.java
deleted file mode 100644
index 3a718343e3..0000000000
--- a/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/util/LabeledButtonTest.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.ui.tests.internal.util;
-
-import static org.junit.Assert.assertEquals;
-import org.eclipse.core.runtime.AssertionFailedException;
-import org.eclipse.jpt.common.ui.internal.swt.widgets.DisplayTools;
-import org.eclipse.jpt.common.ui.internal.util.LabeledButton;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-@SuppressWarnings("nls")
-public final class LabeledButtonTest {
-
- private Composite parent;
-
- @Before
- public void setUp() {
- parent = new Composite(DisplayTools.getShell(), SWT.NONE);
- parent.setLayout(new GridLayout());
- }
-
- @After
- public void tearDown() {
- if (parent != null) {
- parent.dispose();
- parent = null;
- }
- }
-
- @Test
- public void testLabeledButton1() {
- Button button = new Button(parent, SWT.NULL);
- new LabeledButton(button);
- }
-
- @Test(expected=AssertionFailedException.class)
- public void testLabeledButton2() {
- new LabeledButton(null);
- }
-
- @Test
- public void testSetImage() {
-
- Image expected = new Image(parent.getDisplay(), 16, 16);
-
- try {
- Button button = new Button(parent, SWT.NULL);
- LabeledButton labeledButton = new LabeledButton(button);
-
- labeledButton.setImage(expected);
-
- assertEquals(
- "The Button didn't receive the Image",
- expected,
- button.getImage()
- );
- }
- finally {
- expected.dispose();
- }
- }
-
- @Test
- public void testSetImageDispose() {
-
- Image expected = new Image(parent.getDisplay(), 16, 16);
-
- try {
- Button button = new Button(parent, SWT.NULL);
- LabeledButton labeledButton = new LabeledButton(button);
-
- button.dispose();
-
- // This should not fail but simply do nothing
- labeledButton.setImage(expected);
- }
- finally {
- expected.dispose();
- }
- }
-
- @Test
- public void testSetText() {
- Button button = new Button(parent, SWT.NULL);
- LabeledButton labeledButton = new LabeledButton(button);
-
- String expected = "This is a test";
- labeledButton.setText(expected);
-
- assertEquals(
- "The Button didn't receive the text",
- expected,
- button.getText()
- );
- }
-
- @Test
- public void testSetTextDispose() {
- Button button = new Button(parent, SWT.NULL);
- LabeledButton labeledButton = new LabeledButton(button);
-
- button.dispose();
-
- // This should not fail but simply do nothing
- String expected = "This is a test";
- labeledButton.setText(expected);
- }
-}
diff --git a/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/util/LabeledControlUpdaterTest.java b/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/util/LabeledControlUpdaterTest.java
deleted file mode 100644
index 389d82486c..0000000000
--- a/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/util/LabeledControlUpdaterTest.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2012 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.ui.tests.internal.util;
-
-import static org.junit.Assert.assertEquals;
-import org.eclipse.jpt.common.ui.internal.swt.widgets.DisplayTools;
-import org.eclipse.jpt.common.ui.internal.util.LabeledControlUpdater;
-import org.eclipse.jpt.common.ui.internal.util.LabeledLabel;
-import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
-import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-@SuppressWarnings("nls")
-public final class LabeledControlUpdaterTest {
-
- private Composite parent;
-
- @Before
- public void setUp() {
- parent = new Composite(DisplayTools.getShell(), SWT.NONE);
- parent.setLayout(new GridLayout());
- }
-
- @After
- public void tearDown() {
- if (parent != null) {
- parent.dispose();
- parent = null;
- }
- }
-
- @Test
- public void testSetImage() {
-
- Image expected = new Image(parent.getDisplay(), 16, 16);
-
- try {
- Label label = new Label(parent, SWT.NULL);
- LabeledLabel labeledLabel = new LabeledLabel(label);
-
- ModifiablePropertyValueModel<Image> imageHolder = new SimplePropertyValueModel<Image>();
- new LabeledControlUpdater(labeledLabel, null, imageHolder);
-
- labeledLabel.setImage(expected);
-
- assertEquals(
- "The Label didn't receive the Image",
- expected,
- label.getImage()
- );
- }
- finally {
- expected.dispose();
- }
- }
-
- @Test
- public void testSetImageDispose() {
-
- Image expected = new Image(parent.getDisplay(), 16, 16);
-
- try {
- Label label = new Label(parent, SWT.NULL);
- LabeledLabel labeledLabel = new LabeledLabel(label);
-
- ModifiablePropertyValueModel<Image> imageHolder = new SimplePropertyValueModel<Image>();
- new LabeledControlUpdater(labeledLabel, null, imageHolder);
-
- label.dispose();
- labeledLabel.setImage(expected);
- }
- finally {
- expected.dispose();
- }
- }
-
- @Test
- public void testSetText() {
-
- Label label = new Label(parent, SWT.NULL);
- LabeledLabel labeledLabel = new LabeledLabel(label);
-
- ModifiablePropertyValueModel<String> textHolder = new SimplePropertyValueModel<String>();
- new LabeledControlUpdater(labeledLabel, textHolder);
-
- String expected = "This is a test";
- textHolder.setValue(expected);
-
- assertEquals(
- "The Label didn't receive the text",
- expected,
- label.getText()
- );
- }
-
- @Test
- public void testSetTextDispose() {
-
- Label label = new Label(parent, SWT.NULL);
- LabeledLabel labeledLabel = new LabeledLabel(label);
-
- ModifiablePropertyValueModel<String> textHolder = new SimplePropertyValueModel<String>();
- new LabeledControlUpdater(labeledLabel, textHolder);
-
- label.dispose();
-
- String expected = "This is a test";
- textHolder.setValue(expected);
- }
-}
diff --git a/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/util/LabeledLabelTest.java b/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/util/LabeledLabelTest.java
deleted file mode 100644
index eaa8b4d5ca..0000000000
--- a/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/util/LabeledLabelTest.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.ui.tests.internal.util;
-
-import static org.junit.Assert.assertEquals;
-import org.eclipse.core.runtime.AssertionFailedException;
-import org.eclipse.jpt.common.ui.internal.swt.widgets.DisplayTools;
-import org.eclipse.jpt.common.ui.internal.util.LabeledLabel;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-@SuppressWarnings("nls")
-public final class LabeledLabelTest {
-
- private Composite parent;
-
- @Before
- public void setUp() {
- parent = new Composite(DisplayTools.getShell(), SWT.NONE);
- parent.setLayout(new GridLayout());
- }
-
- @After
- public void tearDown() {
- if (parent != null) {
- parent.dispose();
- parent = null;
- }
- }
-
- @Test
- public void testLabeledButton1() {
- Label label = new Label(parent, SWT.NULL);
- new LabeledLabel(label);
- }
-
- @Test(expected=AssertionFailedException.class)
- public void testLabeledButton2() {
- new LabeledLabel(null);
- }
-
- @Test
- public void testSetImage() {
-
- Image expected = new Image(parent.getDisplay(), 16, 16);
-
- try {
- Label label = new Label(parent, SWT.NULL);
- LabeledLabel labeledLabel = new LabeledLabel(label);
-
- labeledLabel.setImage(expected);
-
- assertEquals(
- "The Label didn't receive the Image",
- expected,
- label.getImage()
- );
- }
- finally {
- expected.dispose();
- }
- }
-
- @Test
- public void testSetImageDispose() {
-
- Image expected = new Image(parent.getDisplay(), 16, 16);
-
- try {
- Label label = new Label(parent, SWT.NULL);
- LabeledLabel labeledLabel = new LabeledLabel(label);
-
- label.dispose();
-
- // This should not fail but simply do nothing
- labeledLabel.setImage(expected);
- }
- finally {
- expected.dispose();
- }
- }
-
- @Test
- public void testSetText() {
- Label label = new Label(parent, SWT.NULL);
- LabeledLabel labeledLabel = new LabeledLabel(label);
-
- String expected = "This is a test";
- labeledLabel.setText(expected);
-
- assertEquals(
- "The Label didn't receive the text",
- expected,
- label.getText()
- );
- }
-
- @Test
- public void testSetTextDispose() {
- Label label = new Label(parent, SWT.NULL);
- LabeledLabel labeledLabel = new LabeledLabel(label);
-
- label.dispose();
-
- // This should not fail but simply do nothing
- String expected = "This is a test";
- labeledLabel.setText(expected);
- }
-}

Back to the top