diff options
author | Torsten Sommer | 2013-06-22 13:35:47 +0000 |
---|---|---|
committer | Torsten Sommer | 2013-06-22 13:35:47 +0000 |
commit | 906352478b9dc9dbb57d502d81d3be0e94684633 (patch) | |
tree | 391a37479697c8ea526e6809d44bde78191b644c /bundles | |
parent | 92db07bfe7951489b5e92cac38d1f935c38217bd (diff) | |
download | org.eclipse.efxclipse-906352478b9dc9dbb57d502d81d3be0e94684633.tar.gz org.eclipse.efxclipse-906352478b9dc9dbb57d502d81d3be0e94684633.tar.xz org.eclipse.efxclipse-906352478b9dc9dbb57d502d81d3be0e94684633.zip |
Date picker added. Styling improved.
Diffstat (limited to 'bundles')
6 files changed, 134 insertions, 19 deletions
diff --git a/bundles/runtime/org.eclipse.fx.ecp.ui/plugin.xml b/bundles/runtime/org.eclipse.fx.ecp.ui/plugin.xml index 701f046e7..257c709a2 100644 --- a/bundles/runtime/org.eclipse.fx.ecp.ui/plugin.xml +++ b/bundles/runtime/org.eclipse.fx.ecp.ui/plugin.xml @@ -44,14 +44,8 @@ <staticTest priority="1" singleValue="true" - supportedClassType="java.util.Date"> - </staticTest> - <staticTest - priority="1" - singleValue="true" supportedClassType="java.lang.String"> </staticTest> - </factory> <factory class="org.eclipse.fx.ecp.ui.controls.EnumChoiceBox$Factory" @@ -218,6 +212,16 @@ supportedClassType="java.math.BigInteger"> </staticTest> </factory> + <factory + class="org.eclipse.fx.ecp.ui.controls.DateControl$Factory" + id="org.eclipse.fx.ecp.ui.controls.datePicker" + showLabel="true"> + <staticTest + priority="1" + singleValue="true" + supportedClassType="java.util.Date"> + </staticTest> + </factory> </extension> diff --git a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/ECPUtil.java b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/ECPUtil.java index 11e5deaa4..8d50ca8cf 100644 --- a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/ECPUtil.java +++ b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/ECPUtil.java @@ -29,15 +29,15 @@ import org.osgi.framework.Bundle; public class ECPUtil { public static final ComposedAdapterFactory DEFAULT_ADAPTER_FACTORY; - private static final String PACKAGE_IMAGE_URL = null; + private static final String PACKAGE_IMAGE_URL; static { DEFAULT_ADAPTER_FACTORY = new ComposedAdapterFactory(); DEFAULT_ADAPTER_FACTORY.addAdapterFactory(new ReflectiveItemProviderAdapterFactory()); DEFAULT_ADAPTER_FACTORY.addAdapterFactory(new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE)); -// Bundle bundle = Platform.getBundle("org.eclipse.fx.ecp.app"); -// URL entry = bundle.getEntry("icons/EPackage.gif"); -// PACKAGE_IMAGE_URL = entry.toExternalForm(); + Bundle bundle = Platform.getBundle("org.eclipse.fx.ecp.app"); + URL entry = bundle.getEntry("icons/EPackage.gif"); + PACKAGE_IMAGE_URL = entry.toExternalForm(); } public static TreeItem<ENamedElement> getConcreteClasses() { diff --git a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/DateControl.java b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/DateControl.java new file mode 100644 index 000000000..3e221053b --- /dev/null +++ b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/DateControl.java @@ -0,0 +1,98 @@ +package org.eclipse.fx.ecp.ui.controls; + +import java.time.LocalDate; +import java.util.Date; +import java.util.Objects; + +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.notify.impl.AdapterImpl; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecp.edit.ECPControlContext; +import org.eclipse.emf.edit.command.SetCommand; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.emf.edit.provider.IItemPropertyDescriptor; +import org.eclipse.fx.ecp.ui.ECPControl; + +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.scene.Node; +import javafx.scene.control.Control; +import javafx.scene.control.DatePicker; +import javafx.scene.control.SkinBase; +import javafx.scene.layout.HBox; + +public class DateControl extends Control { + + private EObject modelElement; + private EStructuralFeature feature; + private DatePicker datePicker; + + public DateControl(IItemPropertyDescriptor propertyDescriptor, ECPControlContext context) { + + modelElement = context.getModelElement(); + final EditingDomain editingDomain = context.getEditingDomain(); + feature = (EStructuralFeature) propertyDescriptor.getFeature(modelElement); + + setSkin(new Skin(this)); + + datePicker.valueProperty().addListener(new ChangeListener<LocalDate>() { + + @Override + public void changed(ObservableValue<? extends LocalDate> observableValue, LocalDate oldDate, LocalDate newDate) { + // only commit if the value has changed + if (!Objects.equals(oldDate, newDate)) { + @SuppressWarnings("deprecation") + Date date = new Date(newDate.getYear(), newDate.getMonthValue(), newDate.getDayOfMonth()); + Command command = SetCommand.create(editingDomain, modelElement, feature, date); + if (command.canExecute()) + editingDomain.getCommandStack().execute(command); + } + } + + }); + + modelElement.eAdapters().add(new AdapterImpl() { + + @Override + public void notifyChanged(Notification msg) { + if (msg.getFeature() == feature) + update(); + } + + }); + + update(); + } + + public void update() { + Date date = (Date) modelElement.eGet(feature); + if(date == null) + date = new Date(); + @SuppressWarnings("deprecation") + LocalDate localDate = LocalDate.of(date.getYear(), date.getMonth(), date.getDate()); + datePicker.valueProperty().set(localDate); + } + + private final class Skin extends SkinBase<DateControl> { + private Skin(DateControl control) { + super(control); + HBox hBox = new HBox(); + getChildren().add(hBox); + + datePicker = new DatePicker(); + hBox.getChildren().add(datePicker); + } + } + + public static class Factory implements ECPControl.Factory { + + @Override + public Node createControl(IItemPropertyDescriptor itemPropertyDescriptor, ECPControlContext context) { + return new DateControl(itemPropertyDescriptor, context); + } + + } + +} diff --git a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/ECPControls.css b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/ECPControls.css index 650937424..cdf430dc4 100644 --- a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/ECPControls.css +++ b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/ECPControls.css @@ -2,14 +2,23 @@ -fx-max-width: 200; } -.integer-control { - -fx-max-width: 200; +.model-element-form .spinner .text-input { + -fx-pref-width: 144; +} + +.model-element-form .date-picker { + -fx-pref-width: 200; + -fx-pref-height: 26; +} + +.model-element-form .check-box { + -fx-pref-height: 26; } .model-element-form .grid { - -fx-padding: 10.0; - -fx-hgap: 6.0; - -fx-vgap: 10.0; + -fx-padding: 20 25 25 20; + -fx-hgap: 15; + -fx-vgap: 15; } .up-button, .down-button, .remove-button { @@ -46,6 +55,10 @@ -fx-pref-width: 8; } +.decrease-button, .increase-button { + -fx-pref-width: 28; +} + .increase-button .plus { -fx-background-color: -fx-mark-highlight-color, -fx-mark-color; -fx-background-insets: 0 0 -1 0, 0; diff --git a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/numeric/NumberSpinner.java b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/numeric/NumberSpinner.java index d25c8f01b..0160067d9 100644 --- a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/numeric/NumberSpinner.java +++ b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/numeric/NumberSpinner.java @@ -163,7 +163,7 @@ public abstract class NumberSpinner extends Control implements ECPControl { this.feature = feature; this.editingDomain = editingDomain; - getStyleClass().add("integer-control"); + getStyleClass().add("spinner"); } @Override diff --git a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/form/DefaultModelElementForm.java b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/form/DefaultModelElementForm.java index f424ee0d5..be811eed3 100644 --- a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/form/DefaultModelElementForm.java +++ b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/form/DefaultModelElementForm.java @@ -65,9 +65,9 @@ public class DefaultModelElementForm extends Control implements ModelElementForm label.getStyleClass().add("control-label"); GridPane.setValignment(label, VPos.TOP); gridPane.add(label, 0, i); - gridPane.setPadding(new Insets(20)); - gridPane.setVgap(10); - gridPane.setHgap(12); +// gridPane.setPadding(new Insets(20)); +// gridPane.setVgap(10); +// gridPane.setHgap(12); EStructuralFeature feature = (EStructuralFeature) propertyDescriptor.getFeature(modelElement); |