Commit 6119b40c authored by Dumoulin Nicolas's avatar Dumoulin Nicolas
Browse files

bugfixes and some refactoring. Now editing subobjects is working, but the...

bugfixes and some refactoring. Now editing subobjects is working, but the navigation buttons bar remains to do.
parent 7fa31a76
......@@ -20,32 +20,6 @@
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.1.1:exec</goal>
</goals>
<properties>
<exec.classpathScope>runtime</exec.classpathScope>
<exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath ${packageClassName}</exec.args>
<jpda.listen>true</jpda.listen>
<exec.executable>java</exec.executable>
</properties>
</action>
<action>
<actionName>debug</actionName>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.1.1:exec</goal>
</goals>
<properties>
<exec.classpathScope>runtime</exec.classpathScope>
<exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath fr.cemagref.ohoui.demo.View</exec.args>
<jpda.listen>true</jpda.listen>
<exec.executable>java</exec.executable>
</properties>
</action>
<action>
<actionName>debug</actionName>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.1.1:exec</goal>
</goals>
<properties>
<exec.classpathScope>runtime</exec.classpathScope>
<exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath fr.cemagref.ohoui.demo.View</exec.args>
......
......@@ -24,6 +24,8 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BoxLayout;
import javax.swing.JComponent;
......@@ -40,17 +42,26 @@ import org.openide.util.Lookup;
*
* @author Nicolas Dumoulin <nicolas.dumoulin@cemagref.fr>
*/
public class DefaultObjectEditor extends AbstractOhEditor<Object, JComponent> {
public class CommonDefaultObjectEditor extends AbstractOhEditor<Object, JComponent> {
private static final Logger LOGGER = Logger.getLogger(CommonDefaultObjectEditor.class.getName());
protected List<AbstractOhEditor> childrenEditors = new ArrayList<AbstractOhEditor>();
private JPanel pagePanel = new JPanel();
public DefaultObjectEditor(OhObjectComplex<?> object) {
public CommonDefaultObjectEditor(OhObjectComplex<?> object) {
super(object);
panel = new JPanel();
panel.add(pagePanel, BorderLayout.NORTH);
pagePanel.setLayout(new BoxLayout(pagePanel, BoxLayout.PAGE_AXIS));
for (OhObject child : object) {
}
/**
* Build the editor from the handled object. This method is intended to be
* called just after the constructor call.
*/
public void buildEditor() {
for (OhObject child : (OhObjectComplex<?>) object) {
LOGGER.log(Level.FINER, "Building editor for child {0}", object.getName());
// Editors retrieving for other types
List<Class> availableTypes = new ArrayList<Class>();
availableTypes.add(child.getDeclaredType());
......@@ -145,7 +156,7 @@ public class DefaultObjectEditor extends AbstractOhEditor<Object, JComponent> {
}
}
}
return getOhObject();
return getOhObject().getValue();
}
/**
......@@ -153,13 +164,13 @@ public class DefaultObjectEditor extends AbstractOhEditor<Object, JComponent> {
*/
private final class EditTypeAction implements ActionListener {
private DefaultObjectEditor container;
private CommonDefaultObjectEditor container;
private OhEditorPanel currentObjectEditor;
private OhObject ohObject;
private Class[] availableTypes;
private int editorIndex;
public EditTypeAction(DefaultObjectEditor container, OhEditorPanel currentObjectEditor, OhObject ohObject, Class[] availableTypes, int editorIndex) {
public EditTypeAction(CommonDefaultObjectEditor container, OhEditorPanel currentObjectEditor, OhObject ohObject, Class[] availableTypes, int editorIndex) {
this.container = container;
this.currentObjectEditor = currentObjectEditor;
this.ohObject = ohObject;
......
......@@ -20,9 +20,8 @@ import fr.cemagref.ohoui.structure.OhObject;
import fr.cemagref.ohoui.structure.OhObjectComplex;
import fr.cemagref.ohoui.ui.swing.basiccontrols.AbstractOhEditor;
import fr.cemagref.ohoui.ui.swing.basiccontrols.CommonDefaultObjectEditor;
import fr.cemagref.ohoui.ui.swing.basiccontrols.EditorsProvider;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JComponent;
/**
......@@ -31,20 +30,13 @@ import javax.swing.JComponent;
*
* @author Nicolas Dumoulin <nicolas.dumoulin@cemagref.fr>
*/
public class DefaultObjectEditor extends fr.cemagref.ohoui.ui.swing.basiccontrols.DefaultObjectEditor {
public class DefaultObjectEditor extends CommonDefaultObjectEditor {
private List<ObjectComplexEditorPanel> complexEditors;
private OhPanel container;
public DefaultObjectEditor(OhObjectComplex<?> object) {
public DefaultObjectEditor(OhPanel container, OhObjectComplex<?> object) {
super(object);
}
public void setContainer(OhPanel container) {
if (complexEditors != null) {
for (ObjectComplexEditorPanel editor : complexEditors) {
editor.setContainer(container);
}
}
this.container = container;
}
@Override
......@@ -53,17 +45,14 @@ public class DefaultObjectEditor extends fr.cemagref.ohoui.ui.swing.basiccontrol
if (editor != null) {
// TODO add button for reinstanciate object
addPanelAt((JComponent) editor.getPanel(), index);
registerEditor(editor);
} else {
if (!(object instanceof OhObjectComplex)) {
throw new UnsupportedOperationException("This case has not been planned.");
}
editor = new ObjectComplexEditorPanel((OhObjectComplex) object);
if (complexEditors == null) {
complexEditors = new ArrayList<ObjectComplexEditorPanel>();
}
complexEditors.add((ObjectComplexEditorPanel) editor);
((ObjectComplexEditorPanel)editor).setContainer(container);
addPanelAt(editor.getPanel(), index);
}
registerEditor(editor);
}
}
......@@ -17,10 +17,12 @@
package fr.cemagref.ohoui.ui.swing.onepanel;
import fr.cemagref.ohoui.structure.OhObjectComplex;
import fr.cemagref.ohoui.ui.swing.basiccontrols.AbstractOhEditor;
import fr.cemagref.ohoui.ui.swing.basiccontrols.OhEditorPanel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComponent;
/**
*
......@@ -44,7 +46,12 @@ public class ObjectComplexEditorPanel extends OhEditorPanel<Object> implements A
@Override
public Object getValue() {
return container.getEditorFor(super.object);
AbstractOhEditor<Object, JComponent> editor = container.getEditorFor(super.object);
if (editor != null) {
return editor.getValue();
} else {
return null;
}
}
@Override
......
......@@ -50,6 +50,7 @@ public class OhPanel extends JPanel {
private Map<Object, AbstractOhEditor<Object, JComponent>> editorsMap;
private CardLayout editorsCardLayout;
private final static String EMPTY_EDITOR_CODE = "empty";
private AbstractOhEditor<Object, JComponent> rootEditor;
/**
* Load an object for editing.
......@@ -69,8 +70,7 @@ public class OhPanel extends JPanel {
OhOuiContext ohOuiContext = new OhOuiContext();
OhObjectComplex ohObjectComplex = DefaultObjectIntrospector.introspect(title, o, ohOuiContext);
selectObject(ohObjectComplex);
rootEditor = selectObject(ohObjectComplex);
}
private String getCode(OhObjectComplex selectedObject) {
......@@ -81,7 +81,7 @@ public class OhPanel extends JPanel {
* Select an object for editing in the tree of the datastructure
* @param selectedObject
*/
public final void selectObject(OhObjectComplex selectedObject) {
public final AbstractOhEditor<Object, JComponent> selectObject(OhObjectComplex selectedObject) {
// find the path of the edited object from the root
OhObjectComplex current = selectedObject;
StringBuilder buff = new StringBuilder();
......@@ -102,6 +102,7 @@ public class OhPanel extends JPanel {
} else {
editorsCardLayout.show(editorsPanel, EMPTY_EDITOR_CODE);
}
return editor;
}
public final AbstractOhEditor<Object, JComponent> getEditorFor(OhObject selectedObject) {
......@@ -110,12 +111,11 @@ public class OhPanel extends JPanel {
// retrieve editor and put it in cache
if (EditorsProvider.hasEditorFor(selectedObject)) {
editor = EditorsProvider.createEditorFor(selectedObject);
// TODO following tests should be avoided by presence of correct producer
} else if (selectedObject instanceof OhObjectCollection) {
// TODO bring an editor with a list and add/remove buttons
} else if (selectedObject instanceof OhObjectComplex) {
editor = new DefaultObjectEditor((OhObjectComplex<?>) selectedObject);
((DefaultObjectEditor) editor).setContainer(this);
editor = new DefaultObjectEditor(this, (OhObjectComplex<?>) selectedObject);
((DefaultObjectEditor) editor).buildEditor();
} else {
// TODO pay attention if object value is null ?
editor = EditorsProvider.createEditorFor(selectedObject);
......@@ -126,6 +126,6 @@ public class OhPanel extends JPanel {
}
public void applyChanges() {
throw new UnsupportedOperationException("Not yet implemented");
rootEditor.getValue();
}
}
......@@ -20,6 +20,7 @@ import fr.cemagref.ohoui.structure.OhObject;
import fr.cemagref.ohoui.structure.OhObjectComplex;
import fr.cemagref.ohoui.ui.swing.basiccontrols.AbstractOhEditor;
import fr.cemagref.ohoui.ui.swing.basiccontrols.CommonDefaultObjectEditor;
import fr.cemagref.ohoui.ui.swing.basiccontrols.EditorsProvider;
import javax.swing.JComponent;
import javax.swing.JPanel;
......@@ -27,7 +28,7 @@ import javax.swing.JPanel;
/**
* @author Nicolas Dumoulin <nicolas.dumoulin@cemagref.fr>
*/
public class DefaultObjectEditor extends fr.cemagref.ohoui.ui.swing.basiccontrols.DefaultObjectEditor {
public class DefaultObjectEditor extends CommonDefaultObjectEditor {
public DefaultObjectEditor(OhObjectComplex<?> object) {
super(object);
......
......@@ -143,6 +143,7 @@ public class NodesAndPanelsPanel extends JPanel implements ListSelectionListener
// TODO bring an editor with a list and add/remove buttons
} else if (selectedObject instanceof OhObjectComplex) {
editor = new DefaultObjectEditor((OhObjectComplex<?>) selectedObject);
((DefaultObjectEditor) editor).buildEditor();
} else {
// TODO pay attention if object value is null ?
editor = EditorsProvider.createEditorFor(selectedObject);
......
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