incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ke...@apache.org
Subject svn commit: r1144678 - in /incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components: scalars/ scalars/primitive/ widgets/dropdownchoices/ widgets/valuecollection/
Date Sat, 09 Jul 2011 14:35:37 GMT
Author: kevin
Date: Sat Jul  9 14:35:37 2011
New Revision: 1144678

URL: http://svn.apache.org/viewvc?rev=1144678&view=rev
Log:
I made some progress, but then lost it. This is a transient commit, with choices support disabled
(see ComponentFactoryScalarAbstract#createComponent ). 

Added:
    incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/dropdownchoices/DropDownChoicesForValueMementos.java
  (with props)
    incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/valuecollection/ValueCollection.css
  (with props)
    incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/valuecollection/ValueCollection.html
  (with props)
Modified:
    incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/ComponentFactoryScalarAbstract.java
    incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/ScalarPanelAbstract.java
    incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/primitive/BooleanPanel.java
    incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/valuecollection/ValueCollection.java

Modified: incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/ComponentFactoryScalarAbstract.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/ComponentFactoryScalarAbstract.java?rev=1144678&r1=1144677&r2=1144678&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/ComponentFactoryScalarAbstract.java
(original)
+++ incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/ComponentFactoryScalarAbstract.java
Sat Jul  9 14:35:37 2011
@@ -19,11 +19,12 @@
 
 package org.apache.isis.viewer.wicket.ui.components.scalars;
 
+import org.apache.wicket.Component;
+import org.apache.wicket.model.IModel;
+
 import org.apache.isis.viewer.wicket.model.models.ScalarModel;
 import org.apache.isis.viewer.wicket.ui.ComponentFactoryAbstract;
 import org.apache.isis.viewer.wicket.ui.ComponentType;
-import org.apache.wicket.Component;
-import org.apache.wicket.model.IModel;
 
 public abstract class ComponentFactoryScalarAbstract extends ComponentFactoryAbstract {
 
@@ -45,10 +46,20 @@ public abstract class ComponentFactorySc
         return appliesIf(scalarModel.isScalarTypeAnyOf(scalarTypes));
     }
 
+    int choiceCount = 0;
+
     @Override
     public final Component createComponent(final String id, final IModel<?> model)
{
         final ScalarModel scalarModel = (ScalarModel) model;
         return createComponent(id, scalarModel);
+
+        // TODO: This is where the ValueCollection panel gets created.
+        // final List<ObjectAdapter> choices = scalarModel.getChoices();
+        // if (choices.size() > 0) {
+        // return new ValueCollection(id, scalarModel);
+        // } else {
+        // return createComponent(id, scalarModel);
+        // }
     }
 
     protected abstract Component createComponent(String id, ScalarModel scalarModel);

Modified: incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/ScalarPanelAbstract.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/ScalarPanelAbstract.java?rev=1144678&r1=1144677&r2=1144678&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/ScalarPanelAbstract.java
(original)
+++ incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/ScalarPanelAbstract.java
Sat Jul  9 14:35:37 2011
@@ -19,14 +19,15 @@
 
 package org.apache.isis.viewer.wicket.ui.components.scalars;
 
-import org.apache.isis.viewer.wicket.model.models.ScalarModel;
-import org.apache.isis.viewer.wicket.ui.panels.PanelAbstract;
 import org.apache.wicket.Component;
 import org.apache.wicket.behavior.AttributeAppender;
 import org.apache.wicket.markup.html.form.FormComponentLabel;
 import org.apache.wicket.markup.html.form.LabeledWebMarkupContainer;
 import org.apache.wicket.model.Model;
 
+import org.apache.isis.viewer.wicket.model.models.ScalarModel;
+import org.apache.isis.viewer.wicket.ui.panels.PanelAbstract;
+
 /**
  * Adapter for {@link PanelAbstract panel}s that use a {@link ScalarModel} as their backing
model.
  * 
@@ -77,10 +78,12 @@ public abstract class ScalarPanelAbstrac
 
     protected Component componentIfCompact;
     private Component componentIfRegular;
+    protected final ScalarModel scalarModel;
 
     public ScalarPanelAbstract(final String id, final ScalarModel scalarModel) {
         super(id, scalarModel);
         setFormat(Format.REGULAR);
+        this.scalarModel = scalarModel;
     }
 
     protected Format getFormat() {

Modified: incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/primitive/BooleanPanel.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/primitive/BooleanPanel.java?rev=1144678&r1=1144677&r2=1144678&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/primitive/BooleanPanel.java
(original)
+++ incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/primitive/BooleanPanel.java
Sat Jul  9 14:35:37 2011
@@ -85,7 +85,8 @@ public class BooleanPanel extends Scalar
 
             @Override
             public Boolean getObject() {
-                final ObjectAdapter adapter = getModel().getObject();
+                final ScalarModel model = getModel();
+                final ObjectAdapter adapter = model.getObject();
                 return (Boolean) adapter.getObject();
             }
 

Added: incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/dropdownchoices/DropDownChoicesForValueMementos.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/dropdownchoices/DropDownChoicesForValueMementos.java?rev=1144678&view=auto
==============================================================================
--- incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/dropdownchoices/DropDownChoicesForValueMementos.java
(added)
+++ incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/dropdownchoices/DropDownChoicesForValueMementos.java
Sat Jul  9 14:35:37 2011
@@ -0,0 +1,65 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.viewer.wicket.ui.components.widgets.dropdownchoices;
+
+import java.util.List;
+
+import org.apache.wicket.markup.html.form.DropDownChoice;
+import org.apache.wicket.markup.html.form.IChoiceRenderer;
+import org.apache.wicket.model.IModel;
+
+import org.apache.isis.viewer.wicket.model.mementos.ObjectAdapterMemento;
+
+public class DropDownChoicesForValueMementos extends DropDownChoice<ObjectAdapterMemento>
{
+
+    private final static class ValueMementoRenderer implements IChoiceRenderer<ObjectAdapterMemento>
{
+
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        public Object getDisplayValue(final ObjectAdapterMemento nom) {
+            return nom.getObjectAdapter().titleString();
+        }
+
+        @Override
+        public String getIdValue(final ObjectAdapterMemento nom, final int index) {
+            return String.valueOf(index);
+        }
+
+    }
+
+    private static final long serialVersionUID = 1L;
+
+    public DropDownChoicesForValueMementos(final String id, final IModel<ObjectAdapterMemento>
model,
+        final IModel<? extends List<? extends ObjectAdapterMemento>> choices)
{
+        this(id, model, choices, new ValueMementoRenderer());
+    }
+
+    private DropDownChoicesForValueMementos(final String id, final IModel<ObjectAdapterMemento>
model,
+        final IModel<? extends List<? extends ObjectAdapterMemento>> choices,
+        final IChoiceRenderer<? super ObjectAdapterMemento> renderer) {
+        super(id, model, choices, renderer);
+    }
+
+    @Override
+    protected boolean wantOnSelectionChangedNotifications() {
+        return true;
+    }
+}
\ No newline at end of file

Propchange: incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/dropdownchoices/DropDownChoicesForValueMementos.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/valuecollection/ValueCollection.css
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/valuecollection/ValueCollection.css?rev=1144678&view=auto
==============================================================================
--- incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/valuecollection/ValueCollection.css
(added)
+++ incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/valuecollection/ValueCollection.css
Sat Jul  9 14:35:37 2011
@@ -0,0 +1,43 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+a.valueDetailsLink {
+	text-align: left;
+	display:inline;
+	border: 1px  #bfaea6 solid;
+	white-space:nowrap;
+	margin:0em;
+	padding: 1px;
+	padding-right: 1.6em;
+	padding-left: 0.4em;
+	font-weight: normal;
+	cursor:default;
+	
+	color: #A66144;
+	background-color: #C4D9EA;
+	text-decoration:none;
+/*	-moz-border-radius: 6px;
+	-webkit-border-radius: 6px;
+	border-radius: 6px; */
+}
+
+a.valueDetailsLink:hover {
+	color: #D7E7F5;
+	background-color: #407098;
+}

