Skip to main content
summaryrefslogtreecommitdiffstats
path: root/jpa
diff options
context:
space:
mode:
authorkmoore2008-08-27 18:13:48 +0000
committerkmoore2008-08-27 18:13:48 +0000
commit50dd99d3f0db35689d9c05ab9e869c16c949a44a (patch)
tree0b52ab7994b8ed8fb8deda100c9213111a23e908 /jpa
parent34d0d802061ab84ab1e6a533f10b26c9436a179f (diff)
downloadwebtools.dali-50dd99d3f0db35689d9c05ab9e869c16c949a44a.tar.gz
webtools.dali-50dd99d3f0db35689d9c05ab9e869c16c949a44a.tar.xz
webtools.dali-50dd99d3f0db35689d9c05ab9e869c16c949a44a.zip
new DateTimeModelAdapter, added addDateTime methods to Pane and WidgetFactory
Diffstat (limited to 'jpa')
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/WidgetFactory.java11
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/DateTimeModelAdapter.java352
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/DefaultWidgetFactory.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/FormWidgetFactory.java15
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/Pane.java79
5 files changed, 463 insertions, 2 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/WidgetFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/WidgetFactory.java
index 0a957daf53..22e0dd2d55 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/WidgetFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/WidgetFactory.java
@@ -13,6 +13,7 @@ import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
@@ -82,6 +83,16 @@ public interface WidgetFactory {
Composite createComposite(Composite parent);
/**
+ * Creates a new DateTime.
+ *
+ * @param container The parent container
+ * @param style The style is to tell the type of widget
+ * (<code>SWT.DATE</code> or <code>SWT.TIME</code> or <code>SWT.CALENDAR</code>)
+ * @return A new <code>DateTime</code>
+ */
+ DateTime createDateTime(Composite parent, int style);
+
+ /**
* Creates a new editable custom <code>CCombo</code>.
*
* @param parent The parent container
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/DateTimeModelAdapter.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/DateTimeModelAdapter.java
new file mode 100644
index 0000000000..b90444f0de
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/DateTimeModelAdapter.java
@@ -0,0 +1,352 @@
+/*******************************************************************************
+ * 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.ui.internal.swt;
+
+import org.eclipse.jpt.ui.internal.listeners.SWTPropertyChangeListenerWrapper;
+import org.eclipse.jpt.utility.internal.StringTools;
+import org.eclipse.jpt.utility.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.utility.model.listener.PropertyChangeListener;
+import org.eclipse.jpt.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.widgets.DateTime;
+
+/**
+ * This adapter can be used to keep a DateTime widget in synch with
+ * model integers hours, minutes, and seconds. Has default hours,
+ * minutes and seconds of 0 which corresponds to 12:00:00 AM. This model
+ * adapter can only be used for a DateTime widget with the style SWT.TIME
+ */
+@SuppressWarnings("nls")
+public class DateTimeModelAdapter {
+
+ /**
+ * A value model on the underlying model hours integer.
+ */
+ protected final WritablePropertyValueModel<Integer> hoursHolder;
+
+ /**
+ * A value model on the underlying model minutes integer.
+ */
+ protected final WritablePropertyValueModel<Integer> minutesHolder;
+
+ /**
+ * A value model on the underlying model seconds integer.
+ */
+ protected final WritablePropertyValueModel<Integer> secondsHolder;
+
+ /**
+ * A listener that allows us to synchronize the dateTime's selection state with
+ * the model hours integer.
+ */
+ protected final PropertyChangeListener hoursPropertyChangeListener;
+
+ /**
+ * A listener that allows us to synchronize the dateTime's selection state with
+ * the model minutes integer.
+ */
+ protected final PropertyChangeListener minutesPropertyChangeListener;
+
+ /**
+ * A listener that allows us to synchronize the dateTime's selection state with
+ * the model seconds integer.
+ */
+ protected final PropertyChangeListener secondsPropertyChangeListener;
+
+ /**
+ * The dateTime we keep synchronized with the model integers.
+ */
+ protected final DateTime dateTime;
+
+ /**
+ * A listener that allows us to synchronize our selection number holder
+ * with the spinner's value.
+ */
+ protected final SelectionListener dateTimeSelectionListener;
+
+ /**
+ * A listener that allows us to stop listening to stuff when the dateTime
+ * is disposed.
+ */
+ protected final DisposeListener dateTimeDisposeListener;
+
+ /**
+ * This lock is used to prevent the listeners to be notified when the value
+ * changes from the spinner or from the holder.
+ */
+ private boolean locked;
+
+ // ********** static methods **********
+
+ /**
+ * Adapt the specified model integer holders to the specified dateTime.
+ */
+ public static DateTimeModelAdapter adapt(
+ WritablePropertyValueModel<Integer> hoursHolder,
+ WritablePropertyValueModel<Integer> minutesHolder,
+ WritablePropertyValueModel<Integer> secondsHolder,
+ DateTime dateTime)
+ {
+ return new DateTimeModelAdapter(hoursHolder, minutesHolder, secondsHolder, dateTime);
+ }
+
+
+ // ********** constructors **********
+
+ /**
+ * Constructor - the hoursHolder, minutesHolder, secondsHolder, and dateTime are required
+ */
+ protected DateTimeModelAdapter(WritablePropertyValueModel<Integer> hoursHolder,
+ WritablePropertyValueModel<Integer> minutesHolder,
+ WritablePropertyValueModel<Integer> secondsHolder,
+ DateTime dateTime) {
+ super();
+ if ((hoursHolder == null)
+ || (minutesHolder == null)
+ || (secondsHolder == null)
+ || (dateTime == null)) {
+ throw new NullPointerException();
+ }
+ this.hoursHolder = hoursHolder;
+ this.minutesHolder = minutesHolder;
+ this.secondsHolder = secondsHolder;
+ this.dateTime = dateTime;
+
+ this.hoursPropertyChangeListener = this.buildHoursPropertyChangeListener();
+ this.hoursHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.hoursPropertyChangeListener);
+
+ this.minutesPropertyChangeListener = this.buildMinutesPropertyChangeListener();
+ this.minutesHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.minutesPropertyChangeListener);
+
+ this.secondsPropertyChangeListener = this.buildSecondsPropertyChangeListener();
+ this.secondsHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.secondsPropertyChangeListener);
+
+ this.dateTimeSelectionListener = this.buildDateTimeSelectionListener();
+ this.dateTime.addSelectionListener(this.dateTimeSelectionListener);
+
+ this.dateTimeDisposeListener = this.buildDateTimeDisposeListener();
+ this.dateTime.addDisposeListener(this.dateTimeDisposeListener);
+
+ this.updateDateTimeHours(hoursHolder.getValue());
+ this.updateDateTimeMinutes(minutesHolder.getValue());
+ this.updateDateTimeSeconds(secondsHolder.getValue());
+ }
+
+
+ // ********** initialization **********
+
+ protected PropertyChangeListener buildHoursPropertyChangeListener() {
+ return new SWTPropertyChangeListenerWrapper(this.buildHoursPropertyChangeListener_());
+ }
+
+ protected PropertyChangeListener buildHoursPropertyChangeListener_() {
+ return new PropertyChangeListener() {
+ public void propertyChanged(PropertyChangeEvent event) {
+ DateTimeModelAdapter.this.hoursChanged(event);
+ }
+ @Override
+ public String toString() {
+ return "dateTime hours listener";
+ }
+ };
+ }
+
+ protected PropertyChangeListener buildMinutesPropertyChangeListener() {
+ return new SWTPropertyChangeListenerWrapper(this.buildMinutesPropertyChangeListener_());
+ }
+
+ protected PropertyChangeListener buildMinutesPropertyChangeListener_() {
+ return new PropertyChangeListener() {
+ public void propertyChanged(PropertyChangeEvent event) {
+ DateTimeModelAdapter.this.minutesChanged(event);
+ }
+ @Override
+ public String toString() {
+ return "dateTime minutes listener";
+ }
+ };
+ }
+
+ protected PropertyChangeListener buildSecondsPropertyChangeListener() {
+ return new SWTPropertyChangeListenerWrapper(this.buildSecondsPropertyChangeListener_());
+ }
+
+ protected PropertyChangeListener buildSecondsPropertyChangeListener_() {
+ return new PropertyChangeListener() {
+ public void propertyChanged(PropertyChangeEvent event) {
+ DateTimeModelAdapter.this.secondsChanged(event);
+ }
+ @Override
+ public String toString() {
+ return "dateTime seconds listener";
+ }
+ };
+ }
+
+ protected SelectionListener buildDateTimeSelectionListener() {
+ return new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ DateTimeModelAdapter.this.dateTimeSelected(e);
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+
+ @Override
+ public String toString() {
+ return "dateTime selection listener";
+ }
+ };
+ }
+
+ protected DisposeListener buildDateTimeDisposeListener() {
+ return new DisposeListener() {
+ public void widgetDisposed(DisposeEvent event) {
+ DateTimeModelAdapter.this.dateTimeDisposed(event);
+ }
+ @Override
+ public String toString() {
+ return "dateTime dispose listener";
+ }
+ };
+ }
+
+
+ // ********** model events **********
+
+ protected void hoursChanged(PropertyChangeEvent event) {
+ if (!this.locked) {
+ this.updateDateTimeHours((Integer) event.getNewValue());
+ }
+ }
+
+ protected void minutesChanged(PropertyChangeEvent event) {
+ if (!this.locked) {
+ this.updateDateTimeMinutes((Integer) event.getNewValue());
+ }
+ }
+
+ protected void secondsChanged(PropertyChangeEvent event) {
+ if (!this.locked) {
+ this.updateDateTimeSeconds((Integer) event.getNewValue());
+ }
+ }
+
+ // ********** dateTime events **********
+
+ protected void dateTimeSelected(SelectionEvent event) {
+ if (!this.locked) {
+ this.locked = true;
+ try {
+ //too bad they didn't split the event up
+ hoursSelected();
+ minutesSelected();
+ secondsSelected();
+ }
+ finally {
+ this.locked = false;
+ }
+ }
+ }
+
+ protected void hoursSelected() {
+ Integer hours = null;
+ if (this.dateTime.getHours() != 0) {
+ hours = Integer.valueOf(this.dateTime.getHours());
+ }
+ this.hoursHolder.setValue(hours);
+ }
+
+ protected void minutesSelected() {
+ Integer minutes = null;
+ if (this.dateTime.getMinutes() != 0) {
+ minutes = Integer.valueOf(this.dateTime.getMinutes());
+ }
+ this.minutesHolder.setValue(minutes);
+ }
+
+ protected void secondsSelected() {
+ Integer seconds = null;
+ if (this.dateTime.getSeconds() != 0) {
+ seconds = Integer.valueOf(this.dateTime.getSeconds());
+ }
+ this.secondsHolder.setValue(seconds);
+ }
+
+ protected void dateTimeDisposed(DisposeEvent event) {
+ // the dateTime is not yet "disposed" when we receive this event
+ // so we can still remove our listeners
+ this.dateTime.removeDisposeListener(this.dateTimeDisposeListener);
+ this.dateTime.removeSelectionListener(this.dateTimeSelectionListener);
+ this.hoursHolder.removePropertyChangeListener(PropertyValueModel.VALUE, this.hoursPropertyChangeListener);
+ this.minutesHolder.removePropertyChangeListener(PropertyValueModel.VALUE, this.minutesPropertyChangeListener);
+ this.secondsHolder.removePropertyChangeListener(PropertyValueModel.VALUE, this.secondsPropertyChangeListener);
+ }
+
+ // ********** update **********
+
+ protected void updateDateTimeHours(Integer hours) {
+ if (this.dateTime.isDisposed()) {
+ return;
+ }
+ if (hours == null) {
+ hours = Integer.valueOf(0);//TODO defaultHours
+ }
+ this.locked = true;
+ try {
+ this.dateTime.setHours(hours.intValue());
+ }
+ finally {
+ this.locked = false;
+ }
+ }
+
+ protected void updateDateTimeMinutes(Integer minutes) {
+ if (this.dateTime.isDisposed()) {
+ return;
+ }
+ if (minutes == null) {
+ minutes = Integer.valueOf(0);//TODO defaultMinutes
+ }
+ this.locked = true;
+ try {
+ this.dateTime.setMinutes(minutes.intValue());
+ }
+ finally {
+ this.locked = false;
+ }
+ }
+
+ protected void updateDateTimeSeconds(Integer seconds) {
+ if (this.dateTime.isDisposed()) {
+ return;
+ }
+ if (seconds == null) {
+ seconds = Integer.valueOf(0);//TODO defaultSeconds
+ }
+ this.locked = true;
+ try {
+ this.dateTime.setSeconds(seconds.intValue());
+ }
+ finally {
+ this.locked = false;
+ }
+ }
+
+ // ********** standard methods **********
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.hoursHolder);
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/DefaultWidgetFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/DefaultWidgetFactory.java
index feb75a9138..ae23f0c27d 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/DefaultWidgetFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/DefaultWidgetFactory.java
@@ -16,6 +16,7 @@ import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
@@ -107,6 +108,13 @@ public class DefaultWidgetFactory implements WidgetFactory {
public Composite createComposite(Composite parent) {
return new Composite(parent, SWT.NULL);
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public DateTime createDateTime(Composite parent, int style) {
+ return new DateTime(parent, style);
+ }
/**
* {@inheritDoc}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/FormWidgetFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/FormWidgetFactory.java
index db31c1840a..a522ad1d79 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/FormWidgetFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/FormWidgetFactory.java
@@ -18,6 +18,7 @@ import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
@@ -160,9 +161,21 @@ public class FormWidgetFactory implements WidgetFactory {
*/
public Composite createComposite(Composite parent) {
Composite composite = widgetFactory.createComposite(parent);
- widgetFactory.paintBordersFor(composite);
+ widgetFactory.paintBordersFor(composite);
return composite;
}
+ /**
+ * {@inheritDoc}
+ */
+ public DateTime createDateTime(Composite parent, int style) {
+ parent = createBorderContainer(parent);
+
+ DateTime dateTime = new DateTime(parent, style | SWT.FLAT);
+ dateTime.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
+ this.widgetFactory.adapt(dateTime, true, false);
+
+ return dateTime;
+ }
/**
* {@inheritDoc}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/Pane.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/Pane.java
index 8e4a270bb5..6a7ee5a0d2 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/Pane.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/Pane.java
@@ -21,6 +21,7 @@ import org.eclipse.jpt.ui.internal.listeners.SWTPropertyChangeListenerWrapper;
import org.eclipse.jpt.ui.internal.swt.BooleanButtonModelAdapter;
import org.eclipse.jpt.ui.internal.swt.CComboModelAdapter;
import org.eclipse.jpt.ui.internal.swt.ComboModelAdapter;
+import org.eclipse.jpt.ui.internal.swt.DateTimeModelAdapter;
import org.eclipse.jpt.ui.internal.swt.SpinnerModelAdapter;
import org.eclipse.jpt.ui.internal.swt.TextFieldModelAdapter;
import org.eclipse.jpt.ui.internal.swt.TriStateCheckBoxModelAdapter;
@@ -53,6 +54,7 @@ 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.DateTime;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Layout;
@@ -2040,6 +2042,63 @@ public abstract class Pane<T extends Model>
}
/**
+ * Creates a new managed DateTime of type SWT.TIME. Managed means that this Pane will
+ * handle enabling/disabling of this widget if a PaneEnabler is used.
+ *
+ * @param parent The parent container
+ * @param hoursHolder The holder of the hours integer value
+ * @param minutesHolder The holder of the minutes integer value
+ * @param secondsHolder The holder of the seconds integer value
+ * @param helpId The topic help ID to be registered for the new dateTime
+ * @return The newly created <code>DateTime</code>
+ *
+ * @category Layout
+ */
+ protected final DateTime addDateTime(Composite parent,
+ WritablePropertyValueModel<Integer> hoursHolder,
+ WritablePropertyValueModel<Integer> minutesHolder,
+ WritablePropertyValueModel<Integer> secondsHolder,
+ String helpId) {
+
+ DateTime dateTime = this.addUnmanagedDateTime(parent, hoursHolder, minutesHolder, secondsHolder, helpId);
+ this.manageWidget(dateTime);
+
+ return dateTime;
+ }
+
+
+ /**
+ * Creates a new unmanaged DateTime of type SWT.TIME. Unmanaged means that this Pane will
+ * not handle the enabling/disabling of this widget. The owning object will handle
+ * it with its own PaneEnabler or ControlEnabler.
+ *
+ * @param parent The parent container
+ * @param hoursHolder The holder of the hours integer value
+ * @param minutesHolder The holder of the minutes integer value
+ * @param secondsHolder The holder of the seconds integer value
+ * @param helpId The topic help ID to be registered for the new dateTime
+ * @return The newly created <code>DateTime</code>
+ *
+ * @category Layout
+ */
+ protected final DateTime addUnmanagedDateTime(Composite parent,
+ WritablePropertyValueModel<Integer> hoursHolder,
+ WritablePropertyValueModel<Integer> minutesHolder,
+ WritablePropertyValueModel<Integer> secondsHolder,
+ String helpId) {
+
+ DateTime dateTime = this.widgetFactory.createDateTime(parent, SWT.TIME);
+
+ DateTimeModelAdapter.adapt(hoursHolder, minutesHolder, secondsHolder, dateTime);
+
+ if (helpId != null) {
+ getHelpSystem().setHelp(dateTime, helpId);
+ }
+
+ return dateTime;
+ }
+
+ /**
* Creates a new container that will have a text field as the center control
* labeled with the given label.
*
@@ -3027,12 +3086,30 @@ public abstract class Pane<T extends Model>
String title,
String helpId) {
+ return addTitledGroup(container, title, 1, helpId);
+ }
+
+ /**
+ * Creates a new container with a titled border.
+ *
+ * @param title The text of the titled border
+ * @param container The parent container
+ * @param helpId The topic help ID to be registered for the new group
+ * @return The newly created <code>Composite</code> with a titled border
+ *
+ * @category Layout
+ */
+ protected final Group addTitledGroup(Composite container,
+ String title,
+ int columnCount,
+ String helpId) {
+
Group group = this.widgetFactory.createGroup(container, title);
//manageWidget(group); TODO unsure if I want to manage groups,
//also should probably rename this addUnmanagedTitledPane
group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- GridLayout layout = new GridLayout(1, false);
+ GridLayout layout = new GridLayout(columnCount, false);
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.marginTop = 5;

Back to the top