diff options
Diffstat (limited to 'jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt')
5 files changed, 0 insertions, 2140 deletions
diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/BooleanStateControllerUITest.java b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/BooleanStateControllerUITest.java deleted file mode 100644 index 9219810f7a..0000000000 --- a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/BooleanStateControllerUITest.java +++ /dev/null @@ -1,278 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.ui.tests.internal.utility.swt; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.ActionContributionItem; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.window.ApplicationWindow; -import org.eclipse.jface.window.Window; -import org.eclipse.jpt.ui.internal.utility.swt.SWTTools; -import org.eclipse.jpt.utility.internal.model.value.SimpleListValueModel; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.layout.FormAttachment; -import org.eclipse.swt.layout.FormData; -import org.eclipse.swt.layout.FormLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; - -/** - * Play around with boolean state controllers ('enabled' and 'visible'). - * <p> - * Note the behavior of composites:<ul> - * <li>When a composite is disabled, its children are disabled but <em>not</em> - * grayed out. - * <li>When a composite is made invisible, its children are also made - * invisible. - * </ul> - */ -@SuppressWarnings("nls") -public class BooleanStateControllerUITest - extends ApplicationWindow -{ - private final WritablePropertyValueModel<Boolean> enabledHolder; - private final WritablePropertyValueModel<Boolean> visibleHolder; - private final SimpleListValueModel<String> listHolder; - private final WritablePropertyValueModel<String> listSelectionHolder; - - public static void main(String[] args) throws Exception { - Window window = new BooleanStateControllerUITest(args); - window.setBlockOnOpen(true); - window.open(); - Display.getCurrent().dispose(); - System.exit(0); - } - - private BooleanStateControllerUITest(@SuppressWarnings("unused") String[] args) { - super(null); - this.enabledHolder = new SimplePropertyValueModel<Boolean>(Boolean.TRUE); - this.visibleHolder = new SimplePropertyValueModel<Boolean>(Boolean.TRUE); - this.listHolder = this.buildListHolder(); - this.listSelectionHolder = new SimplePropertyValueModel<String>(null); - } - - private SimpleListValueModel<String> buildListHolder() { - SimpleListValueModel<String> result = new SimpleListValueModel<String>(); - result.add("zero"); - result.add("one"); - result.add("two"); - result.add("three"); - result.add("four"); - result.add("five"); - result.add("six"); - result.add("seven"); - return result; - } - - @Override - protected Control createContents(Composite parent) { - ((Shell) parent).setText(this.getClass().getSimpleName()); - parent.setSize(500, 150); - Composite mainPanel = new Composite(parent, SWT.NONE); - mainPanel.setLayout(new FormLayout()); - Control widgetPanel = this.buildWidgetPanels(mainPanel); - this.buildControlPanel(mainPanel, widgetPanel); - return mainPanel; - } - - private Control buildWidgetPanels(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - - FormData fd = new FormData(); - fd.top = new FormAttachment(0); - fd.bottom = new FormAttachment(100, -35); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(100); - panel.setLayoutData(fd); - - panel.setLayout(new FillLayout(SWT.VERTICAL)); - - this.buildWidgetPanel1(panel); - this.buildWidgetPanel2(panel); - - return panel; - } - - private void buildWidgetPanel1(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - panel.setLayout(new FillLayout(SWT.HORIZONTAL)); - - Button enabledComboBoxCheckBox = this.buildEnabledComboBoxCheckBox(panel); - SWTTools.bind(this.enabledHolder, enabledComboBoxCheckBox); - - Button visibleComboBoxCheckBox = this.buildVisibleComboBoxCheckBox(panel); - SWTTools.bind(this.visibleHolder, visibleComboBoxCheckBox); - - Label comboBoxLabel = this.buildComboBoxLabel(panel); - Combo comboBox = this.buildComboBox(panel); - SWTTools.bind(this.listHolder, this.listSelectionHolder, comboBox); - SWTTools.controlEnabledState(this.enabledHolder, comboBoxLabel, comboBox); - SWTTools.controlVisibleState(this.visibleHolder, comboBoxLabel, comboBox); - } - - private Button buildEnabledComboBoxCheckBox(Composite parent) { - return this.buildCheckBox(parent, "enabled"); - } - - private Button buildVisibleComboBoxCheckBox(Composite parent) { - return this.buildCheckBox(parent, "visible"); - } - - private Button buildCheckBox(Composite parent, String text) { - Button checkBox = new Button(parent, SWT.CHECK); - checkBox.setText(text); - return checkBox; - } - - private Label buildComboBoxLabel(Composite parent) { - Label label = new Label(parent, SWT.LEFT); - label.setText("list:"); - return label; - } - - private Combo buildComboBox(Composite parent) { - return new Combo(parent, SWT.READ_ONLY); - } - - private void buildWidgetPanel2(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - panel.setLayout(new FillLayout(SWT.HORIZONTAL)); - - Button checkBox1 = this.buildCheckBox(panel, "one"); - this.buildCheckBox(panel, "two"); - this.buildCheckBox(panel, "three"); - this.buildCheckBox(panel, "four"); - - SWTTools.controlEnabledState(this.enabledHolder, panel, checkBox1); - SWTTools.controlVisibleState(this.visibleHolder, panel); - } - - private void buildControlPanel(Composite parent, Control widgetPanel) { - Composite panel = new Composite(parent, SWT.NONE); - FormData fd = new FormData(); - fd.top = new FormAttachment(widgetPanel); - fd.bottom = new FormAttachment(100); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(100); - panel.setLayoutData(fd); - - panel.setLayout(new FillLayout()); - this.buildClearEnabledModelButton(panel); - this.buildClearVisibleModelButton(panel); - this.buildNullSelectionModelButton(panel); - this.buildNextButton(panel); - } - - private void buildClearEnabledModelButton(Composite parent) { - this.buildClearEnabledModelACI().fill(parent); - } - - private ActionContributionItem buildClearEnabledModelACI() { - Action action = new Action("clear enabled model", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - BooleanStateControllerUITest.this.clearEnabledModel(); - } - }; - action.setToolTipText("clear enabled model"); - return new ActionContributionItem(action); - } - - void clearEnabledModel() { - this.enabledHolder.setValue(null); - } - - private void buildClearVisibleModelButton(Composite parent) { - this.buildClearVisibleModelACI().fill(parent); - } - - private ActionContributionItem buildClearVisibleModelACI() { - Action action = new Action("clear visible model", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - BooleanStateControllerUITest.this.clearVisibleModel(); - } - }; - action.setToolTipText("clear visible model"); - return new ActionContributionItem(action); - } - - void clearVisibleModel() { - this.visibleHolder.setValue(null); - } - - private void buildNullSelectionModelButton(Composite parent) { - this.buildNullSelectionModelACI().fill(parent); - } - - private ActionContributionItem buildNullSelectionModelACI() { - Action action = new Action("null selection model", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - BooleanStateControllerUITest.this.setSelectionModelNull(); - } - }; - action.setToolTipText("null selection model"); - return new ActionContributionItem(action); - } - - void setSelectionModelNull() { - this.listSelectionHolder.setValue(null); - } - - private void buildNextButton(Composite parent) { - this.buildNextACI().fill(parent); - } - - private ActionContributionItem buildNextACI() { - Action action = new Action("next", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - BooleanStateControllerUITest.this.next(); - } - }; - action.setToolTipText("next"); - return new ActionContributionItem(action); - } - - void next() { - this.listSelectionHolder.setValue(this.getNextListSelection()); - } - - private String getNextListSelection() { - return this.listHolder.get(this.getNextListSelectionIndex()); - } - - private int getNextListSelectionIndex() { - int index = this.getListSelectionIndex(); - if (index == -1) { - return 0; - } - index++; - return (index == this.listHolder.size()) ? 0 : index; - } - - private int getListSelectionIndex() { - return this.listHolder.indexOf(this.getListSelection()); - } - - private String getListSelection() { - return this.listSelectionHolder.getValue(); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/CheckBoxModelBindingUITest.java b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/CheckBoxModelBindingUITest.java deleted file mode 100644 index e6f232c4e0..0000000000 --- a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/CheckBoxModelBindingUITest.java +++ /dev/null @@ -1,318 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 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.ui.tests.internal.utility.swt; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.ActionContributionItem; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.window.ApplicationWindow; -import org.eclipse.jface.window.Window; -import org.eclipse.jpt.ui.internal.utility.swt.SWTTools; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.layout.FormAttachment; -import org.eclipse.swt.layout.FormData; -import org.eclipse.swt.layout.FormLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; - -/** - * Play around with a set of check boxes. - */ -@SuppressWarnings("nls") -public class CheckBoxModelBindingUITest - extends ApplicationWindow -{ - private final TestModel testModel; - private final WritablePropertyValueModel<TestModel> testModelHolder; - private final WritablePropertyValueModel<Boolean> flag1Holder; - private final WritablePropertyValueModel<Boolean> flag2Holder; - private final WritablePropertyValueModel<Boolean> notFlag2Holder; - - public static void main(String[] args) throws Exception { - Window window = new CheckBoxModelBindingUITest(args); - window.setBlockOnOpen(true); - window.open(); - Display.getCurrent().dispose(); - System.exit(0); - } - - private CheckBoxModelBindingUITest(@SuppressWarnings("unused") String[] args) { - super(null); - this.testModel = new TestModel(true, true); - this.testModelHolder = new SimplePropertyValueModel<TestModel>(this.testModel); - this.flag1Holder = this.buildFlag1Holder(this.testModelHolder); - this.flag2Holder = this.buildFlag2Holder(this.testModelHolder); - this.notFlag2Holder = this.buildNotFlag2Holder(this.testModelHolder); - } - - private WritablePropertyValueModel<Boolean> buildFlag1Holder(PropertyValueModel<TestModel> subjectHolder) { - return new PropertyAspectAdapter<TestModel, Boolean>(subjectHolder, TestModel.FLAG1_PROPERTY) { - @Override - protected Boolean buildValue_() { - return Boolean.valueOf(this.subject.isFlag1()); - } - @Override - protected void setValue_(Boolean value) { - this.subject.setFlag1(value.booleanValue()); - } - }; - } - - private WritablePropertyValueModel<Boolean> buildFlag2Holder(PropertyValueModel<TestModel> subjectHolder) { - return new PropertyAspectAdapter<TestModel, Boolean>(subjectHolder, TestModel.FLAG2_PROPERTY) { - @Override - protected Boolean buildValue_() { - return Boolean.valueOf(this.subject.isFlag2()); - } - @Override - protected void setValue_(Boolean value) { - this.subject.setFlag2(value.booleanValue()); - } - }; - } - - private WritablePropertyValueModel<Boolean> buildNotFlag2Holder(PropertyValueModel<TestModel> subjectHolder) { - return new PropertyAspectAdapter<TestModel, Boolean>(subjectHolder, TestModel.NOT_FLAG2_PROPERTY) { - @Override - protected Boolean buildValue_() { - return Boolean.valueOf(this.subject.isNotFlag2()); - } - @Override - protected void setValue_(Boolean value) { - this.subject.setNotFlag2(value.booleanValue()); - } - }; - } - - @Override - protected Control createContents(Composite parent) { - ((Shell) parent).setText(this.getClass().getSimpleName()); - parent.setSize(400, 100); - Composite mainPanel = new Composite(parent, SWT.NONE); - mainPanel.setLayout(new FormLayout()); - Control checkBoxPanel = this.buildCheckBoxPanel(mainPanel); - this.buildControlPanel(mainPanel, checkBoxPanel); - return mainPanel; - } - - private Control buildCheckBoxPanel(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - - FormData fd = new FormData(); - fd.top = new FormAttachment(0); - fd.bottom = new FormAttachment(100, -35); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(100); - panel.setLayoutData(fd); - - panel.setLayout(new FillLayout()); - this.buildFlag1CheckBox(panel); - this.buildFlag2CheckBox(panel); - this.buildNotFlag2CheckBox(panel); - this.buildUnattachedCheckBox(panel); - - return panel; - } - - private void buildFlag1CheckBox(Composite parent) { - Button checkBox = new Button(parent, SWT.CHECK); - checkBox.setText("flag 1"); - SWTTools.bind(this.flag1Holder, checkBox); - } - - private void buildFlag2CheckBox(Composite parent) { - Button checkBox = new Button(parent, SWT.CHECK); - checkBox.setText("flag 2"); - SWTTools.bind(this.flag2Holder, checkBox); - } - - private void buildNotFlag2CheckBox(Composite parent) { - Button checkBox = new Button(parent, SWT.CHECK); - checkBox.setText("not flag 2"); - SWTTools.bind(this.notFlag2Holder, checkBox); - } - - private void buildUnattachedCheckBox(Composite parent) { - Button checkBox = new Button(parent, SWT.CHECK); - checkBox.setText("unattached"); - checkBox.addSelectionListener(this.buildUnattachedSelectionListener()); - } - - private SelectionListener buildUnattachedSelectionListener() { - return new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - System.out.println("unattached default selected: " + e); - } - public void widgetSelected(SelectionEvent e) { - System.out.println("unattached selected: " + e); - } - }; - } - - private void buildControlPanel(Composite parent, Control checkBoxPanel) { - Composite panel = new Composite(parent, SWT.NONE); - FormData fd = new FormData(); - fd.top = new FormAttachment(checkBoxPanel); - fd.bottom = new FormAttachment(100); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(100); - panel.setLayoutData(fd); - - panel.setLayout(new FillLayout()); - this.buildFlipFlag1Button(panel); - this.buildNotFlag2ToggleButton(panel); - this.buildClearModelButton(panel); - this.buildRestoreModelButton(panel); - this.buildPrintModelButton(panel); - } - - private void buildFlipFlag1Button(Composite parent) { - this.buildFlipFlag1ACI().fill(parent); - } - - private ActionContributionItem buildFlipFlag1ACI() { - Action action = new Action("flip flag 1", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - CheckBoxModelBindingUITest.this.flipFlag1(); - } - }; - action.setToolTipText("flip flag 1"); - return new ActionContributionItem(action); - } - - void flipFlag1() { - this.testModel.setFlag1( ! this.testModel.isFlag1()); - } - - private void buildNotFlag2ToggleButton(Composite parent) { - Button checkBox = new Button(parent, SWT.TOGGLE); - checkBox.setText("not flag 2"); - SWTTools.bind(this.notFlag2Holder, checkBox); - } - - private void buildClearModelButton(Composite parent) { - this.buildClearModelACI().fill(parent); - } - - private ActionContributionItem buildClearModelACI() { - Action action = new Action("clear model", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - CheckBoxModelBindingUITest.this.clearModel(); - } - }; - action.setToolTipText("clear model"); - return new ActionContributionItem(action); - } - - void clearModel() { - this.testModelHolder.setValue(null); - } - - private void buildRestoreModelButton(Composite parent) { - this.buildRestoreModelACI().fill(parent); - } - - private ActionContributionItem buildRestoreModelACI() { - Action action = new Action("restore model", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - CheckBoxModelBindingUITest.this.restoreModel(); - } - }; - action.setToolTipText("restore model"); - return new ActionContributionItem(action); - } - - void restoreModel() { - this.testModelHolder.setValue(this.testModel); - } - - private void buildPrintModelButton(Composite parent) { - this.buildPrintModelACI().fill(parent); - } - - private ActionContributionItem buildPrintModelACI() { - Action action = new Action("print model", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - CheckBoxModelBindingUITest.this.printModel(); - } - }; - action.setToolTipText("print model"); - return new ActionContributionItem(action); - } - - void printModel() { - System.out.println("flag 1: " + this.testModel.isFlag1()); - System.out.println("flag 2: " + this.testModel.isFlag2()); - System.out.println("not flag 2: " + this.testModel.isNotFlag2()); - System.out.println("***"); - } - - - public static class TestModel extends AbstractModel { - private boolean flag1; - public static final String FLAG1_PROPERTY = "flag1"; - private boolean flag2; - public static final String FLAG2_PROPERTY = "flag2"; - private boolean notFlag2; - public static final String NOT_FLAG2_PROPERTY = "notFlag2"; - - public TestModel(boolean flag1, boolean flag2) { - this.flag1 = flag1; - this.flag2 = flag2; - this.notFlag2 = ! flag2; - } - public boolean isFlag1() { - return this.flag1; - } - public void setFlag1(boolean flag1) { - boolean old = this.flag1; - this.flag1 = flag1; - this.firePropertyChanged(FLAG1_PROPERTY, old, flag1); - } - public boolean isFlag2() { - return this.flag2; - } - public void setFlag2(boolean flag2) { - boolean old = this.flag2; - this.flag2 = flag2; - this.firePropertyChanged(FLAG2_PROPERTY, old, flag2); - - old = this.notFlag2; - this.notFlag2 = ! flag2; - this.firePropertyChanged(NOT_FLAG2_PROPERTY, old, this.notFlag2); - } - public boolean isNotFlag2() { - return this.notFlag2; - } - public void setNotFlag2(boolean notFlag2) { - this.setFlag2( ! notFlag2); - } - @Override - public String toString() { - return "TestModel(" + this.isFlag1() + " - " + this.isFlag2() + ")"; - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/DropDownListBoxModelBindingUITest.java b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/DropDownListBoxModelBindingUITest.java deleted file mode 100644 index 65499c2cb3..0000000000 --- a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/DropDownListBoxModelBindingUITest.java +++ /dev/null @@ -1,665 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.ui.tests.internal.utility.swt; - -import java.text.Collator; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.ActionContributionItem; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.window.ApplicationWindow; -import org.eclipse.jface.window.Window; -import org.eclipse.jpt.ui.internal.utility.swt.SWTTools; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.SortedListValueModelWrapper; -import org.eclipse.jpt.utility.model.Model; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.layout.FormAttachment; -import org.eclipse.swt.layout.FormData; -import org.eclipse.swt.layout.FormLayout; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -/** - * Play around with a set of read-only combo-boxes. - */ -@SuppressWarnings("nls") -public class DropDownListBoxModelBindingUITest - extends ApplicationWindow -{ - final TaskList taskList; - private final WritablePropertyValueModel<TaskList> taskListHolder; - private Text taskTextField; - - public static void main(String[] args) throws Exception { - Window window = new DropDownListBoxModelBindingUITest(args); - window.setBlockOnOpen(true); - window.open(); - Display.getCurrent().dispose(); - System.exit(0); - } - - private DropDownListBoxModelBindingUITest(@SuppressWarnings("unused") String[] args) { - super(null); - this.taskList = new TaskList(); - this.taskListHolder = new SimplePropertyValueModel<TaskList>(this.taskList); - this.taskList.addTask("swim"); - this.taskList.addTask("bike"); - this.taskList.addTask("run"); - Task rest = this.taskList.addTask("rest"); - this.taskList.addTask("repeat"); - this.taskList.setPriorityTask(rest); - } - - @Override - protected Control createContents(Composite parent) { - ((Shell) parent).setText(this.getClass().getSimpleName()); - parent.setSize(800, 300); - Composite mainPanel = new Composite(parent, SWT.NONE); - mainPanel.setLayout(new FormLayout()); - Control taskListPanel = this.buildTaskListPanel(mainPanel); - this.buildControlPanel(mainPanel, taskListPanel); - return mainPanel; - } - - private Control buildTaskListPanel(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - - FormData fd = new FormData(); - fd.top = new FormAttachment(0); - fd.bottom = new FormAttachment(100, -30); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(100); - panel.setLayoutData(fd); - - panel.setLayout(new FormLayout()); - this.buildTaskListPanel_(panel); // false = native (Combo) - - return panel; - } - - private Control buildTaskListPanel_(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - - FormData fd = new FormData(); - fd.top = new FormAttachment(0); - fd.bottom = new FormAttachment(50); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(100); - panel.setLayoutData(fd); - - panel.setLayout(new FormLayout()); - this.buildPrimitiveTaskListPanel(panel); - this.buildObjectTaskListPanel(panel); - - return panel; - } - - private void buildPrimitiveTaskListPanel(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - - FormData fd = new FormData(); - fd.top = new FormAttachment(0); - fd.bottom = new FormAttachment(50); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(100); - panel.setLayoutData(fd); - - panel.setLayout(new FillLayout()); - this.buildUnsortedPrimitiveListPanel(panel); - this.buildStandardSortedPrimitiveListPanel(panel); - this.buildCustomSortedPrimitiveListPanel(panel); - } - - private void buildObjectTaskListPanel(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - - FormData fd = new FormData(); - fd.top = new FormAttachment(50); - fd.bottom = new FormAttachment(100); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(100); - panel.setLayoutData(fd); - - panel.setLayout(new FillLayout()); - this.buildUnsortedObjectListPanel(panel); - this.buildStandardSortedObjectListPanel(panel); - this.buildCustomSortedObjectListPanel(panel); - } - - private void buildUnsortedPrimitiveListPanel(Composite parent) { - String label = "primitive unsorted"; - this.buildComboBoxPanel(parent, label, this.buildUnsortedPrimitiveListModel(), this.buildPriorityTaskNameAdapter()); - } - - private void buildStandardSortedPrimitiveListPanel(Composite parent) { - String label = "primitive sorted"; - this.buildComboBoxPanel(parent, label, this.buildStandardSortedPrimitiveListModel(), this.buildPriorityTaskNameAdapter()); - } - - private void buildCustomSortedPrimitiveListPanel(Composite parent) { - String label = "primitive reverse sorted"; - this.buildComboBoxPanel(parent, label, this.buildCustomSortedPrimitiveListModel(), this.buildPriorityTaskNameAdapter()); - } - - private void buildUnsortedObjectListPanel(Composite parent) { - String label = "object unsorted"; - this.buildComboBoxPanel(parent, label, this.buildUnsortedObjectListModel(), this.buildPriorityTaskAdapter()); - } - - private void buildStandardSortedObjectListPanel(Composite parent) { - String label = "object sorted"; - this.buildComboBoxPanel(parent, label, this.buildStandardSortedObjectListModel(), this.buildPriorityTaskAdapter()); - } - - private void buildCustomSortedObjectListPanel(Composite parent) { - String label = "object reverse sorted"; - this.buildComboBoxPanel(parent, label, this.buildCustomSortedObjectListModel(), this.buildPriorityTaskAdapter()); - } - - private ListValueModel<String> buildUnsortedPrimitiveListModel() { - return this.buildPrimitiveTaskListAdapter(); - } - - private ListValueModel<String> buildStandardSortedPrimitiveListModel() { - return new SortedListValueModelWrapper<String>(this.buildPrimitiveTaskListAdapter()); - } - - private ListValueModel<String> buildCustomSortedPrimitiveListModel() { - return new SortedListValueModelWrapper<String>(this.buildPrimitiveTaskListAdapter(), this.buildCustomStringComparator()); - } - - private ListValueModel<Task> buildUnsortedObjectListModel() { - return this.buildObjectTaskListAdapter(); - } - - private ListValueModel<Task> buildStandardSortedObjectListModel() { - return new SortedListValueModelWrapper<Task>(this.buildObjectTaskListAdapter()); - } - - private ListValueModel<Task> buildCustomSortedObjectListModel() { - return new SortedListValueModelWrapper<Task>(this.buildObjectTaskListAdapter(), this.buildCustomTaskComparator()); - } - - private <E> void buildComboBoxPanel(Composite parent, String label, ListValueModel<E> model, WritablePropertyValueModel<E> selectedItemModel) { - Composite panel = new Composite(parent, SWT.NONE); - panel.setLayout(new FormLayout()); - - Label comboBoxLabel = new Label(panel, SWT.LEFT | SWT.VERTICAL); - comboBoxLabel.setText(label); - FormData fd = new FormData(); - fd.top = new FormAttachment(0, 3); - fd.bottom = new FormAttachment(0, 20); - fd.left = new FormAttachment(0, 5); - fd.right = new FormAttachment(100); - comboBoxLabel.setLayoutData(fd); - - Combo comboBox = this.buildComboBox(panel); - fd = new FormData(); - fd.top = new FormAttachment(comboBoxLabel); - fd.bottom = new FormAttachment(100); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(100); - comboBox.setLayoutData(fd); - SWTTools.bind(model, selectedItemModel, comboBox); // use #toString() - } - - private Combo buildComboBox(Composite parent) { - return new Combo(parent, SWT.READ_ONLY); - } - - private Comparator<String> buildCustomStringComparator() { - return new Comparator<String>() { - public int compare(String s1, String s2) { - return s2.compareTo(s1); - } - }; - } - - private Comparator<Task> buildCustomTaskComparator() { - return new Comparator<Task>() { - public int compare(Task to1, Task to2) { - return to2.compareTo(to1); - } - }; - } - - private ListValueModel<String> buildPrimitiveTaskListAdapter() { - return new ListAspectAdapter<TaskList, String>(this.taskListHolder, TaskList.TASK_NAMES_LIST) { - @Override - protected ListIterator<String> listIterator_() { - return this.subject.taskNames(); - } - }; - } - - private ListValueModel<Task> buildObjectTaskListAdapter() { - return new ListAspectAdapter<TaskList, Task>(this.taskListHolder, TaskList.TASKS_LIST) { - @Override - protected ListIterator<Task> listIterator_() { - return this.subject.tasks(); - } - }; - } - - private WritablePropertyValueModel<Task> buildPriorityTaskAdapter() { - return new PriorityTaskAdapter(this.taskListHolder); - } - - static class PriorityTaskAdapter - extends PropertyAspectAdapter<TaskList, Task> - { - PriorityTaskAdapter(WritablePropertyValueModel<TaskList> taskListHolder) { - super(taskListHolder, TaskList.PRIORITY_TASK_PROPERTY); - } - @Override - protected Task buildValue_() { - return this.subject.getPriorityTask(); - } - @Override - protected void setValue_(Task value) { - this.subject.setPriorityTask(value); - } - } - - private WritablePropertyValueModel<String> buildPriorityTaskNameAdapter() { - return new PriorityTaskNameAdapter(this.taskListHolder); - } - - static class PriorityTaskNameAdapter - extends PropertyAspectAdapter<TaskList, String> - { - PriorityTaskNameAdapter(WritablePropertyValueModel<TaskList> taskListHolder) { - super(taskListHolder, TaskList.PRIORITY_TASK_NAME_PROPERTY); - } - @Override - protected String buildValue_() { - return this.subject.getPriorityTaskName(); - } - @Override - protected void setValue_(String value) { - // ignore - } - } - - private void buildControlPanel(Composite parent, Control taskListPanel) { - Composite panel = new Composite(parent, SWT.NONE); - FormData fd = new FormData(); - fd.top = new FormAttachment(taskListPanel); - fd.bottom = new FormAttachment(100); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(100); - panel.setLayoutData(fd); - - panel.setLayout(new FormLayout()); - Control misc = this.buildMiscTaskPanel(panel); - this.buildAddRemoveTaskPanel(panel, misc); - } - - // is there a better way to associate an ACI with form data? - private Control buildMiscTaskPanel(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - FormData fd = new FormData(); - fd.top = new FormAttachment(0); - fd.bottom = new FormAttachment(100); - fd.left = new FormAttachment(100, -400); - fd.right = new FormAttachment(100); - panel.setLayoutData(fd); - - panel.setLayout(new FillLayout()); - this.buildClearListACI().fill(panel); - this.buildClearModelACI().fill(panel); - this.buildRestoreModelACI().fill(panel); - this.buildChangePriorityTaskACI().fill(panel); - this.buildClearPriorityTaskACI().fill(panel); - return panel; - } - - private ActionContributionItem buildClearListACI() { - Action action = new Action("clear list", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - DropDownListBoxModelBindingUITest.this.clearTasks(); - } - }; - action.setToolTipText("clear all the tasks"); - return new ActionContributionItem(action); - } - - private ActionContributionItem buildClearModelACI() { - Action action = new Action("clear model", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - DropDownListBoxModelBindingUITest.this.clearModel(); - } - }; - action.setToolTipText("clear the task list model"); - return new ActionContributionItem(action); - } - - private ActionContributionItem buildRestoreModelACI() { - Action action = new Action("restore model", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - DropDownListBoxModelBindingUITest.this.restoreModel(); - } - }; - action.setToolTipText("restore the task list model"); - return new ActionContributionItem(action); - } - - private ActionContributionItem buildChangePriorityTaskACI() { - Action action = new Action("change priority", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - DropDownListBoxModelBindingUITest.this.changePriorityTask(); - } - }; - action.setToolTipText("change the priority task"); - return new ActionContributionItem(action); - } - - private ActionContributionItem buildClearPriorityTaskACI() { - Action action = new Action("clear priority", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - DropDownListBoxModelBindingUITest.this.clearPriorityTask(); - } - }; - action.setToolTipText("clear the priority task"); - return new ActionContributionItem(action); - } - - private void buildAddRemoveTaskPanel(Composite parent, Control clearButton) { - Composite panel = new Composite(parent, SWT.NONE); - FormData fd = new FormData(); - fd.top = new FormAttachment(0); - fd.bottom = new FormAttachment(100); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(clearButton); - panel.setLayoutData(fd); - - panel.setLayout(new FormLayout()); - Control addButton = this.buildAddButton(panel); - Control removeButton = this.buildRemoveButton(panel); - this.buildTaskTextField(panel, addButton, removeButton); - } - - // is there a better way to associate an ACI with form data? - private Control buildAddButton(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - FormData fd = new FormData(); - fd.top = new FormAttachment(0); - fd.bottom = new FormAttachment(100); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(0, 50); - panel.setLayoutData(fd); - - panel.setLayout(new FillLayout()); - this.buildAddACI().fill(panel); - return panel; - } - - private ActionContributionItem buildAddACI() { - Action action = new Action("add", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - DropDownListBoxModelBindingUITest.this.addTask(); - } - }; - action.setToolTipText("add a task with the name in the entry field"); - return new ActionContributionItem(action); - } - - // is there a better way to associate an ACI with form data? - private Control buildRemoveButton(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - FormData fd = new FormData(); - fd.top = new FormAttachment(0); - fd.bottom = new FormAttachment(100); - fd.left = new FormAttachment(100, -50); - fd.right = new FormAttachment(100); - panel.setLayoutData(fd); - - panel.setLayout(new FillLayout()); - this.buildRemoveACI().fill(panel); - return panel; - } - - private ActionContributionItem buildRemoveACI() { - Action action = new Action("remove", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - DropDownListBoxModelBindingUITest.this.removeTask(); - } - }; - action.setToolTipText("remove the task with the name in the entry field"); - return new ActionContributionItem(action); - } - - private void buildTaskTextField(Composite parent, Control addButton, Control removeButton) { - this.taskTextField = new Text(parent, SWT.SINGLE | SWT.BORDER); - FormData fd = new FormData(); - fd.top = new FormAttachment(0); - fd.bottom = new FormAttachment(100); - fd.left = new FormAttachment(addButton); - fd.right = new FormAttachment(removeButton); - this.taskTextField.setLayoutData(fd); - } - - private String taskTextFieldText() { - return this.taskTextField.getText(); - } - - void addTask() { - String taskText = this.taskTextFieldText(); - if (taskText.length() != 0) { - this.taskList.addTask(taskText); - } - } - - void removeTask() { - String task = this.taskTextFieldText(); - if (task.length() != 0) { - this.taskList.removeTask(task); - } - } - - void clearTasks() { - this.taskList.clearTasks(); - } - - void clearModel() { - this.taskListHolder.setValue(null); - } - - void restoreModel() { - this.taskListHolder.setValue(this.taskList); - } - - void changePriorityTask() { - boolean found = false; - for (Task task : this.taskList.getTasks()) { - if (this.taskList.getPriorityTask() == task) { - found = true; - } else { - if (found) { - this.taskList.setPriorityTask(task); - return; - } - } - } - Iterator<Task> tasks = this.taskList.tasks(); - if (tasks.hasNext()) { - this.taskList.setPriorityTask(tasks.next()); - } - } - - void clearPriorityTask() { - this.taskList.setPriorityTask(null); - } - - - // ********** TaskList ********** - - // note absence of validation... - public static class TaskList extends AbstractModel { - private final List<String> taskNames = new ArrayList<String>(); - public static final String TASK_NAMES_LIST = "taskNames"; - private final List<Task> tasks = new ArrayList<Task>(); - public static final String TASKS_LIST = "tasks"; - private String priorityTaskName = null; - public static final String PRIORITY_TASK_NAME_PROPERTY = "priorityTaskName"; - private Task priorityTask = null; - public static final String PRIORITY_TASK_PROPERTY = "priorityTask"; - public TaskList() { - super(); - } - public ListIterator<String> taskNames() { - return this.taskNames.listIterator(); - } - public Iterable<Task> getTasks() { - return this.tasks; - } - public ListIterator<Task> tasks() { - return this.tasks.listIterator(); - } - public String getPriorityTaskName() { - return this.priorityTaskName; - } - public Task getPriorityTask() { - return this.priorityTask; - } - public Task addTask(String taskName) { - this.addItemToList(taskName, this.taskNames, TASK_NAMES_LIST); - Task task = new Task(taskName); - this.addItemToList(task, this.tasks, TASKS_LIST); - return task; - } - public void removeTask(String taskName) { - int index = this.taskNames.indexOf(taskName); - if (index != -1) { - Task task = this.tasks.get(index); - if (task == this.priorityTask) { - this.setPriorityTask(null); - } - // assume the indexes match... - this.removeItemFromList(index, this.taskNames, TASK_NAMES_LIST); - this.removeItemFromList(index, this.tasks, TASKS_LIST); - } - } - public void clearTasks() { - this.setPriorityTask(null); - this.clearList(this.taskNames, TASK_NAMES_LIST); - this.clearList(this.tasks, TASKS_LIST); - } - private void setPriorityTaskName(String priorityTaskName) { - String old = this.priorityTaskName; - this.priorityTaskName = priorityTaskName; - this.firePropertyChanged(PRIORITY_TASK_NAME_PROPERTY, old, priorityTaskName); - } - public void setPriorityTask(Task priorityTask) { - Task old = this.priorityTask; - this.priorityTask = priorityTask; - this.firePropertyChanged(PRIORITY_TASK_PROPERTY, old, priorityTask); - this.setPriorityTaskName((priorityTask == null) ? null : priorityTask.getName()); - } - } - - - // ********** Task ********** - - public static class Task extends AbstractModel implements Displayable { - private String name; - private int instanceCount; - private static int INSTANCE_COUNT = 1; - public Task(String name) { - this.name = name; - this.instanceCount = INSTANCE_COUNT++; - } - public String displayString() { - return this.name + ": " + this.instanceCount; - } - public int compareTo(Displayable o) { - return DEFAULT_COMPARATOR.compare(this, o); - } - public String getName() { - return this.name; - } - public void setName(String name) { - Object old = this.name; - this.name = name; - this.firePropertyChanged(DISPLAY_STRING_PROPERTY, old, name); - } - @Override - public String toString() { - return this.displayString(); - } - } - - public interface Displayable extends Model, Comparable<Displayable> { - - String displayString(); - String DISPLAY_STRING_PROPERTY = "displayString"; - - - // ********** helper implementations ********** - - Collator DEFAULT_COLLATOR = Collator.getInstance(); - - Comparator<Displayable> DEFAULT_COMPARATOR = - new Comparator<Displayable>() { - public int compare(Displayable d1, Displayable d2) { - // disallow duplicates based on object identity - if (d1 == d2) { - return 0; - } - - // first compare display strings using the default collator - int result = DEFAULT_COLLATOR.compare(d1.displayString(), d2.displayString()); - if (result != 0) { - return result; - } - - // then compare using object-id - result = System.identityHashCode(d1) - System.identityHashCode(d2); - if (result != 0) { - return result; - } - - // It's unlikely that we get to this point; but, just in case, we will return -1. - // Unfortunately, this introduces some mild unpredictability to the sort order - // (unless the objects are always passed into this method in the same order). - return -1; // if all else fails, indicate that o1 < o2 - } - @Override - public String toString() { - return "Displayable.DEFAULT_COMPARATOR"; - } - }; - - } -} diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/ListBoxModelBindingUITest.java b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/ListBoxModelBindingUITest.java deleted file mode 100644 index ff19beb19b..0000000000 --- a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/ListBoxModelBindingUITest.java +++ /dev/null @@ -1,627 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 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.ui.tests.internal.utility.swt; - -import java.text.Collator; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Comparator; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.ActionContributionItem; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.window.ApplicationWindow; -import org.eclipse.jface.window.Window; -import org.eclipse.jpt.ui.internal.utility.swt.SWTTools; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.CollectionAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimpleCollectionValueModel; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.SortedListValueModelWrapper; -import org.eclipse.jpt.utility.model.Model; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.WritableCollectionValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.layout.FormAttachment; -import org.eclipse.swt.layout.FormData; -import org.eclipse.swt.layout.FormLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -/** - * Play around with a set of list boxes. - */ -@SuppressWarnings("nls") -public class ListBoxModelBindingUITest - extends ApplicationWindow -{ - final TaskList taskList; - private final WritablePropertyValueModel<TaskList> taskListHolder; - private Text taskTextField; - - public static void main(String[] args) throws Exception { - Window window = new ListBoxModelBindingUITest(args); - window.setBlockOnOpen(true); - window.open(); - Display.getCurrent().dispose(); - System.exit(0); - } - - private ListBoxModelBindingUITest(@SuppressWarnings("unused") String[] args) { - super(null); - this.taskList = new TaskList(); - this.taskListHolder = new SimplePropertyValueModel<TaskList>(this.taskList); - this.taskList.addTask("swim"); - this.taskList.addTask("bike"); - this.taskList.addTask("run"); - Task rest = this.taskList.addTask("rest"); - this.taskList.addPriorityTask(rest); - Task repeat = this.taskList.addTask("repeat"); - this.taskList.addPriorityTask(repeat); - } - - @Override - protected Control createContents(Composite parent) { - ((Shell) parent).setText(this.getClass().getSimpleName()); - parent.setSize(800, 400); - Composite mainPanel = new Composite(parent, SWT.NONE); - mainPanel.setLayout(new FormLayout()); - Control taskListPanel = this.buildTaskListPanel(mainPanel); - this.buildControlPanel(mainPanel, taskListPanel); - return mainPanel; - } - - private Control buildTaskListPanel(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - - FormData fd = new FormData(); - fd.top = new FormAttachment(0); - fd.bottom = new FormAttachment(100, -30); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(100); - panel.setLayoutData(fd); - - panel.setLayout(new FormLayout()); - this.buildPrimitiveTaskListPanel(panel); - this.buildObjectTaskListPanel(panel); - - return panel; - } - - private void buildPrimitiveTaskListPanel(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - - FormData fd = new FormData(); - fd.top = new FormAttachment(0); - fd.bottom = new FormAttachment(50); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(100); - panel.setLayoutData(fd); - - panel.setLayout(new FillLayout()); - this.buildUnsortedPrimitiveListPanel(panel); - this.buildStandardSortedPrimitiveListPanel(panel); - this.buildCustomSortedPrimitiveListPanel(panel); - } - - private void buildObjectTaskListPanel(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - - FormData fd = new FormData(); - fd.top = new FormAttachment(50); - fd.bottom = new FormAttachment(100); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(100); - panel.setLayoutData(fd); - - panel.setLayout(new FillLayout()); - this.buildUnsortedObjectListPanel(panel); - this.buildStandardSortedObjectListPanel(panel); - this.buildCustomSortedObjectListPanel(panel); - } - - private void buildUnsortedPrimitiveListPanel(Composite parent) { - this.buildListPanel(parent, "primitive unsorted", this.buildUnsortedPrimitiveListModel(), new SimpleCollectionValueModel<String>()); - } - - private void buildStandardSortedPrimitiveListPanel(Composite parent) { - this.buildListPanel(parent, "primitive sorted", this.buildStandardSortedPrimitiveListModel(), new SimpleCollectionValueModel<String>()); - } - - private void buildCustomSortedPrimitiveListPanel(Composite parent) { - this.buildListPanel(parent, "primitive reverse sorted", this.buildCustomSortedPrimitiveListModel(), new SimpleCollectionValueModel<String>()); - } - - private void buildUnsortedObjectListPanel(Composite parent) { - this.buildListPanel(parent, "object unsorted", this.buildUnsortedObjectListModel(), this.buildPriorityTaskListAdapter()); - } - - private void buildStandardSortedObjectListPanel(Composite parent) { - this.buildListPanel(parent, "object sorted", this.buildStandardSortedObjectListModel(), this.buildPriorityTaskListAdapter()); - } - - private void buildCustomSortedObjectListPanel(Composite parent) { - this.buildListPanel(parent, "object reverse sorted", this.buildCustomSortedObjectListModel(), this.buildPriorityTaskListAdapter()); - } - - private ListValueModel<String> buildUnsortedPrimitiveListModel() { - return this.buildPrimitiveTaskListAdapter(); - } - - private ListValueModel<String> buildStandardSortedPrimitiveListModel() { - return new SortedListValueModelWrapper<String>(this.buildPrimitiveTaskListAdapter()); - } - - private ListValueModel<String> buildCustomSortedPrimitiveListModel() { - return new SortedListValueModelWrapper<String>(this.buildPrimitiveTaskListAdapter(), this.buildCustomStringComparator()); - } - - private ListValueModel<Task> buildUnsortedObjectListModel() { - return this.buildObjectTaskListAdapter(); - } - - private ListValueModel<Task> buildStandardSortedObjectListModel() { - return new SortedListValueModelWrapper<Task>(this.buildObjectTaskListAdapter()); - } - - private ListValueModel<Task> buildCustomSortedObjectListModel() { - return new SortedListValueModelWrapper<Task>(this.buildObjectTaskListAdapter(), this.buildCustomTaskComparator()); - } - - private <E> org.eclipse.swt.widgets.List buildListPanel(Composite parent, String label, ListValueModel<E> model, WritableCollectionValueModel<E> selectedItemsModel) { - Composite panel = new Composite(parent, SWT.NONE); - panel.setLayout(new FormLayout()); - - Label listLabel = new Label(panel, SWT.LEFT | SWT.VERTICAL); - listLabel.setText(label); - FormData fd = new FormData(); - fd.top = new FormAttachment(0, 3); - fd.bottom = new FormAttachment(0, 20); - fd.left = new FormAttachment(0, 5); - fd.right = new FormAttachment(100); - listLabel.setLayoutData(fd); - - org.eclipse.swt.widgets.List listBox = new org.eclipse.swt.widgets.List(panel, SWT.MULTI | SWT.BORDER); - fd = new FormData(); - fd.top = new FormAttachment(listLabel); - fd.bottom = new FormAttachment(100); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(100); - listBox.setLayoutData(fd); - SWTTools.bind(model, selectedItemsModel, listBox); // use #toString() - return listBox; - } - - private Comparator<String> buildCustomStringComparator() { - return new Comparator<String>() { - public int compare(String s1, String s2) { - return s2.compareTo(s1); - } - }; - } - - private Comparator<Task> buildCustomTaskComparator() { - return new Comparator<Task>() { - public int compare(Task to1, Task to2) { - return to2.compareTo(to1); - } - }; - } - - private ListValueModel<String> buildPrimitiveTaskListAdapter() { - return new ListAspectAdapter<TaskList, String>(this.taskListHolder, TaskList.TASK_NAMES_LIST) { - @Override - protected ListIterator<String> listIterator_() { - return this.subject.taskNames(); - } - }; - } - - private ListValueModel<Task> buildObjectTaskListAdapter() { - return new ListAspectAdapter<TaskList, Task>(this.taskListHolder, TaskList.TASKS_LIST) { - @Override - protected ListIterator<Task> listIterator_() { - return this.subject.tasks(); - } - }; - } - - private WritableCollectionValueModel<Task> buildPriorityTaskListAdapter() { - return new PriorityTaskListAdapter(this.taskListHolder); - } - - static class PriorityTaskListAdapter - extends CollectionAspectAdapter<TaskList, Task> - implements WritableCollectionValueModel<Task> - { - PriorityTaskListAdapter(WritablePropertyValueModel<TaskList> taskListHolder) { - super(taskListHolder, TaskList.PRIORITY_TASKS_COLLECTION); - } - @Override - protected Iterator<Task> iterator_() { - return this.subject.priorityTasks(); - } - public void setValues(Iterable<Task> values) { - this.subject.setPriorityTasks(values); - } - } - - private void buildControlPanel(Composite parent, Control taskListPanel) { - Composite panel = new Composite(parent, SWT.NONE); - FormData fd = new FormData(); - fd.top = new FormAttachment(taskListPanel); - fd.bottom = new FormAttachment(100); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(100); - panel.setLayoutData(fd); - - panel.setLayout(new FormLayout()); - Control misc = this.buildMiscTaskPanel(panel); - this.buildAddRemoveTaskPanel(panel, misc); - } - - // is there a better way to associate an ACI with form data? - private Control buildMiscTaskPanel(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - FormData fd = new FormData(); - fd.top = new FormAttachment(0); - fd.bottom = new FormAttachment(100); - fd.left = new FormAttachment(100, -400); - fd.right = new FormAttachment(100); - panel.setLayoutData(fd); - - panel.setLayout(new FillLayout()); - this.buildClearListACI().fill(panel); - this.buildClearModelACI().fill(panel); - this.buildRestoreModelACI().fill(panel); - this.buildAddPriorityTaskACI().fill(panel); - this.buildRemovePriorityTaskACI().fill(panel); - this.buildClearPriorityTasksACI().fill(panel); - return panel; - } - - private ActionContributionItem buildClearListACI() { - Action action = new Action("clear list", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - ListBoxModelBindingUITest.this.clearTasks(); - } - }; - action.setToolTipText("clear all the tasks"); - return new ActionContributionItem(action); - } - - private ActionContributionItem buildClearModelACI() { - Action action = new Action("clear model", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - ListBoxModelBindingUITest.this.clearModel(); - } - }; - action.setToolTipText("clear the task list model"); - return new ActionContributionItem(action); - } - - private ActionContributionItem buildRestoreModelACI() { - Action action = new Action("restore model", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - ListBoxModelBindingUITest.this.restoreModel(); - } - }; - action.setToolTipText("restore the task list model"); - return new ActionContributionItem(action); - } - - private ActionContributionItem buildAddPriorityTaskACI() { - Action action = new Action("add priority", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - ListBoxModelBindingUITest.this.addPriorityTask(); - } - }; - action.setToolTipText("add a task to the priority tasks"); - return new ActionContributionItem(action); - } - - private ActionContributionItem buildRemovePriorityTaskACI() { - Action action = new Action("remove priority", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - ListBoxModelBindingUITest.this.removePriorityTask(); - } - }; - action.setToolTipText("remove a task from the priority tasks"); - return new ActionContributionItem(action); - } - - private ActionContributionItem buildClearPriorityTasksACI() { - Action action = new Action("clear priority", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - ListBoxModelBindingUITest.this.clearPriorityTasks(); - } - }; - action.setToolTipText("clear the priority tasks"); - return new ActionContributionItem(action); - } - - private void buildAddRemoveTaskPanel(Composite parent, Control clearButton) { - Composite panel = new Composite(parent, SWT.NONE); - FormData fd = new FormData(); - fd.top = new FormAttachment(0); - fd.bottom = new FormAttachment(100); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(clearButton); - panel.setLayoutData(fd); - - panel.setLayout(new FormLayout()); - Control addButton = this.buildAddButton(panel); - Control removeButton = this.buildRemoveButton(panel); - this.buildTaskTextField(panel, addButton, removeButton); - } - - // is there a better way to associate an ACI with form data? - private Control buildAddButton(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - FormData fd = new FormData(); - fd.top = new FormAttachment(0); - fd.bottom = new FormAttachment(100); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(0, 50); - panel.setLayoutData(fd); - - panel.setLayout(new FillLayout()); - this.buildAddACI().fill(panel); - return panel; - } - - private ActionContributionItem buildAddACI() { - Action action = new Action("add", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - ListBoxModelBindingUITest.this.addTask(); - } - }; - action.setToolTipText("add a task with the name in the entry field"); - return new ActionContributionItem(action); - } - - // is there a better way to associate an ACI with form data? - private Control buildRemoveButton(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - FormData fd = new FormData(); - fd.top = new FormAttachment(0); - fd.bottom = new FormAttachment(100); - fd.left = new FormAttachment(100, -50); - fd.right = new FormAttachment(100); - panel.setLayoutData(fd); - - panel.setLayout(new FillLayout()); - this.buildRemoveACI().fill(panel); - return panel; - } - - private ActionContributionItem buildRemoveACI() { - Action action = new Action("remove", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - ListBoxModelBindingUITest.this.removeTask(); - } - }; - action.setToolTipText("remove the task with the name in the entry field"); - return new ActionContributionItem(action); - } - - private void buildTaskTextField(Composite parent, Control addButton, Control removeButton) { - this.taskTextField = new Text(parent, SWT.SINGLE | SWT.BORDER); - FormData fd = new FormData(); - fd.top = new FormAttachment(0); - fd.bottom = new FormAttachment(100); - fd.left = new FormAttachment(addButton); - fd.right = new FormAttachment(removeButton); - this.taskTextField.setLayoutData(fd); - } - - private String taskTextFieldText() { - return this.taskTextField.getText(); - } - - void addTask() { - String taskText = this.taskTextFieldText(); - if (taskText.length() != 0) { - this.taskList.addTask(taskText); - } - } - - void removeTask() { - String task = this.taskTextFieldText(); - if (task.length() != 0) { - this.taskList.removeTask(task); - } - } - - void clearTasks() { - this.taskList.clearTasks(); - } - - void clearModel() { - this.taskListHolder.setValue(null); - } - - void restoreModel() { - this.taskListHolder.setValue(this.taskList); - } - - void addPriorityTask() { - Iterator<Task> tasks = this.taskList.tasks(); - while (tasks.hasNext()) { - if (this.taskList.addPriorityTask(tasks.next())) { - return; - } - } - } - - void removePriorityTask() { - Iterator<Task> pTasks = this.taskList.priorityTasks(); - if (pTasks.hasNext()) { - this.taskList.removePriorityTask(pTasks.next()); - } - } - - void clearPriorityTasks() { - this.taskList.clearPriorityTasks(); - } - - - // ********** TaskList ********** - - // note absence of validation... - public static class TaskList extends AbstractModel { - private final List<String> taskNames = new ArrayList<String>(); - public static final String TASK_NAMES_LIST = "taskNames"; - private final List<Task> tasks = new ArrayList<Task>(); - public static final String TASKS_LIST = "tasks"; - private final Collection<Task> priorityTasks = new HashSet<Task>(); - public static final String PRIORITY_TASKS_COLLECTION = "priorityTasks"; - public TaskList() { - super(); - } - public ListIterator<String> taskNames() { - return this.taskNames.listIterator(); - } - public ListIterator<Task> tasks() { - return this.tasks.listIterator(); - } - public Iterator<Task> priorityTasks() { - return this.priorityTasks.iterator(); - } - public Task addTask(String taskName) { - this.addItemToList(taskName, this.taskNames, TASK_NAMES_LIST); - Task task = new Task(taskName); - this.addItemToList(task, this.tasks, TASKS_LIST); - return task; - } - public void removeTask(String taskName) { - int index = this.taskNames.indexOf(taskName); - if (index != -1) { - this.removeItemFromList(index, this.taskNames, TASK_NAMES_LIST); - // assume the indexes match... - Task removedTask = this.removeItemFromList(index, this.tasks, TASKS_LIST); - this.removeItemFromCollection(removedTask, this.priorityTasks, PRIORITY_TASKS_COLLECTION); - } - } - public void clearTasks() { - this.clearCollection(this.priorityTasks, PRIORITY_TASKS_COLLECTION); - this.clearList(this.taskNames, TASK_NAMES_LIST); - this.clearList(this.tasks, TASKS_LIST); - } - public boolean addPriorityTask(Task task) { - return this.addItemToCollection(task, this.priorityTasks, PRIORITY_TASKS_COLLECTION); - } - public void removePriorityTask(Task task) { - this.removeItemFromCollection(task, this.priorityTasks, PRIORITY_TASKS_COLLECTION); - } - public void clearPriorityTasks() { - this.clearCollection(this.priorityTasks, PRIORITY_TASKS_COLLECTION); - } - public void setPriorityTasks(Iterable<Task> tasks) { - this.priorityTasks.clear(); - CollectionTools.addAll(this.priorityTasks, tasks); - this.fireCollectionChanged(PRIORITY_TASKS_COLLECTION, this.priorityTasks); - } - } - - - // ********** Task ********** - - public static class Task extends AbstractModel implements Displayable { - private String name; - private int instanceCount; - private static int INSTANCE_COUNT = 1; - public Task(String name) { - this.name = name; - this.instanceCount = INSTANCE_COUNT++; - } - public String displayString() { - return this.name + ": " + this.instanceCount; - } - public int compareTo(Displayable o) { - return DEFAULT_COMPARATOR.compare(this, o); - } - public String getName() { - return this.name; - } - public void setName(String name) { - Object old = this.name; - this.name = name; - this.firePropertyChanged(DISPLAY_STRING_PROPERTY, old, name); - } - @Override - public String toString() { - return this.displayString(); - } - } - - public interface Displayable extends Model, Comparable<Displayable> { - - String displayString(); - String DISPLAY_STRING_PROPERTY = "displayString"; - - - // ********** helper implementations ********** - - Collator DEFAULT_COLLATOR = Collator.getInstance(); - - Comparator<Displayable> DEFAULT_COMPARATOR = - new Comparator<Displayable>() { - public int compare(Displayable d1, Displayable d2) { - // disallow duplicates based on object identity - if (d1 == d2) { - return 0; - } - - // first compare display strings using the default collator - int result = DEFAULT_COLLATOR.compare(d1.displayString(), d2.displayString()); - if (result != 0) { - return result; - } - - // then compare using object-id - result = System.identityHashCode(d1) - System.identityHashCode(d2); - if (result != 0) { - return result; - } - - // It's unlikely that we get to this point; but, just in case, we will return -1. - // Unfortunately, this introduces some mild unpredictability to the sort order - // (unless the objects are always passed into this method in the same order). - return -1; // if all else fails, indicate that o1 < o2 - } - @Override - public String toString() { - return "Displayable.DEFAULT_COMPARATOR"; - } - }; - - } -} diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/TextFieldModelBindingUITest.java b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/TextFieldModelBindingUITest.java deleted file mode 100644 index 4b3cb048c6..0000000000 --- a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/utility/swt/TextFieldModelBindingUITest.java +++ /dev/null @@ -1,252 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 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.ui.tests.internal.utility.swt; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.ActionContributionItem; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.window.ApplicationWindow; -import org.eclipse.jface.window.Window; -import org.eclipse.jpt.ui.internal.utility.swt.SWTTools; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.layout.FormAttachment; -import org.eclipse.swt.layout.FormData; -import org.eclipse.swt.layout.FormLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -/** - * Play around with a set of entry fields. - */ -@SuppressWarnings("nls") -public class TextFieldModelBindingUITest - extends ApplicationWindow -{ - private final TestModel testModel; - private static final String DEFAULT_NAME = "Scooby Doo"; - private final WritablePropertyValueModel<TestModel> testModelHolder; - private final WritablePropertyValueModel<String> nameHolder; - private final WritablePropertyValueModel<String> allCapsNameHolder; - - - public static void main(String[] args) throws Exception { - Window window = new TextFieldModelBindingUITest(); - window.setBlockOnOpen(true); - window.open(); - Display.getCurrent().dispose(); - System.exit(0); - } - - private TextFieldModelBindingUITest() { - super(null); - this.testModel = new TestModel(DEFAULT_NAME); - this.testModelHolder = new SimplePropertyValueModel<TestModel>(this.testModel); - this.nameHolder = this.buildNameHolder(this.testModelHolder); - this.allCapsNameHolder = this.buildAllCapsNameHolder(this.testModelHolder); - } - - private WritablePropertyValueModel<String> buildNameHolder(PropertyValueModel<TestModel> vm) { - return new PropertyAspectAdapter<TestModel, String>(vm, TestModel.NAME_PROPERTY) { - @Override - protected String buildValue_() { - return this.subject.name(); - } - @Override - protected void setValue_(String value) { - this.subject.setName(value); - } - }; - } - - private WritablePropertyValueModel<String> buildAllCapsNameHolder(PropertyValueModel<TestModel> vm) { - return new PropertyAspectAdapter<TestModel, String>(vm, TestModel.NAME_PROPERTY) { - @Override - protected String buildValue_() { - return this.subject.name().toUpperCase(); - } - @Override - protected void setValue_(String value) { - // do nothing - } - }; - } - - @Override - protected Control createContents(Composite parent) { - ((Shell) parent).setText(this.getClass().getSimpleName()); - parent.setSize(400, 100); - Composite mainPanel = new Composite(parent, SWT.NONE); - mainPanel.setLayout(new FormLayout()); - Control textFieldPanel = this.buildTextFieldPanel(mainPanel); - this.buildControlPanel(mainPanel, textFieldPanel); - return mainPanel; - } - - private Control buildTextFieldPanel(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - - FormData fd = new FormData(); - fd.top = new FormAttachment(0); - fd.bottom = new FormAttachment(100, -35); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(100); - panel.setLayoutData(fd); - - panel.setLayout(new FillLayout()); - this.buildNameTextField(panel); - this.buildReadOnlyNameTextField(panel); - this.buildAllCapsNameTextField(panel); - - return panel; - } - - private void buildNameTextField(Composite parent) { - Text textField = new Text(parent, SWT.SINGLE); - SWTTools.bind(this.nameHolder, textField); - } - - private void buildReadOnlyNameTextField(Composite parent) { - Text textField = new Text(parent, SWT.SINGLE); - textField.setEnabled(false); - SWTTools.bind(this.nameHolder, textField); - } - - private void buildAllCapsNameTextField(Composite parent) { - Text textField = new Text(parent, SWT.SINGLE); - textField.setEnabled(false); - SWTTools.bind(this.allCapsNameHolder, textField); - } - - private void buildControlPanel(Composite parent, Control checkBoxPanel) { - Composite panel = new Composite(parent, SWT.NONE); - FormData fd = new FormData(); - fd.top = new FormAttachment(checkBoxPanel); - fd.bottom = new FormAttachment(100); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(100); - panel.setLayoutData(fd); - - panel.setLayout(new FillLayout()); - this.buildResetNameButton(panel); - this.buildClearModelButton(panel); - this.buildRestoreModelButton(panel); - this.buildPrintModelButton(panel); - } - - private void buildResetNameButton(Composite parent) { - this.buildResetNameACI().fill(parent); - } - - private ActionContributionItem buildResetNameACI() { - Action action = new Action("reset name", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - TextFieldModelBindingUITest.this.resetName(); - } - }; - action.setToolTipText("reset name"); - return new ActionContributionItem(action); - } - - void resetName() { - this.testModel.setName(DEFAULT_NAME); - } - - private void buildClearModelButton(Composite parent) { - this.buildClearModelACI().fill(parent); - } - - private ActionContributionItem buildClearModelACI() { - Action action = new Action("clear model", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - TextFieldModelBindingUITest.this.clearModel(); - } - }; - action.setToolTipText("clear model"); - return new ActionContributionItem(action); - } - - void clearModel() { - this.testModelHolder.setValue(null); - } - - private void buildRestoreModelButton(Composite parent) { - this.buildRestoreModelACI().fill(parent); - } - - private ActionContributionItem buildRestoreModelACI() { - Action action = new Action("restore model", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - TextFieldModelBindingUITest.this.restoreModel(); - } - }; - action.setToolTipText("restore model"); - return new ActionContributionItem(action); - } - - void restoreModel() { - this.testModelHolder.setValue(this.testModel); - } - - private void buildPrintModelButton(Composite parent) { - this.buildPrintModelACI().fill(parent); - } - - private ActionContributionItem buildPrintModelACI() { - Action action = new Action("print model", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - TextFieldModelBindingUITest.this.printModel(); - } - }; - action.setToolTipText("print model"); - return new ActionContributionItem(action); - } - - void printModel() { - System.out.println("name: " + this.testModel.name()); - } - - - // ********** model class ********** - - class TestModel extends AbstractModel { - private String name; - public static final String NAME_PROPERTY = "name"; - - public TestModel(String name) { - this.name = name; - } - public String name() { - return this.name; - } - public void setName(String name) { - Object old = this.name; - this.name = name; - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - @Override - public String toString() { - return "TestModel(" + this.name + ")"; - } - } - -} |