Propchange: incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/valuecollection/ValueCollection.css
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/valuecollection/ValueCollection.html
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/valuecollection/ValueCollection.html?rev=1144678&view=auto
==============================================================================
--- incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/valuecollection/ValueCollection.html
(added)
+++ incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/valuecollection/ValueCollection.html
Sat Jul  9 14:35:37 2011
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+  
+         http://www.apache.org/licenses/LICENSE-2.0
+         
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"  
+      xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd"  
+      xml:lang="en"  
+      lang="en">
+	<head></head>
+	<body>
+		<wicket:panel>
+			<div class="string scalarPanel">
+			
+			
+			<!--
+				<label for="scalarValue" wicket:id="scalarIfRegular">
+					<span wicket:id="scalarName" class="scalarName">[Label text]</span>
+					<select wicket:id="valueId"/>
+				</label>
+			-->
+				
+			<!-- works - sort of 
+				<select wicket:id="choices"/>
+				<label for="scalarValue" wicket:id="scalarIfRegular">
+	      			<span wicket:id="scalarName" class="scalarName">[Label text]</span>
+	      			<span class="scalarValue">
+	      				<input type="text" name="scalarValue" id="scalarValue" wicket:id="scalarValue"
/>
+	      			</span>
+				</label>
+			-->
+				<label wicket:id="scalarIfCompact"></label>
+      			<span wicket:id="feedback"></span>
+				
+			</div>
+		</wicket:panel>
+	</body>
+</html>
+<!-- 
+	<wicket:head>
+		<wicket:link>
+			<link href="ValueCollection.css" rel="stylesheet" type="text/css"/>
+		</wicket:link>
+	</wicket:head>
+-->
\ No newline at end of file

