Commit cbfd2258 authored by Dumoulin Nicolas's avatar Dumoulin Nicolas
Browse files

modification applied for simple children (no list for example)

parent c3f0b056
......@@ -16,7 +16,7 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jSplitPane1" alignment="0" pref="421" max="32767" attributes="0"/>
<Component id="jSplitPane1" min="-2" pref="707" max="-2" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
......@@ -30,9 +30,6 @@
<Properties>
<Property name="dividerSize" type="int" value="6"/>
<Property name="resizeWeight" type="double" value="0.1"/>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="new Dimension(jTablePreferredSize.width+editorPreferredSize.width, Math.max(jTablePreferredSize.height,editorPreferredSize.height))" type="code"/>
</Property>
</Properties>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout"/>
......
......@@ -73,6 +73,7 @@ public class NodesAndPanelsPanel extends JPanel implements ListSelectionListener
// build form and adjust UI settings
initComponents();
jSplitPane1.setPreferredSize(new Dimension(jTablePreferredSize.width + editorPreferredSize.width, Math.max(jTablePreferredSize.height, editorPreferredSize.height)));
jSplitPane1.setDividerLocation(jTablePreferredSize.width);
jTable.setPreferredScrollableViewportSize(jTable.getPreferredSize());
// adjust the table renderer and listener
Outline outline = (Outline) jTable;
......@@ -136,10 +137,12 @@ public class NodesAndPanelsPanel extends JPanel implements ListSelectionListener
* @return the object edited after applying all the modifications.
*/
public Object applyChanges() {
// TODO
// - browse the tree and invoke AbstractOhEditor.getValue ?
// - beware of the parts of tree that are involved in several editors
return ((OhComplexTreeNode)treeModel.getRoot()).getContent().getValue();
// the DefaultObjectEditor will recursively apply changes
// TODO how to manage objects that appears in tree (skipped because of
// EditorsProvider.hasEditorFor(child) in DefaultObjectEditor constructor)
OhObjectComplex rootOhObjectComplex = ((OhComplexTreeNode) treeModel.getRoot()).getContent();
AbstractOhEditor<Object, JComponent> rootEditor = editorsMap.get(rootOhObjectComplex);
return rootEditor.getValue();
}
/** This method is called from within the constructor to
......@@ -159,7 +162,6 @@ public class NodesAndPanelsPanel extends JPanel implements ListSelectionListener
jSplitPane1.setDividerSize(6);
jSplitPane1.setResizeWeight(0.1);
jSplitPane1.setPreferredSize(new Dimension(jTablePreferredSize.width+editorPreferredSize.width, Math.max(jTablePreferredSize.height,editorPreferredSize.height)));
jScrollPaneRight.setMaximumSize(editorMaxSize);
jScrollPaneRight.setMinimumSize(editorMinSize);
......@@ -186,7 +188,7 @@ public class NodesAndPanelsPanel extends JPanel implements ListSelectionListener
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 421, Short.MAX_VALUE)
.addComponent(jSplitPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 707, javax.swing.GroupLayout.PREFERRED_SIZE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
......
......@@ -18,14 +18,15 @@ package fr.cemagref.ohoui.ui.swing.panels;
import fr.cemagref.ohoui.structure.OhObject;
import fr.cemagref.ohoui.structure.OhObjectComplex;
import java.awt.BorderLayout;
import java.awt.Component;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import javax.swing.BoxLayout;
import javax.swing.JComponent;
import javax.swing.JPanel;
import org.openide.util.Exceptions;
/**
* Default implementation of editor for an ohObjectComplex, it produces an editor by
......@@ -35,38 +36,25 @@ import javax.swing.JPanel;
*/
public class DefaultObjectEditor extends AbstractOhEditor<Object, JComponent> {
private List<FieldAndEditor> fieldAndOUIPanels = new ArrayList<FieldAndEditor>();
private List<AbstractOhEditor> childrenEditors = new ArrayList<AbstractOhEditor>();
public DefaultObjectEditor(OhObjectComplex<?> object) {
super(object);
panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
JPanel panel2 = new JPanel();
panel.add(panel2, BorderLayout.NORTH);
panel2.setLayout(new BoxLayout(panel2, BoxLayout.PAGE_AXIS));
for (OhObject child : object) {
if (child.getValue() == null) {
// TODO add button for object creation
} else if (EditorsProvider.hasEditorFor(child)) {
panel.add((JComponent) EditorsProvider.createEditorFor(child).getPanel());
AbstractOhEditor<Object, JComponent> editor = EditorsProvider.createEditorFor(child);
panel2.add((JComponent) editor.getPanel());
childrenEditors.add(editor);
}
}
}
@Override
public OhObject getOhObject() {
for (FieldAndEditor fieldAndOUIPanel : fieldAndOUIPanels) {
if (fieldAndOUIPanel.editor.isEnabled()) {
try {
fieldAndOUIPanel.field.set(super.object, fieldAndOUIPanel.editor.getOhObject().getValue());
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
System.err.println("Error while trying to modify : " + fieldAndOUIPanel.field);
e.printStackTrace();
}
}
}
return super.object;
}
@Override
public boolean isEnabled() {
return panel.isEnabled();
......@@ -90,17 +78,17 @@ public class DefaultObjectEditor extends AbstractOhEditor<Object, JComponent> {
@Override
public Object getValue() {
throw new UnsupportedOperationException("Not supported yet.");
}
private static class FieldAndEditor {
public Field field;
public OhEditorPanel editor;
public FieldAndEditor(Field field, OhEditorPanel editor) {
this.field = field;
this.editor = editor;
for (AbstractOhEditor editor : childrenEditors) {
if (editor.isEnabled()) {
try {
editor.getOhObject().setValue(editor.getValue());
} catch (IllegalArgumentException ex) {
Exceptions.printStackTrace(ex);
} catch (IllegalAccessException ex) {
Exceptions.printStackTrace(ex);
}
}
}
return getOhObject();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment