Commit 5918eb7f authored by Dumoulin Nicolas's avatar Dumoulin Nicolas
Browse files

NEW implementation with only one panel (to be continued)

parent d6e842ee
......@@ -27,4 +27,30 @@
<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>
<jpda.listen>true</jpda.listen>
<exec.executable>java</exec.executable>
</properties>
</action>
</actions>
......@@ -33,6 +33,11 @@
<artifactId>lang</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ohoui-ui-swing-panels</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
<?xml version="1.0" encoding="UTF-8" ?>
<?xml version="1.1" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<AuxValues>
......
......@@ -4,6 +4,7 @@ import fr.cemagref.ohoui.annotations.Description;
import fr.cemagref.ohoui.ui.nodes.ValueProperty;
import fr.cemagref.ohoui.reflect.IntrospectionException;
import fr.cemagref.ohoui.ui.swing.NodesAndPanelsPanel;
import fr.cemagref.ohoui.ui.swing.onepanel.OhPanel;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.io.File;
......@@ -40,6 +41,7 @@ class MyClass {
}
class MyNestedClass {
double d = 3;
String s = "yep";
......@@ -47,7 +49,6 @@ class MyNestedClass {
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
}
public class View extends javax.swing.JPanel implements ExplorerManager.Provider {
......@@ -104,13 +105,24 @@ public class View extends javax.swing.JPanel implements ExplorerManager.Provider
JFrame f = new JFrame("OhOUI");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final MyClass myObject = new MyClass();
final NodesAndPanelsPanel nodesAndPanelsPanel = new NodesAndPanelsPanel(myObject);
/*final NodesAndPanelsPanel nodesAndPanelsPanel = new NodesAndPanelsPanel(myObject);
f.add(nodesAndPanelsPanel);
f.add(new JButton(new AbstractAction("Update and print to the console") {
@Override
public void actionPerformed(ActionEvent e) {
nodesAndPanelsPanel.applyChanges();
System.out.println(ToStringBuilder.reflectionToString(myObject));
}
}), BorderLayout.NORTH);*/
final OhPanel editionPanel = new OhPanel();
editionPanel.loadObject("Demo", myObject);
f.add(editionPanel);
f.add(new JButton(new AbstractAction("Update and print to the console") {
@Override
public void actionPerformed(ActionEvent e) {
nodesAndPanelsPanel.applyChanges();
editionPanel.applyChanges();
System.out.println(ToStringBuilder.reflectionToString(myObject));
}
}), BorderLayout.NORTH);
......
......@@ -24,9 +24,10 @@
<modules>
<module>core</module>
<module>ui-nodes</module>
<module>ui-swing</module>
<module>ui-swing-basiccontrols</module>
<module>ui-swing-panels</module>
<module>ui-swing</module>
<module>ui-nodes</module>
<module>demo</module>
</modules>
......
......@@ -76,7 +76,7 @@ public class DefaultObjectEditor extends AbstractOhEditor<Object, JComponent> {
}
pagePanel.add((JComponent) editor.getPanel());
childrenEditors.add(editor);
} else if (EditorsProvider.hasEditorFor(child)) {
} else {
// adding provided editor
addEditorFor(child);
}
......
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>fr.cemagref.ohoui</groupId>
<artifactId>ohoui</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>ohoui-ui-swing-panels</artifactId>
<packaging>jar</packaging>
<name>${project.artifactId} ${project.version}</name>
<dependencies>
<dependency>
<groupId>fr.cemagref.ohoui</groupId>
<artifactId>ohoui-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>fr.cemagref.ohoui</groupId>
<artifactId>ohoui-ui-swing-basiccontrols</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
/*
* Copyright (C) 2010 Cemagref
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.cemagref.ohoui.ui.swing.onepanel;
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.EditorsProvider;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JComponent;
/**
* Default implementation of editor for an ohObjectComplex, it produces an editor by
* assembling editors for each field.
*
* @author Nicolas Dumoulin <nicolas.dumoulin@cemagref.fr>
*/
public class DefaultObjectEditor extends fr.cemagref.ohoui.ui.swing.basiccontrols.DefaultObjectEditor {
private List<ObjectComplexEditorPanel> complexEditors;
public DefaultObjectEditor(OhObjectComplex<?> object) {
super(object);
}
public void setContainer(OhPanel container) {
if (complexEditors != null) {
for (ObjectComplexEditorPanel editor : complexEditors) {
editor.setContainer(container);
}
}
}
@Override
protected void addEditorFor(OhObject object, int index) {
AbstractOhEditor<Object, JComponent> editor = EditorsProvider.createEditorFor(object);
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);
addPanelAt(editor.getPanel(), index);
}
}
}
/*
* Copyright (C) 2011 Cemagref
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.cemagref.ohoui.ui.swing.onepanel;
import fr.cemagref.ohoui.structure.OhObjectComplex;
import fr.cemagref.ohoui.ui.swing.basiccontrols.OhEditorPanel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
/**
*
* @author Nicolas Dumoulin <nicolas.dumoulin@cemagref.fr>
*/
public class ObjectComplexEditorPanel extends OhEditorPanel<Object> implements ActionListener {
private OhPanel container;
public ObjectComplexEditorPanel(OhObjectComplex<Object> object) {
super(object);
addLabel(object.getName(), object.getDescription());
JButton button = new JButton("Edit\u2026");
button.addActionListener(this);
addComponent(button, object.getDescription());
}
public void setContainer(OhPanel container) {
this.container = container;
}
@Override
public Object getValue() {
return container.getEditorFor(super.object);
}
@Override
public void actionPerformed(ActionEvent e) {
this.container.selectObject((OhObjectComplex) super.object);
}
}
/*
* Copyright (C) 2011 Cemagref
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.cemagref.ohoui.ui.swing.onepanel;
import fr.cemagref.ohoui.reflect.DefaultObjectIntrospector;
import fr.cemagref.ohoui.reflect.IntrospectionException;
import fr.cemagref.ohoui.reflect.OhOuiContext;
import fr.cemagref.ohoui.structure.OhObject;
import fr.cemagref.ohoui.structure.OhObjectCollection;
import fr.cemagref.ohoui.structure.OhObjectComplex;
import fr.cemagref.ohoui.ui.swing.basiccontrols.AbstractOhEditor;
import fr.cemagref.ohoui.ui.swing.basiccontrols.EditorsProvider;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
/**
* This class provides a panel for editing an object.
* Each field will generate a field in a vertical form. Complex fields like
* collections or non-standard type (numbers, string, …) will generate a button
* for opening a new panel and editing this sub-object.
* If needed, a menu can display the path in the data structure of the object
* that is currently edited, that allows the user to come back to higher level
* node in the data structure.
*
* @author Nicolas Dumoulin <nicolas.dumoulin@cemagref.fr>
*/
public class OhPanel extends JPanel {
private JPanel editorsPanel;
private JComponent pathPanel;
private Map<Object, AbstractOhEditor<Object, JComponent>> editorsMap;
private CardLayout editorsCardLayout;
private final static String EMPTY_EDITOR_CODE = "empty";
/**
* Load an object for editing.
* @param title The name of the object to edit used for displaying
* @param o the object to edit
* @throws IntrospectionException
*/
public void loadObject(String title, Object o) throws IntrospectionException {
this.editorsMap = new HashMap<Object, AbstractOhEditor<Object, JComponent>>();
this.editorsCardLayout = new CardLayout();
this.editorsPanel = new JPanel(editorsCardLayout);
editorsPanel.add(new JPanel(), EMPTY_EDITOR_CODE);
pathPanel = new JLabel();
this.setLayout(new BorderLayout());
this.add(pathPanel, BorderLayout.NORTH);
this.add(editorsPanel);
OhOuiContext ohOuiContext = new OhOuiContext();
OhObjectComplex ohObjectComplex = DefaultObjectIntrospector.introspect(title, o, ohOuiContext);
selectObject(ohObjectComplex);
}
private String getCode(OhObjectComplex selectedObject) {
return Integer.toString(selectedObject.hashCode());
}
/**
* Select an object for editing in the tree of the datastructure
* @param selectedObject
*/
public final void selectObject(OhObjectComplex selectedObject) {
// find the path of the edited object from the root
OhObjectComplex current = selectedObject;
StringBuilder buff = new StringBuilder();
while (current != null) {
buff.insert(0, current.getName()).insert(0, " > ");
current = current.getParent();
}
// update the path display
((JLabel) pathPanel).setText(buff.substring(3));
// display the editor
boolean firstAdd = !editorsMap.containsKey(selectedObject);
AbstractOhEditor<Object, JComponent> editor = getEditorFor(selectedObject);
if (editor != null) {
if (firstAdd) {
editorsPanel.add(editor.getPanel(), getCode(selectedObject));
}
editorsCardLayout.show(editorsPanel, getCode(selectedObject));
} else {
editorsCardLayout.show(editorsPanel, EMPTY_EDITOR_CODE);
}
}
public final AbstractOhEditor<Object, JComponent> getEditorFor(OhObject selectedObject) {
AbstractOhEditor<Object, JComponent> editor = editorsMap.get(selectedObject);
if (editor == null) {
// 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);
} else {
// TODO pay attention if object value is null ?
editor = EditorsProvider.createEditorFor(selectedObject);
}
editorsMap.put(selectedObject, editor);
}
return editor;
}
public void applyChanges() {
throw new UnsupportedOperationException("Not yet implemented");
}
}
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