Propchange: incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/valuecollection/ValueCollection.html
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/valuecollection/ValueCollection.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/valuecollection/ValueCollection.java?rev=1144678&r1=1144677&r2=1144678&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/valuecollection/ValueCollection.java
(original)
+++ incubator/isis/trunk/framework/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/valuecollection/ValueCollection.java
Sat Jul  9 14:35:37 2011
@@ -16,23 +16,218 @@
  */
 package org.apache.isis.viewer.wicket.ui.components.widgets.valuecollection;
 
+import java.util.List;
+
+import com.google.common.collect.Lists;
+
+import org.apache.wicket.AttributeModifier;
+import org.apache.wicket.Component;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.form.FormComponentLabel;
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.markup.html.panel.ComponentFeedbackPanel;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
+
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.viewer.wicket.model.models.EntityModel;
-import org.apache.isis.viewer.wicket.ui.components.widgets.formcomponent.FormComponentPanelAbstract;
+import org.apache.isis.core.metamodel.facets.maxlen.MaxLengthFacet;
+import org.apache.isis.core.metamodel.facets.typicallen.TypicalLengthFacet;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.viewer.wicket.model.mementos.ObjectAdapterMemento;
+import org.apache.isis.viewer.wicket.model.models.ScalarModel;
+import org.apache.isis.viewer.wicket.model.util.Generics;
+import org.apache.isis.viewer.wicket.model.util.Mementos;
+import org.apache.isis.viewer.wicket.ui.components.scalars.ScalarPanelAbstract;
+import org.apache.isis.viewer.wicket.ui.components.widgets.dropdownchoices.DropDownChoicesForValueMementos;
 
 /**
  * Initial skeleton - trying to add support for value choices.
  * 
  * @version $Rev$ $Date$
  */
