Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/MultiControl.java')
-rw-r--r--bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/MultiControl.java136
1 files changed, 107 insertions, 29 deletions
diff --git a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/MultiControl.java b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/MultiControl.java
index 21b6d7617..b27ba5f73 100644
--- a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/MultiControl.java
+++ b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/MultiControl.java
@@ -1,18 +1,19 @@
package org.eclipse.fx.ecp.ui.controls;
-import java.io.InputStream;
import java.net.URL;
-import java.util.List;
import java.util.Objects;
+import javafx.beans.property.Property;
+import javafx.beans.value.ChangeListener;
+import javafx.beans.value.ObservableValue;
+import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
-import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Button;
-import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.image.ImageView;
+import javafx.scene.input.InputMethodEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
@@ -27,15 +28,16 @@ import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecp.edit.ECPControlContext;
-import org.eclipse.emf.edit.command.DeleteCommand;
+import org.eclipse.emf.edit.command.AddCommand;
import org.eclipse.emf.edit.command.MoveCommand;
import org.eclipse.emf.edit.command.RemoveCommand;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
import org.eclipse.fx.ecp.ui.Control;
import org.eclipse.fx.ecp.ui.ECPUIPlugin;
+import org.eclipse.fx.emf.databinding.edit.EMFEditFXProperties;
+import org.eclipse.fx.emf.databinding.edit.EMFEditFXProperties.EListItemProperty;
import org.osgi.framework.Bundle;
@SuppressWarnings("all")
@@ -47,13 +49,20 @@ public class MultiControl extends VBox implements Control {
private EditingDomain editingDomain;
private EList<?> values;
private VBox controlsBox;
-
- public MultiControl(IItemPropertyDescriptor propertyDescriptor, ECPControlContext context) {
+ private Button addButton;
+ private TextField addTextField;
+ private Command addCommand;
+ private final ECPControlContext context;
+
+ public MultiControl(final EStructuralFeature feature, final ECPControlContext context) {
+ this.feature = feature;
+ this.context = context;
modelElement = context.getModelElement();
editingDomain = context.getEditingDomain();
- feature = (EStructuralFeature) propertyDescriptor.getFeature(modelElement);
values = (EList<?>) modelElement.eGet(feature);
+ setSpacing(4);
+
controlsBox = new VBox();
getChildren().add(controlsBox);
controlsBox.setSpacing(4);
@@ -61,8 +70,42 @@ public class MultiControl extends VBox implements Control {
for (int i = 0; i < values.size(); i++) {
controlsBox.getChildren().add(new ControlWrapper(i));
}
+
+ HBox hBox = new HBox();
+ getChildren().add(hBox);
+
+ addTextField = new TextField();
+ hBox.getChildren().add(addTextField);
+// addTextField.setText(feature.getDefaultValue().toString());
+ addTextField.setPromptText("Enter a value");
+ addTextField.setStyle("-fx-background-radius: 3 0 0 3, 2 0 0 2; -fx-background-insets: 0 0 1 0, 1 1 2 1;");
+ addTextField.setMaxWidth(Double.MAX_VALUE);
+ HBox.setHgrow(addTextField, Priority.ALWAYS);
+ addTextField.textProperty().addListener(new ChangeListener<String>() {
+
+ @Override
+ public void changed(ObservableValue<? extends String> arg0, String arg1, String arg2) {
+ updateAddButton();
+ }
+
- getChildren().add(new Button(null, getImage("icons/add.png")));
+ });
+
+ addButton = new Button(null, getImage("icons/add.png"));
+ hBox.getChildren().add(addButton);
+ addButton.getStyleClass().add("right-pill");
+ addButton.setOnAction(new EventHandler<ActionEvent>() {
+
+ @Override
+ public void handle(ActionEvent arg0) {
+ if(addCommand != null && addCommand.canExecute()) {
+ editingDomain.getCommandStack().execute(addCommand);
+ addTextField.setText(null);
+ addTextField.requestFocus();
+ }
+ }
+
+ });
modelElement.eAdapters().add(new AdapterImpl() {
@@ -72,34 +115,51 @@ public class MultiControl extends VBox implements Control {
if (Objects.equals(msg.getFeature(), feature)) {
final int position = msg.getPosition();
-
+
+ final ObservableList<Node> children = controlsBox.getChildren();
+
switch (msg.getEventType()) {
case Notification.REMOVE:
- controlsBox.getChildren().remove(position);
+ children.remove(position);
break;
case Notification.MOVE:
int oldIndex = ((Integer) msg.getOldValue()).intValue();
- ControlWrapper controlWrapper = (ControlWrapper) controlsBox.getChildren().remove(oldIndex);
- controlsBox.getChildren().add(position, controlWrapper);
+ ControlWrapper controlWrapper = (ControlWrapper) children.remove(oldIndex);
+ children.add(position, controlWrapper);
controlWrapper.setIndex(position);
break;
- }
-
- for (Node node : controlsBox.getChildren()) {
- if(node instanceof ControlWrapper)
- ((ControlWrapper) node).updateButtons();
+ case Notification.ADD:
+ controlsBox.getChildren().add(new ControlWrapper(position));
}
+ for (int i = 0; i < children.size(); i++)
+ ((ControlWrapper) children.get(i)).setIndex(i);
+
+ updateButtons(children);
+
+ updateAddButton();
}
}
});
+
+ updateAddButton();
validationMessage = new ValidationMessage();
getChildren().add(validationMessage);
}
+ private void updateAddButton() {
+ addCommand = AddCommand.create(editingDomain, modelElement, feature, addTextField.getText());
+ addButton.setDisable(!addCommand.canExecute());
+ }
+
+ private void updateButtons(final ObservableList<Node> children) {
+ for (Node node : children)
+ ((ControlWrapper) node).updateButtons();
+ }
+
public static ImageView getImage(String resourcePath) {
Bundle bundle = Platform.getBundle(ECPUIPlugin.PLUGIN_ID);
Path path = new Path(resourcePath);
@@ -124,8 +184,8 @@ public class MultiControl extends VBox implements Control {
public static class Factory implements Control.Factory {
@Override
- public Control createControl(IItemPropertyDescriptor itemPropertyDescriptor, ECPControlContext context) {
- return new MultiControl(itemPropertyDescriptor, context);
+ public Control createControl(Property<?> property, EStructuralFeature feature, ECPControlContext context) {
+ return new MultiControl(feature, context);
}
}
@@ -138,13 +198,32 @@ public class MultiControl extends VBox implements Control {
public ControlWrapper(int initialIndex) {
index = initialIndex;
-
+
setFillHeight(true);
- TextField label = new TextField(values.get(initialIndex).toString());
- label.setMaxWidth(Double.MAX_VALUE);
- HBox.setHgrow(label, Priority.ALWAYS);
- label.setStyle("-fx-background-radius: 3 0 0 3, 2 0 0 2; -fx-background-insets: 0 0 1 0, 1 1 2 1;");
- getChildren().add(label);
+ Object value = values.get(initialIndex);
+
+ org.eclipse.fx.ecp.ui.Control.Factory factory = Control.Factory.Registry.INSTANCE.getFactory(feature, modelElement, false);
+
+
+// TextField label = new TextField();
+
+ try {
+ Property<?> property = EMFEditFXProperties.listItem(editingDomain, modelElement, feature, initialIndex);
+ Node control = (Node) factory.createControl(property, feature, context);
+ getChildren().add(control);
+// label.textProperty().bindBidirectional((Property<String>) property);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+// if(value != null)
+// label.setText(value.toString());
+// label.setPromptText("Please enter a value");
+// label.setMaxWidth(Double.MAX_VALUE);
+// HBox.setHgrow(label, Priority.ALWAYS);
+// label.setStyle("-fx-background-radius: 3 0 0 3, 2 0 0 2; -fx-background-insets: 0 0 1 0, 1 1 2 1;");
+// getChildren().add(label);
if (feature.isOrdered()) {
@@ -191,10 +270,9 @@ public class MultiControl extends VBox implements Control {
}
});
-
+
updateButtons();
}
-
public void setIndex(int index) {
this.index = index;

Back to the top