-public class ValueCollection extends FormComponentPanelAbstract<ObjectAdapter> {
-
+public class ValueCollection extends ScalarPanelAbstract { // ScalarPanelTextFieldAbstract
     private static final long serialVersionUID = 1L;
 
-    public ValueCollection(final String id, final EntityModel entityModel) {
-        super(id, entityModel);
-        setType(ObjectAdapter.class);
-        // buildGui();
+    private static final String ID_SCALAR_IF_REGULAR = "scalarIfRegular";
+    private static final String ID_SCALAR_IF_COMPACT = "scalarIfCompact";
+    private static final String ID_FEEDBACK = "feedback";
+
+    private static final String ID_SCALAR_NAME = "scalarName";
+    private static final String ID_SCALAR_VALUE = "scalarValue";
+
+    private static final String ID_VALUE_ID = "valueId";
+
+    public ValueCollection(final String id, final ScalarModel scalarModel) {
+        super(id, scalarModel);
+        // this.idTextField = ID_SCALAR_VALUE;
+    }
+
+    @Override
+    protected FormComponentLabel addComponentForRegular() {
+        // buildGui);
+        valueIdField = createField();
+        syncWithInput();
+        // }}
+
+        addStandardSemantics();
+        // addSemantics();
+
+        final FormComponentLabel labelIfRegular = createFormComponentLabel();
+        addOrReplace(labelIfRegular);
+
+        addOrReplace(new ComponentFeedbackPanel(ID_FEEDBACK, valueIdField));
+        return labelIfRegular;
+    }
+
+    private TextField<ObjectAdapterMemento> createField() {
+
+        return new TextField<ObjectAdapterMemento>(ID_VALUE_ID, new Model<ObjectAdapterMemento>()
{
+
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public ObjectAdapterMemento getObject() {
+                if (pending != null) {
+                    return pending;
+                }
+                final ObjectAdapter adapter = ValueCollection.this.getModelValue();
+                return ObjectAdapterMemento.createOrNull(adapter);
+            }
+
+            @Override
+            public void setObject(final ObjectAdapterMemento adapterMemento) {
+                pending = adapterMemento;
+            }
+
+        }) {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            protected void onModelChanged() {
+                super.onModelChanged();
+                syncWithInput();
+            }
+
+        };
+    }
+
+    protected void addStandardSemantics() {
+        setRequiredIfSpecified();
+        setTextFieldSizeIfSpecified();
+    }
+
+    private void setRequiredIfSpecified() {
+        final ScalarModel scalarModel = getModel();
+        final boolean required = scalarModel.isRequired();
+        valueIdField.setRequired(required);
+    }
+
+    private void setTextFieldSizeIfSpecified() {
+        final int size = determineSize();
+        if (size != -1) {
+            valueIdField.add(new AttributeModifier("size", true, new Model<String>(""
+ size)));
+        }
+    }
+
+    private int determineSize() {
+        final ScalarModel scalarModel = getModel();
+        final ObjectSpecification noSpec = scalarModel.getTypeOfSpecification();
+
+        final TypicalLengthFacet typicalLengthFacet = noSpec.getFacet(TypicalLengthFacet.class);
+        if (typicalLengthFacet != null) {
+            return typicalLengthFacet.value();
+        }
+        final MaxLengthFacet maxLengthFacet = noSpec.getFacet(MaxLengthFacet.class);
+        if (maxLengthFacet != null) {
+            return maxLengthFacet.value();
+        }
+        return -1;
+    }
+
+    protected FormComponentLabel createFormComponentLabel() {
+        final String name = getModel().getName();
+        valueIdField.setLabel(Model.of(name));
+
+        final FormComponentLabel scalarNameAndValue = new FormComponentLabel(ID_SCALAR_IF_REGULAR,
valueIdField);
+
+        scalarNameAndValue.add(valueIdField);
+
+        final Label scalarName = new Label(ID_SCALAR_NAME, getFormat().getLabelCaption(valueIdField));
+        scalarNameAndValue.add(scalarName);
+
+        return scalarNameAndValue;
+    }
+
+    @Override
+    protected Component addComponentForCompact() {
+        final Label labelIfCompact = new Label(ID_SCALAR_IF_COMPACT, getModel().getObjectAsString());
+        addOrReplace(labelIfCompact);
+        return labelIfCompact;
+    }
+
+    /**
+     * Builds the parts of the GUI that are not dynamic.
+     * 
+     * @return
+     */
+    // private void buildGui() {
+    // addOrReplaceIdField();
+    // syncWithInput();
+    // }
+
+    private TextField<ObjectAdapterMemento> valueIdField;
+    static final String ID_VALUE_DETAILS = "valueDetails";
+    private ObjectAdapterMemento pending;
+
+    // private void addOrReplaceIdField() {
+    // valueIdField.setType(ObjectAdapterMemento.class);
+    // // addOrReplace(valueIdField);
+    // valueIdField.setVisible(false);
+    // }
+
+    protected ObjectAdapter getModelValue() {
+        return scalarModel.getObject();
+    }
+
+    private ObjectAdapter getPendingAdapter() {
+        final ObjectAdapterMemento memento = valueIdField.getModelObject();
+        return memento != null ? memento.getObjectAdapter() : null;
+    }
+
+    private void syncWithInput() {
+        final ObjectAdapter adapter = Generics.coalesce(getPendingAdapter(), scalarModel.getObject());
+
+        // choices drop-down
+        final IModel<List<? extends ObjectAdapterMemento>> choicesMementos =
getChoicesModel();
+
+        final IModel<ObjectAdapterMemento> modelObject = valueIdField.getModel();
+        final DropDownChoicesForValueMementos dropDownChoicesForValueMementos =
+            new DropDownChoicesForValueMementos(ID_SCALAR_VALUE, modelObject, choicesMementos);
+        addOrReplace(dropDownChoicesForValueMementos);
+
+        // link
+        // syncEntityDetailsButtonWithInput(adapter);
+        syncValueDetailsWithInput(adapter);
+    }
+
+    private void syncValueDetailsWithInput(final ObjectAdapter adapter) {
+        if (adapter != null && scalarModel.isEntityDetailsVisible()) {
+            // final ScalarModel entityModel = new ScalarModel(adapter);
+            // addOrReplace(new EntityCombinedPanel(ID_VALUE_DETAILS, entityModel));
+        } else {
+            permanentlyHide(ID_VALUE_DETAILS);
+        }
+    }
+
+    private IModel<List<? extends ObjectAdapterMemento>> getChoicesModel() {
+        final List<ObjectAdapter> choices = scalarModel.getChoices();
+        if (choices.size() == 0) {
+            return null;
+        }
+        // take a copy otherwise is only lazily evaluated
+        final List<ObjectAdapterMemento> choicesMementos =
+            Lists.newArrayList(Lists.transform(choices, Mementos.fromAdapter()));
+        return Model.ofList(choicesMementos);
     }
 
 }



Mime
View raw message