Initial Commit
commit
cda2d8211b
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
|
||||||
|
<classpathentry kind="lib" path="contrib/javassist-3.15.0-GA.jar"/>
|
||||||
|
<classpathentry kind="lib" path="contrib/hibernate-jpa-2.0-api-1.0.1.Final.jar"/>
|
||||||
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
</classpath>
|
|
@ -0,0 +1,3 @@
|
||||||
|
|
||||||
|
bin/*
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>org.hwo</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
|
@ -0,0 +1,11 @@
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.source=1.6
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,118 @@
|
||||||
|
package org.hwo;
|
||||||
|
|
||||||
|
import java.util.prefs.BackingStoreException;
|
||||||
|
import java.util.prefs.Preferences;
|
||||||
|
|
||||||
|
|
||||||
|
public class DBProfile
|
||||||
|
{
|
||||||
|
private Integer profileno;
|
||||||
|
private String bezeichnung;
|
||||||
|
private String hostname;
|
||||||
|
private String database;
|
||||||
|
private Integer port;
|
||||||
|
private String username;
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
public DBProfile(Preferences pref,int profileno)
|
||||||
|
{
|
||||||
|
this.setProfileno(profileno);
|
||||||
|
load(pref);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getProfileno() {
|
||||||
|
return profileno;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load(Preferences pref)
|
||||||
|
{
|
||||||
|
Preferences prefs = pref.node("database").node(profileno.toString());
|
||||||
|
|
||||||
|
hostname = prefs.get("hostname", "localhost");
|
||||||
|
database = prefs.get("database", "hworganizer");
|
||||||
|
username = prefs.get("username", "");
|
||||||
|
password = prefs.get("password", "");
|
||||||
|
port = prefs.getInt("port", 5432);
|
||||||
|
bezeichnung = prefs.get("bezeichnung", "Profil " + profileno.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save(Preferences pref)
|
||||||
|
{
|
||||||
|
Preferences prefs = pref.node("database").node(profileno.toString());
|
||||||
|
|
||||||
|
prefs.put("hostname", hostname);
|
||||||
|
prefs.put("database", database);
|
||||||
|
prefs.put("username", username);
|
||||||
|
prefs.put("password", password);
|
||||||
|
prefs.putInt("port", port);
|
||||||
|
prefs.put("bezeichnung", bezeichnung);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
prefs.flush();
|
||||||
|
} catch (BackingStoreException bse)
|
||||||
|
{
|
||||||
|
System.err.println("Einstellungen konnten nicht gespeichert werden!");
|
||||||
|
System.err.println(bse.toString());
|
||||||
|
bse.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProfileno(int profileno) {
|
||||||
|
this.profileno = profileno;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHostname() {
|
||||||
|
return hostname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHostname(String hostname) {
|
||||||
|
this.hostname = hostname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDatabase() {
|
||||||
|
return database;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDatabase(String database) {
|
||||||
|
this.database = database;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsername(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getPort() {
|
||||||
|
return port;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPort(Integer port) {
|
||||||
|
this.port = port;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBezeichnung() {
|
||||||
|
return bezeichnung;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBezeichnung(String bezeichnung) {
|
||||||
|
this.bezeichnung = bezeichnung;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return getBezeichnung();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
package org.hwo.__mapper_v0_;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public abstract class AbstractObjectMapper {
|
||||||
|
|
||||||
|
private List<Class<?>> registeredClasses;
|
||||||
|
private boolean isPrepared;
|
||||||
|
|
||||||
|
public AbstractObjectMapper()
|
||||||
|
{
|
||||||
|
setRegisteredClasses(new LinkedList<Class<?>>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public AbstractObjectMapper registerClass(Class<?> clazz)
|
||||||
|
{
|
||||||
|
getRegisteredClasses().add(clazz);
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
abstract public void prepareMapper();
|
||||||
|
public boolean isPrepared()
|
||||||
|
{
|
||||||
|
return isPrepared;
|
||||||
|
};
|
||||||
|
protected void setPrepared()
|
||||||
|
{
|
||||||
|
isPrepared = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract public Object loadObject(ObjectReference objectReference);
|
||||||
|
public Object loadObject(Class<?> clazz,Object id)
|
||||||
|
{
|
||||||
|
return loadObject(ObjectReference.create(clazz, id));
|
||||||
|
}
|
||||||
|
abstract public boolean saveObject(Object o);
|
||||||
|
|
||||||
|
public List<Class<?>> getRegisteredClasses() {
|
||||||
|
return registeredClasses;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRegisteredClasses(List<Class<?>> registeredClasses) {
|
||||||
|
this.registeredClasses = registeredClasses;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,135 @@
|
||||||
|
package org.hwo.__mapper_v0_;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.ParameterizedType;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
|
||||||
|
public class ObjectDescriptor {
|
||||||
|
|
||||||
|
private AbstractObjectMapper mapper;
|
||||||
|
private Class<?> clazz;
|
||||||
|
private List<FieldDescriptor> fields;
|
||||||
|
private FieldDescriptor id;
|
||||||
|
|
||||||
|
public ObjectDescriptor(AbstractObjectMapper mapper,Class<?> clazz)
|
||||||
|
{
|
||||||
|
this.mapper = mapper;
|
||||||
|
this.clazz = clazz;
|
||||||
|
this.fields = new ArrayList<FieldDescriptor>();
|
||||||
|
|
||||||
|
setup();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setup()
|
||||||
|
{
|
||||||
|
for (Field f:clazz.getDeclaredFields())
|
||||||
|
{
|
||||||
|
String name = f.getName();
|
||||||
|
Column column = f.getAnnotation(Column.class);
|
||||||
|
if (column!=null)
|
||||||
|
{
|
||||||
|
if (column.name()!=null)
|
||||||
|
name = column.name();
|
||||||
|
}
|
||||||
|
FieldDescriptor fd = new FieldDescriptor(name, f);
|
||||||
|
fields.add(fd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resolve()
|
||||||
|
{
|
||||||
|
for (FieldDescriptor fd:fields)
|
||||||
|
fd.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public class FieldDescriptor {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private Field classField;
|
||||||
|
private boolean isSimpleType;
|
||||||
|
private boolean isListType;
|
||||||
|
|
||||||
|
private Class<?> fieldType;
|
||||||
|
|
||||||
|
public FieldDescriptor(String name,Field classField)
|
||||||
|
{
|
||||||
|
this.setName(name);
|
||||||
|
this.setClassField(classField);
|
||||||
|
|
||||||
|
if (
|
||||||
|
(classField.getType()==Integer.class) ||
|
||||||
|
(classField.getType()==int.class) ||
|
||||||
|
(classField.getType()==Long.class) ||
|
||||||
|
(classField.getType()==long.class) ||
|
||||||
|
(classField.getType()==float.class) ||
|
||||||
|
(classField.getType()==Float.class) ||
|
||||||
|
(classField.getType()==Double.class) ||
|
||||||
|
(classField.getType()==double.class) ||
|
||||||
|
(classField.getType()==String.class) ||
|
||||||
|
(classField.getType()==char.class) ||
|
||||||
|
(classField.getType()==Boolean.class) ||
|
||||||
|
(classField.getType()==boolean.class) ||
|
||||||
|
false
|
||||||
|
)
|
||||||
|
|
||||||
|
{
|
||||||
|
isSimpleType = true;
|
||||||
|
fieldType = classField.getType();
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
(classField.getType()==List.class) ||
|
||||||
|
(classField.getType()==Set.class)
|
||||||
|
|
||||||
|
)
|
||||||
|
{
|
||||||
|
isListType = true;
|
||||||
|
fieldType = (Class)((ParameterizedType)classField.getGenericType()).getActualTypeArguments()[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Field getClassField() {
|
||||||
|
return classField;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClassField(Field classField) {
|
||||||
|
this.classField = classField;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSimpleType() {
|
||||||
|
return isSimpleType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSimpleType(boolean isSimpleType) {
|
||||||
|
this.isSimpleType = isSimpleType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resolve()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isListType() {
|
||||||
|
return isListType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setListType(boolean isListType) {
|
||||||
|
this.isListType = isListType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
package org.hwo.__mapper_v0_;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Hashtable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ObjectReference {
|
||||||
|
|
||||||
|
private static Hashtable<Class<?>, Hashtable<Object, ObjectReference>> referenceList = new Hashtable<Class<?>, Hashtable<Object,ObjectReference>>();
|
||||||
|
|
||||||
|
private static Hashtable<Object, ObjectReference> getReferenceList(Class<?> clazz)
|
||||||
|
{
|
||||||
|
if (!referenceList.containsKey(clazz))
|
||||||
|
referenceList.put(clazz, new Hashtable<Object, ObjectReference>());
|
||||||
|
return referenceList.get(clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ObjectReference create(Class<?> clazz,Object id)
|
||||||
|
{
|
||||||
|
Hashtable<Object, ObjectReference> classReferenceList = getReferenceList(clazz);
|
||||||
|
if (classReferenceList.containsKey(id))
|
||||||
|
return classReferenceList.get(id);
|
||||||
|
|
||||||
|
ObjectReference ref = new ObjectReference(clazz, id);
|
||||||
|
classReferenceList.put(id, ref);
|
||||||
|
return ref;
|
||||||
|
};
|
||||||
|
|
||||||
|
private Class<?> clazz;
|
||||||
|
private Object id;
|
||||||
|
|
||||||
|
private ObjectReference(Class<?> clazz,Object id)
|
||||||
|
{
|
||||||
|
this.setClazz(clazz);
|
||||||
|
this.setId(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Class<?> getClazz() {
|
||||||
|
return clazz;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClazz(Class<?> clazz) {
|
||||||
|
this.clazz = clazz;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Object id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
package org.hwo.__mapper_v0_;
|
||||||
|
|
||||||
|
import java.util.Hashtable;
|
||||||
|
|
||||||
|
public class SimpleObjectMapper extends AbstractObjectMapper {
|
||||||
|
|
||||||
|
Hashtable<Class<?>, ObjectDescriptor> objectDescriptors;
|
||||||
|
|
||||||
|
public SimpleObjectMapper()
|
||||||
|
{
|
||||||
|
objectDescriptors = new Hashtable<Class<?>, ObjectDescriptor>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectDescriptor getObjectDescriptor(Class<?> clazz)
|
||||||
|
{
|
||||||
|
return objectDescriptors.get(clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AbstractObjectMapper registerClass(Class<?> clazz) {
|
||||||
|
objectDescriptors.put(clazz, new ObjectDescriptor(this, clazz));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void prepareMapper() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object loadObject(ObjectReference objectReference) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean saveObject(Object o) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,223 @@
|
||||||
|
package org.hwo.csv;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
import javassist.bytecode.EnclosingMethodAttribute;
|
||||||
|
|
||||||
|
public class CSV {
|
||||||
|
|
||||||
|
List<String[]> records;
|
||||||
|
|
||||||
|
private char separator;
|
||||||
|
private char enclosedBy;
|
||||||
|
|
||||||
|
boolean isEnclosed;
|
||||||
|
List<String> parserRecord;
|
||||||
|
List<Character> parserField;
|
||||||
|
char lastChar;
|
||||||
|
|
||||||
|
public CSV()
|
||||||
|
{
|
||||||
|
this.records = new LinkedList<String[]>();
|
||||||
|
this.setSeparator(';');
|
||||||
|
this.setEnclosedBy('\"');
|
||||||
|
|
||||||
|
this.parserRecord = new ArrayList<String>();
|
||||||
|
this.parserField = new ArrayList<Character>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void nextRecord()
|
||||||
|
{
|
||||||
|
nextField();
|
||||||
|
|
||||||
|
this.records.add(parserRecord.toArray(new String[]{}));
|
||||||
|
parserRecord.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void nextField()
|
||||||
|
{
|
||||||
|
char fieldChars[] = new char[ parserField.size() ];
|
||||||
|
|
||||||
|
for (int i=0;i<parserField.size(); i++)
|
||||||
|
fieldChars[i] = parserField.get(i);
|
||||||
|
|
||||||
|
parserRecord.add(String.valueOf(fieldChars));
|
||||||
|
parserField.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void feeder(char ch)
|
||||||
|
{
|
||||||
|
if (ch == getEnclosedBy())
|
||||||
|
{
|
||||||
|
isEnclosed = !isEnclosed;
|
||||||
|
|
||||||
|
if (isEnclosed && lastChar == getEnclosedBy())
|
||||||
|
parserField.add(getEnclosedBy());
|
||||||
|
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
if (isEnclosed)
|
||||||
|
parserField.add(ch);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (ch == '\r')
|
||||||
|
{
|
||||||
|
// Ignore \r
|
||||||
|
} else if (ch == '\n')
|
||||||
|
nextRecord();
|
||||||
|
else if (ch == getSeparator())
|
||||||
|
nextField();
|
||||||
|
else
|
||||||
|
parserField.add(ch);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
lastChar = ch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void readFromStream(InputStream is) throws IOException
|
||||||
|
{
|
||||||
|
this.readFromStream(new InputStreamReader(is,"ISO-8859-1"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void readFromStream(InputStreamReader isr) throws IOException
|
||||||
|
{
|
||||||
|
BufferedReader br = new BufferedReader(isr);
|
||||||
|
|
||||||
|
isEnclosed = false;
|
||||||
|
records.clear();
|
||||||
|
parserField.clear();
|
||||||
|
parserRecord.clear();
|
||||||
|
|
||||||
|
while (br.ready())
|
||||||
|
feeder((char)br.read());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void saveToFile(String filename)
|
||||||
|
{
|
||||||
|
saveToFile(new File(filename));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveToFile(File output)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
FileOutputStream fos = new FileOutputStream(output,false);
|
||||||
|
saveToStream(fos);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveToStream(OutputStream output)
|
||||||
|
{
|
||||||
|
OutputStreamWriter osw;
|
||||||
|
try {
|
||||||
|
osw = new OutputStreamWriter(output,"UTF8");
|
||||||
|
saveToStream(osw);
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveToStream(OutputStreamWriter output)
|
||||||
|
{
|
||||||
|
BufferedWriter writer = new BufferedWriter(output);
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
for (String[] record:this.records)
|
||||||
|
{
|
||||||
|
for (int i=0;i<record.length;i++)
|
||||||
|
{
|
||||||
|
if (i>0)
|
||||||
|
writer.write(separator);
|
||||||
|
|
||||||
|
if (record[i] != null)
|
||||||
|
{
|
||||||
|
if (String.class.isInstance(record[i]))
|
||||||
|
writer.write(enclosedBy);
|
||||||
|
|
||||||
|
writer.write(record[i]);
|
||||||
|
|
||||||
|
if (String.class.isInstance(record[i]))
|
||||||
|
writer.write(enclosedBy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writer.write("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue(int row,int column)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return this.records.get(row)[column];
|
||||||
|
} catch (ArrayIndexOutOfBoundsException ex)
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String[]> getCells()
|
||||||
|
{
|
||||||
|
return this.records;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Object[]> getCellsAsObjects()
|
||||||
|
{
|
||||||
|
List<Object[]> ol = new ArrayList<Object[]>();
|
||||||
|
|
||||||
|
for (String[] record:records)
|
||||||
|
{
|
||||||
|
Object[] ro = new Object[record.length];
|
||||||
|
for (int i=0;i<ro.length;i++)
|
||||||
|
ro[i] = record[i];
|
||||||
|
ol.add(ro);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ol;
|
||||||
|
}
|
||||||
|
|
||||||
|
public char getSeparator() {
|
||||||
|
return separator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeparator(char separator) {
|
||||||
|
this.separator = separator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public char getEnclosedBy() {
|
||||||
|
return enclosedBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnclosedBy(char enclosedBy) {
|
||||||
|
this.enclosedBy = enclosedBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package org.hwo.interactiveobjects;
|
||||||
|
|
||||||
|
public interface IInteractiveObjectEditor {
|
||||||
|
|
||||||
|
public void setInteractiveObject(Object o);
|
||||||
|
public Object getInteractiveObject();
|
||||||
|
|
||||||
|
public void setVisible(boolean visible);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package org.hwo.interactiveobjects;
|
||||||
|
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface InteractiveObject {
|
||||||
|
|
||||||
|
public boolean keywordSearch() default false;
|
||||||
|
|
||||||
|
public Class<? extends IInteractiveObjectEditor> editor();
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
package org.hwo.interactiveobjects;
|
||||||
|
|
||||||
|
import java.util.Hashtable;
|
||||||
|
|
||||||
|
public class InteractiveObjectHelper {
|
||||||
|
|
||||||
|
|
||||||
|
private static Hashtable<Object, IInteractiveObjectEditor> p_editors = new Hashtable<Object, IInteractiveObjectEditor>();
|
||||||
|
|
||||||
|
private static InteractiveObject getInteractiveObject(Class<?> clazz)
|
||||||
|
{
|
||||||
|
InteractiveObject io = clazz.getAnnotation(InteractiveObject.class);
|
||||||
|
if (io != null)
|
||||||
|
return io;
|
||||||
|
if (clazz.getSuperclass() != null)
|
||||||
|
return getInteractiveObject(clazz.getSuperclass());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static InteractiveObject getInteractiveObject(Object item)
|
||||||
|
{
|
||||||
|
Class<?> clazz = item.getClass();
|
||||||
|
return getInteractiveObject(clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isInteractiveObject(Class<?> clazz)
|
||||||
|
{
|
||||||
|
return (getInteractiveObject(clazz)!=null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IInteractiveObjectEditor getEditor(Object item)
|
||||||
|
{
|
||||||
|
InteractiveObject io = getInteractiveObject(item);
|
||||||
|
|
||||||
|
if (io != null)
|
||||||
|
{
|
||||||
|
if (!p_editors.containsKey(item))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
IInteractiveObjectEditor editor = io.editor().newInstance();
|
||||||
|
p_editors.put(item, editor);
|
||||||
|
} catch (Exception ex)
|
||||||
|
{
|
||||||
|
System.err.println(ex.toString());
|
||||||
|
ex.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return p_editors.get(item);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showEditor(Object o)
|
||||||
|
{
|
||||||
|
IInteractiveObjectEditor editor = getEditor(o);
|
||||||
|
editor.setInteractiveObject(o);
|
||||||
|
editor.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,132 @@
|
||||||
|
package org.hwo.models;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
public class Column {
|
||||||
|
private int MODE_FIELD = 1;
|
||||||
|
private int MODE_GETSET = 2;
|
||||||
|
|
||||||
|
private int mode;
|
||||||
|
private String fieldName;
|
||||||
|
private boolean readonly;
|
||||||
|
private Class p_class;
|
||||||
|
private Field field;
|
||||||
|
private Method getter;
|
||||||
|
private Method setter;
|
||||||
|
|
||||||
|
public Column(Class classInfo,String fieldName,boolean readonly) throws NoSuchFieldException
|
||||||
|
{
|
||||||
|
this.fieldName = fieldName;
|
||||||
|
this.readonly = readonly;
|
||||||
|
this.p_class = classInfo;
|
||||||
|
this.getter = null;
|
||||||
|
this.setter = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
mode = MODE_FIELD;
|
||||||
|
this.field = this.p_class.getDeclaredField(fieldName);
|
||||||
|
this.field.setAccessible(true);
|
||||||
|
} catch (NoSuchFieldException nsfex)
|
||||||
|
{
|
||||||
|
mode = MODE_GETSET;
|
||||||
|
// Kein deklariertes Feld, also suchen wir eine get... und set... Methode...
|
||||||
|
Method[] methods = this.p_class.getDeclaredMethods();
|
||||||
|
for (Method method : methods) {
|
||||||
|
// passender getter?
|
||||||
|
if (("get"+fieldName.toLowerCase()).equals(method.getName().toLowerCase()))
|
||||||
|
getter = method;
|
||||||
|
// passender setter?
|
||||||
|
if (("set"+fieldName.toLowerCase()).equals(method.getName().toLowerCase()))
|
||||||
|
setter = method;
|
||||||
|
}
|
||||||
|
if (getter == null)
|
||||||
|
throw nsfex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getFieldName()
|
||||||
|
{
|
||||||
|
return this.fieldName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getReadOnly()
|
||||||
|
{
|
||||||
|
if ((mode == MODE_GETSET) && (setter == null))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return this.readonly;
|
||||||
|
}
|
||||||
|
public void setReadOnly(boolean readOnly)
|
||||||
|
{
|
||||||
|
this.readonly = readOnly;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Class getColumnClass()
|
||||||
|
{
|
||||||
|
if (mode == MODE_GETSET)
|
||||||
|
return this.getter.getReturnType();
|
||||||
|
|
||||||
|
return this.field.getType();
|
||||||
|
}
|
||||||
|
|
||||||
|
Object getValue(Object o)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (mode == MODE_GETSET)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Object ro = this.getter.invoke(o, null);
|
||||||
|
return ro;
|
||||||
|
} catch (InvocationTargetException itex)
|
||||||
|
{
|
||||||
|
System.err.println(itex.toString());
|
||||||
|
itex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.field.get(o);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
System.err.println("IllegalArgument! " + e.toString());
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
System.err.println("IllegalAccess! " + e.toString());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
void setValue(Object o,Object value)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (mode == MODE_GETSET)
|
||||||
|
{
|
||||||
|
if (this.setter != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.setter.invoke(o,new Object[]{ value });
|
||||||
|
} catch (InvocationTargetException itex)
|
||||||
|
{
|
||||||
|
System.err.println(itex.toString());
|
||||||
|
itex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.field.set(o,value);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
System.err.println("IllegalArgument! " + e.toString());
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
System.err.println("IllegalAccess! " + e.toString());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
package org.hwo.models;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import javax.swing.AbstractListModel;
|
||||||
|
|
||||||
|
public class FlexibleObjectListModel<T> extends AbstractListModel {
|
||||||
|
|
||||||
|
private List<T> items;
|
||||||
|
|
||||||
|
public FlexibleObjectListModel() {
|
||||||
|
this.items = new ArrayList<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getElementAt(int index) {
|
||||||
|
return this.items.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSize() {
|
||||||
|
return this.items.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear()
|
||||||
|
{
|
||||||
|
this.items.clear();
|
||||||
|
fireContentsChanged(this, 0, getSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<T> getItems() {
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setItems(List<T> items) {
|
||||||
|
this.items = items;
|
||||||
|
fireContentsChanged(this, 0, getSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addItem(T o)
|
||||||
|
{
|
||||||
|
this.items.add(o);
|
||||||
|
fireContentsChanged(this, 0, getSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeItem(T o)
|
||||||
|
{
|
||||||
|
int index = this.items.indexOf(o);
|
||||||
|
this.items.remove(o);
|
||||||
|
fireContentsChanged(this, 0, getSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,115 @@
|
||||||
|
package org.hwo.models;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import javax.swing.table.AbstractTableModel;
|
||||||
|
|
||||||
|
public class FlexibleObjectTableModel<T> extends AbstractTableModel{
|
||||||
|
|
||||||
|
List<Column> columns;
|
||||||
|
List<T> rows;
|
||||||
|
|
||||||
|
Class p_classinfo;
|
||||||
|
|
||||||
|
public FlexibleObjectTableModel(Class tClass)
|
||||||
|
{
|
||||||
|
this.columns = new ArrayList<Column>();
|
||||||
|
this.rows = new ArrayList<T>();
|
||||||
|
|
||||||
|
this.p_classinfo = tClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void addColumn(String fieldName)
|
||||||
|
{
|
||||||
|
this.addColumn(fieldName,true);
|
||||||
|
}
|
||||||
|
public void addColumn(String fieldName,boolean readOnly)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.columns.add(new Column(this.p_classinfo,fieldName,readOnly));
|
||||||
|
fireTableStructureChanged();
|
||||||
|
} catch (NoSuchFieldException nsfex)
|
||||||
|
{
|
||||||
|
System.err.println(nsfex.toString());
|
||||||
|
nsfex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<T> getRows()
|
||||||
|
{
|
||||||
|
return this.rows;
|
||||||
|
}
|
||||||
|
public void setRows(List<T> rows)
|
||||||
|
{
|
||||||
|
this.rows = rows;
|
||||||
|
this.fireTableDataChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int indexOf(Object o)
|
||||||
|
{
|
||||||
|
return this.rows.indexOf(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addRow(T o)
|
||||||
|
{
|
||||||
|
this.rows.add(o);
|
||||||
|
this.fireTableDataChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeRow(T o)
|
||||||
|
{
|
||||||
|
this.rows.remove(o);
|
||||||
|
this.fireTableDataChanged();
|
||||||
|
}
|
||||||
|
public void removeRow(int row)
|
||||||
|
{
|
||||||
|
this.rows.remove(row);
|
||||||
|
this.fireTableDataChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getColumnCount() {
|
||||||
|
return this.columns.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getRowCount() {
|
||||||
|
return this.rows.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getValueAt(int arg0, int arg1) {
|
||||||
|
return this.columns.get(arg1).getValue(this.rows.get(arg0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getColumnName(int columnIndex)
|
||||||
|
{
|
||||||
|
return this.columns.get(columnIndex).getFieldName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValueAt(Object aValue,
|
||||||
|
int rowIndex,
|
||||||
|
int columnIndex)
|
||||||
|
{
|
||||||
|
this.columns.get(columnIndex).setValue(this.rows.get(rowIndex), aValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCellEditable(int rowIndex,int columnIndex)
|
||||||
|
{
|
||||||
|
return !this.columns.get(columnIndex).getReadOnly();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class getColumnClass(int columnIndex)
|
||||||
|
{
|
||||||
|
return this.columns.get(columnIndex).getColumnClass();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
package org.hwo.models;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.swing.table.AbstractTableModel;
|
||||||
|
|
||||||
|
public class ListTableModel extends AbstractTableModel {
|
||||||
|
|
||||||
|
private List<Object[]> rows;
|
||||||
|
|
||||||
|
public ListTableModel()
|
||||||
|
{
|
||||||
|
rows = new ArrayList<Object[]>();
|
||||||
|
rows.add(new Object[]{"Eins","Zwei","Drei"});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Integer calcColumnCount()
|
||||||
|
{
|
||||||
|
Integer max = 0;
|
||||||
|
|
||||||
|
for (Object[] record:rows)
|
||||||
|
if (record.length > max)
|
||||||
|
max = record.length;
|
||||||
|
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getColumnCount() {
|
||||||
|
return calcColumnCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getRowCount() {
|
||||||
|
return rows.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getValueAt(int rowIndex, int columnIndex) {
|
||||||
|
return rows.get(rowIndex)[columnIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<Object[]> getRows() {
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setRows(List<Object[]> rows) {
|
||||||
|
this.rows = rows;
|
||||||
|
fireTableStructureChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package org.hwo.models.TableMapper;
|
||||||
|
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface TableColumn {
|
||||||
|
|
||||||
|
String label() default "";
|
||||||
|
boolean readonly() default false;
|
||||||
|
boolean visible() default true;
|
||||||
|
int width() default 100;
|
||||||
|
String after() default "";
|
||||||
|
boolean firstColumn() default false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,609 @@
|
||||||
|
package org.hwo.models.TableMapper;
|
||||||
|
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.event.MouseListener;
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Hashtable;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.swing.JTable;
|
||||||
|
import javax.swing.table.AbstractTableModel;
|
||||||
|
|
||||||
|
import org.hwo.csv.CSV;
|
||||||
|
import org.hwo.interactiveobjects.InteractiveObjectHelper;
|
||||||
|
|
||||||
|
public class TableMapper extends AbstractTableModel
|
||||||
|
{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -6556060772230310664L;
|
||||||
|
|
||||||
|
public class ColumnInfo
|
||||||
|
{
|
||||||
|
private TableColumn p_annotation;
|
||||||
|
|
||||||
|
private Field p_field;
|
||||||
|
private Method p_method;
|
||||||
|
private String p_label;
|
||||||
|
private boolean p_readonly;
|
||||||
|
private Class<?> p_columnclass;
|
||||||
|
private int width;
|
||||||
|
private TableColumn tableColumn;
|
||||||
|
|
||||||
|
private ColumnInfo nextColumn;
|
||||||
|
|
||||||
|
protected ColumnInfo(TableColumn tc,Field field)
|
||||||
|
{
|
||||||
|
tableColumn = tc;
|
||||||
|
p_annotation = field.getAnnotation(TableColumn.class);
|
||||||
|
|
||||||
|
p_method = null;
|
||||||
|
p_field = field;
|
||||||
|
p_columnclass = field.getType();
|
||||||
|
|
||||||
|
initialize();
|
||||||
|
|
||||||
|
if (p_label.equals(""))
|
||||||
|
p_label = field.getName();
|
||||||
|
|
||||||
|
field.setAccessible(true);
|
||||||
|
}
|
||||||
|
protected ColumnInfo(TableColumn tc,Method method)
|
||||||
|
{
|
||||||
|
tableColumn = tc;
|
||||||
|
p_annotation = method.getAnnotation(TableColumn.class);
|
||||||
|
|
||||||
|
p_method = method;
|
||||||
|
p_field = null;
|
||||||
|
p_columnclass = method.getReturnType();
|
||||||
|
|
||||||
|
initialize();
|
||||||
|
|
||||||
|
if (p_label.equals(""))
|
||||||
|
p_label = method.getName();
|
||||||
|
|
||||||
|
method.setAccessible(true);
|
||||||
|
|
||||||
|
p_readonly = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initialize()
|
||||||
|
{
|
||||||
|
p_label = p_annotation.label();
|
||||||
|
p_readonly = p_annotation.readonly();
|
||||||
|
setWidth(p_annotation.width());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void appendAtEnd(ColumnInfo column)
|
||||||
|
{
|
||||||
|
if (nextColumn == null)
|
||||||
|
nextColumn = column;
|
||||||
|
else
|
||||||
|
nextColumn.appendAtEnd(column);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ColumnInfo> toList()
|
||||||
|
{
|
||||||
|
List<ColumnInfo> list = new LinkedList<TableMapper.ColumnInfo>();
|
||||||
|
appendToList(list);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void appendToList(List<ColumnInfo> list)
|
||||||
|
{
|
||||||
|
list.add(this);
|
||||||
|
if (nextColumn != null)
|
||||||
|
nextColumn.appendToList(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeColumn(ColumnInfo ci)
|
||||||
|
{
|
||||||
|
if (nextColumn == ci)
|
||||||
|
{
|
||||||
|
nextColumn = ci.nextColumn;
|
||||||
|
ci.nextColumn = null;
|
||||||
|
} else if (nextColumn != null)
|
||||||
|
nextColumn.removeColumn(ci);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ColumnInfo findColumnByName(String name)
|
||||||
|
{
|
||||||
|
if (this.p_label.equals(name))
|
||||||
|
return this;
|
||||||
|
if (nextColumn!=null)
|
||||||
|
return nextColumn.findColumnByName(name);
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void append(ColumnInfo ci)
|
||||||
|
{
|
||||||
|
ci.nextColumn = nextColumn;
|
||||||
|
nextColumn = ci;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getLabel()
|
||||||
|
{
|
||||||
|
return this.p_label;
|
||||||
|
}
|
||||||
|
public void setLabel(String label)
|
||||||
|
{
|
||||||
|
this.p_label = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getReadOnly()
|
||||||
|
{
|
||||||
|
return this.p_readonly;
|
||||||
|
}
|
||||||
|
public void setReadOnly(boolean readOnly)
|
||||||
|
{
|
||||||
|
this.p_readonly = readOnly;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColumnClass(Class<?> cl)
|
||||||
|
{
|
||||||
|
this.p_columnclass = cl;
|
||||||
|
}
|
||||||
|
public Class<?> getColumnClass()
|
||||||
|
{
|
||||||
|
return this.p_columnclass;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getValue(Object instance) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException
|
||||||
|
{
|
||||||
|
if (p_field != null)
|
||||||
|
return p_field.get(instance);
|
||||||
|
if (p_method != null)
|
||||||
|
return p_method.invoke(instance, null);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(Object instance,Object value) throws IllegalAccessException
|
||||||
|
{
|
||||||
|
if (p_field != null)
|
||||||
|
p_field.set(instance, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWidth() {
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWidth(int width) {
|
||||||
|
this.width = width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ColumnInfo getNextColumn() {
|
||||||
|
return nextColumn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNextColumn(ColumnInfo nextColumn) {
|
||||||
|
this.nextColumn = nextColumn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TableColumn getTableColumn() {
|
||||||
|
return tableColumn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTableColumn(TableColumn tableColumn) {
|
||||||
|
this.tableColumn = tableColumn;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Class<?> p_class;
|
||||||
|
|
||||||
|
private ColumnInfo firstColumn;
|
||||||
|
|
||||||
|
private List<Object> p_rows;
|
||||||
|
private List<ColumnInfo> p_columns;
|
||||||
|
private boolean p_readonly; // Table readonly...
|
||||||
|
|
||||||
|
private TableMapperColumnModel
|
||||||
|
columnModel;
|
||||||
|
|
||||||
|
private JTable jTable;
|
||||||
|
|
||||||
|
private TableMapperObject
|
||||||
|
tableMapperObject;
|
||||||
|
private Field editorObjectField;
|
||||||
|
private Class<?> editorObjectClass;
|
||||||
|
|
||||||
|
private MouseAdapter mouseAdapter;
|
||||||
|
|
||||||
|
private boolean editorEnabled;
|
||||||
|
|
||||||
|
|
||||||
|
public TableMapper(Class<?> clazz,JTable table)
|
||||||
|
{
|
||||||
|
this.p_class = clazz;
|
||||||
|
this.jTable = table;
|
||||||
|
|
||||||
|
this.firstColumn = null;
|
||||||
|
|
||||||
|
this.p_rows = new LinkedList<Object>();
|
||||||
|
this.p_columns = new ArrayList<TableMapper.ColumnInfo>();
|
||||||
|
this.p_readonly = false;
|
||||||
|
|
||||||
|
initializeMapper();
|
||||||
|
initializeColumnInfo();
|
||||||
|
|
||||||
|
table.setModel(this);
|
||||||
|
table.setColumnModel(new TableMapperColumnModel(this));
|
||||||
|
|
||||||
|
table.setAutoCreateRowSorter(true);
|
||||||
|
|
||||||
|
mouseAdapter = new MouseAdapter() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
switch (e.getButton())
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
if (e.getClickCount()==2)
|
||||||
|
{
|
||||||
|
openEditor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
if (InteractiveObjectHelper.isInteractiveObject(editorObjectClass))
|
||||||
|
setEditorEnabled(true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initializeMapper()
|
||||||
|
{
|
||||||
|
tableMapperObject = p_class.getAnnotation(TableMapperObject.class);
|
||||||
|
if (tableMapperObject != null)
|
||||||
|
{
|
||||||
|
if (tableMapperObject.editorField() != null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
editorObjectField = p_class.getDeclaredField(tableMapperObject.editorField());
|
||||||
|
editorObjectField.setAccessible(true);
|
||||||
|
|
||||||
|
editorObjectClass = editorObjectField.getType();
|
||||||
|
|
||||||
|
} catch (SecurityException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
editorObjectClass = p_class;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object getEditorObject()
|
||||||
|
{
|
||||||
|
if (jTable.getSelectedRow()!=-1)
|
||||||
|
{
|
||||||
|
int row = jTable.convertRowIndexToModel(jTable.getSelectedRow());
|
||||||
|
Object rowObject = p_rows.get(row);
|
||||||
|
if (editorObjectField == null)
|
||||||
|
return rowObject;
|
||||||
|
|
||||||
|
try {
|
||||||
|
Object editorObject = editorObjectField.get(rowObject);
|
||||||
|
return editorObject;
|
||||||
|
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void openEditor()
|
||||||
|
{
|
||||||
|
Object editorObject = getEditorObject();
|
||||||
|
if (editorObject!=null)
|
||||||
|
InteractiveObjectHelper.showEditor(editorObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ColumnInfo> getColumnInfo()
|
||||||
|
{
|
||||||
|
return p_columns;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRows(List rows)
|
||||||
|
{
|
||||||
|
this.p_rows = rows;
|
||||||
|
fireTableDataChanged();
|
||||||
|
}
|
||||||
|
public List getRows()
|
||||||
|
{
|
||||||
|
return this.p_rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> List<T> getRows(Class<T> clazz)
|
||||||
|
{
|
||||||
|
return (List<T>) p_rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear()
|
||||||
|
{
|
||||||
|
this.p_rows.clear();
|
||||||
|
fireTableDataChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEditorEnabled()
|
||||||
|
{
|
||||||
|
return editorEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEditorEnabled(boolean enabled)
|
||||||
|
{
|
||||||
|
if (enabled)
|
||||||
|
jTable.addMouseListener(mouseAdapter);
|
||||||
|
else
|
||||||
|
jTable.removeMouseListener(mouseAdapter);
|
||||||
|
|
||||||
|
editorEnabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addColumnInfo(ColumnInfo ci)
|
||||||
|
{
|
||||||
|
if (ci.getTableColumn().firstColumn())
|
||||||
|
p_columns.add(0,ci);
|
||||||
|
else
|
||||||
|
p_columns.add(ci);
|
||||||
|
/*
|
||||||
|
if (firstColumn == null)
|
||||||
|
firstColumn = ci;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (ci.getTableColumn().firstColumn())
|
||||||
|
{
|
||||||
|
ci.setNextColumn(firstColumn);
|
||||||
|
firstColumn = ci;
|
||||||
|
} else
|
||||||
|
firstColumn.appendAtEnd(ci);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addFieldsOfClass(Class<?> clazz)
|
||||||
|
{
|
||||||
|
if (clazz.getSuperclass() != null)
|
||||||
|
addFieldsOfClass(clazz.getSuperclass());
|
||||||
|
|
||||||
|
for (Field field: clazz.getDeclaredFields())
|
||||||
|
{
|
||||||
|
if (field.getAnnotation(TableColumn.class)!=null)
|
||||||
|
{
|
||||||
|
ColumnInfo ci = new ColumnInfo(field.getAnnotation(TableColumn.class),field);
|
||||||
|
addColumnInfo(ci);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Method method: clazz.getDeclaredMethods())
|
||||||
|
{
|
||||||
|
if (method.getAnnotation(TableColumn.class)!=null)
|
||||||
|
{
|
||||||
|
ColumnInfo ci = new ColumnInfo(method.getAnnotation(TableColumn.class),method);
|
||||||
|
addColumnInfo(ci);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private int findColumnIndexByName(String name)
|
||||||
|
{
|
||||||
|
for (int i=0;i<p_columns.size();i++)
|
||||||
|
{
|
||||||
|
if (p_columns.get(i).p_label.equals(name))
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void reorderColumns()
|
||||||
|
{
|
||||||
|
List<ColumnInfo> lc = new ArrayList<TableMapper.ColumnInfo>(p_columns);
|
||||||
|
|
||||||
|
for (ColumnInfo ci:lc)
|
||||||
|
{
|
||||||
|
if (!ci.getTableColumn().after().equals(""))
|
||||||
|
{
|
||||||
|
int indColumn = p_columns.indexOf(ci);
|
||||||
|
int indBefore = findColumnIndexByName(ci.getTableColumn().after());
|
||||||
|
if (indBefore != -1)
|
||||||
|
{
|
||||||
|
if (indBefore < indColumn)
|
||||||
|
{
|
||||||
|
List<ColumnInfo> subset = new ArrayList<TableMapper.ColumnInfo>(p_columns.subList(indColumn, p_columns.size()));
|
||||||
|
p_columns.removeAll(subset);
|
||||||
|
p_columns.addAll(indBefore+1, subset);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
List<ColumnInfo> subset = new ArrayList<TableMapper.ColumnInfo>(p_columns.subList(indColumn, indBefore));
|
||||||
|
p_columns.removeAll(subset);
|
||||||
|
p_columns.addAll(indColumn+1, subset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initializeColumnInfo()
|
||||||
|
{
|
||||||
|
addFieldsOfClass(p_class);
|
||||||
|
reorderColumns();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReadOnly(boolean readOnly)
|
||||||
|
{
|
||||||
|
this.p_readonly = readOnly;
|
||||||
|
}
|
||||||
|
public boolean getReadOnly()
|
||||||
|
{
|
||||||
|
return this.p_readonly;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addRow(Object row)
|
||||||
|
{
|
||||||
|
this.p_rows.add(row);
|
||||||
|
//fireTableRowsInserted(getRowCount()-1, getRowCount()-1);
|
||||||
|
fireTableDataChanged();
|
||||||
|
}
|
||||||
|
public void removeRow(Object row)
|
||||||
|
{
|
||||||
|
int index = this.p_rows.indexOf(row);
|
||||||
|
if (index != -1)
|
||||||
|
{
|
||||||
|
this.p_rows.remove(index);
|
||||||
|
fireTableRowsDeleted(index, index);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getRow(int index)
|
||||||
|
{
|
||||||
|
return this.p_rows.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T getRow(int index,Class<T> clazz)
|
||||||
|
{
|
||||||
|
return (T)this.p_rows.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object appendNewInstance()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Object instance = this.p_class.newInstance();
|
||||||
|
if (instance != null)
|
||||||
|
addRow(instance);
|
||||||
|
return instance;
|
||||||
|
} catch (Exception ex)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getColumnCount() {
|
||||||
|
return this.p_columns.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getRowCount() {
|
||||||
|
return this.p_rows.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getValueAt(int rowIndex, int columnIndex) {
|
||||||
|
if ( (rowIndex < this.p_rows.size()) && (columnIndex < this.p_columns.size()))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return this.p_columns.get(columnIndex).getValue(this.p_rows.get(rowIndex));
|
||||||
|
} catch (Exception ex)
|
||||||
|
{
|
||||||
|
System.err.println("Exception: " + ex);
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValueAt(Object aValue,
|
||||||
|
int rowIndex,
|
||||||
|
int columnIndex)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.p_columns.get(columnIndex).setValue(this.p_rows.get(rowIndex), aValue);
|
||||||
|
} catch (IllegalAccessException ex)
|
||||||
|
{
|
||||||
|
System.err.println("IllegalAccessException: " + ex);
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCellEditable(int rowIndex,int columnIndex)
|
||||||
|
{
|
||||||
|
if (this.p_readonly)
|
||||||
|
return false;
|
||||||
|
return !this.p_columns.get(columnIndex).getReadOnly();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<?> getColumnClass(int columnIndex)
|
||||||
|
{
|
||||||
|
Class<?> c = this.p_columns.get(columnIndex).getColumnClass();
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getColumnName(int columnIndex)
|
||||||
|
{
|
||||||
|
return this.p_columns.get(columnIndex).getLabel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getSelectedRow()
|
||||||
|
{
|
||||||
|
if (jTable.getSelectedRow()!=-1)
|
||||||
|
{
|
||||||
|
return this.p_rows.get(jTable.convertRowIndexToModel(jTable.getSelectedRow()));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean exportToFile(File exportFile)
|
||||||
|
{
|
||||||
|
CSV csv = new CSV();
|
||||||
|
|
||||||
|
List<String[]> cells = csv.getCells();
|
||||||
|
|
||||||
|
String[] header = new String[ getColumnCount() ];
|
||||||
|
for (int i=0;i<getColumnCount();i++)
|
||||||
|
header[i] = p_columns.get(i).getLabel();
|
||||||
|
|
||||||
|
cells.add( header );
|
||||||
|
|
||||||
|
for (int row=0;row<getRowCount();row++)
|
||||||
|
{
|
||||||
|
String[] record = new String[ getColumnCount() ];
|
||||||
|
|
||||||
|
for (int column=0;column<getColumnCount();column++)
|
||||||
|
if (getValueAt(row, column)!=null)
|
||||||
|
record[column] = getValueAt(row, column).toString();
|
||||||
|
else
|
||||||
|
record[column] = "";
|
||||||
|
|
||||||
|
cells.add(record);
|
||||||
|
}
|
||||||
|
|
||||||
|
csv.saveToFile(exportFile);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
};
|
|
@ -0,0 +1,170 @@
|
||||||
|
package org.hwo.models.TableMapper;
|
||||||
|
|
||||||
|
import java.beans.PropertyChangeEvent;
|
||||||
|
import java.beans.PropertyChangeListener;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
import javax.swing.DefaultListSelectionModel;
|
||||||
|
import javax.swing.ListSelectionModel;
|
||||||
|
import javax.swing.event.ChangeEvent;
|
||||||
|
import javax.swing.event.TableColumnModelListener;
|
||||||
|
import javax.swing.table.TableColumn;
|
||||||
|
import javax.swing.table.TableColumnModel;
|
||||||
|
|
||||||
|
import org.hwo.models.TableMapper.TableMapper.ColumnInfo;
|
||||||
|
|
||||||
|
class TableMapperColumnModel implements TableColumnModel{
|
||||||
|
|
||||||
|
private TableMapper tableMapper;
|
||||||
|
private LinkedList<TableColumnModelListener> listeners;
|
||||||
|
|
||||||
|
private ArrayList<TableColumn> tableColumns;
|
||||||
|
|
||||||
|
private int margin;
|
||||||
|
|
||||||
|
private ListSelectionModel listSelectionModel;
|
||||||
|
|
||||||
|
public TableMapperColumnModel(TableMapper tableMapper)
|
||||||
|
{
|
||||||
|
this.tableMapper = tableMapper;
|
||||||
|
this.listeners = new LinkedList<TableColumnModelListener>();
|
||||||
|
this.tableColumns = new ArrayList<TableColumn>();
|
||||||
|
this.listSelectionModel = new DefaultListSelectionModel();
|
||||||
|
|
||||||
|
for (int i=0;i<tableMapper.getColumnCount();i++)
|
||||||
|
{
|
||||||
|
ColumnInfo ci = tableMapper.getColumnInfo().get(i);
|
||||||
|
TableColumn tc = new TableColumn(i, ci.getWidth());
|
||||||
|
tc.setPreferredWidth(ci.getWidth());
|
||||||
|
tc.setHeaderValue(ci.getLabel());
|
||||||
|
tc.addPropertyChangeListener(new PropertyChangeListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void propertyChange(PropertyChangeEvent arg0) {
|
||||||
|
fireColumnMarginChanged();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
tableColumns.add(tc);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void fireColumnMarginChanged()
|
||||||
|
{
|
||||||
|
for (TableColumnModelListener listener:listeners)
|
||||||
|
listener.columnMarginChanged(new ChangeEvent(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addColumn(TableColumn aColumn) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addColumnModelListener(TableColumnModelListener x) {
|
||||||
|
listeners.add(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeColumnModelListener(TableColumnModelListener x) {
|
||||||
|
listeners.remove(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TableColumn getColumn(int columnIndex) {
|
||||||
|
return tableColumns.get(columnIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getColumnCount() {
|
||||||
|
return tableColumns.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getColumnIndex(Object columnIdentifier) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getColumnIndexAtX(int xPosition) {
|
||||||
|
int pos = 0;
|
||||||
|
for (int i=0;i<tableColumns.size();i++)
|
||||||
|
{
|
||||||
|
pos += tableColumns.get(i).getWidth();
|
||||||
|
|
||||||
|
if (xPosition < pos)
|
||||||
|
return i;
|
||||||
|
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getColumnMargin() {
|
||||||
|
return margin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getColumnSelectionAllowed() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Enumeration<TableColumn> getColumns() {
|
||||||
|
return new Vector<TableColumn>(tableColumns).elements();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSelectedColumnCount() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int[] getSelectedColumns() {
|
||||||
|
return new int[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ListSelectionModel getSelectionModel() {
|
||||||
|
return listSelectionModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getTotalColumnWidth() {
|
||||||
|
int width = 0;
|
||||||
|
for (TableColumn tc:tableColumns)
|
||||||
|
width += tc.getWidth();
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void moveColumn(int columnIndex, int newIndex) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeColumn(TableColumn column) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setColumnMargin(int newMargin) {
|
||||||
|
margin = newMargin;
|
||||||
|
fireColumnMarginChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setColumnSelectionAllowed(boolean flag) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSelectionModel(ListSelectionModel newModel) {
|
||||||
|
listSelectionModel = newModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package org.hwo.models.TableMapper;
|
||||||
|
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface TableMapperObject {
|
||||||
|
|
||||||
|
String editorField();
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
package org.hwo.thread;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.EventListener;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public abstract class ThreadedOperation extends Thread{
|
||||||
|
|
||||||
|
List<ThreadedOperationUpdateListener> updateListeners;
|
||||||
|
private String operationName;
|
||||||
|
|
||||||
|
|
||||||
|
public ThreadedOperation()
|
||||||
|
{
|
||||||
|
updateListeners = new ArrayList<ThreadedOperationUpdateListener>();
|
||||||
|
operationName = "AktivitŠt...";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addThreadedOperationUpdateListener(ThreadedOperationUpdateListener listener)
|
||||||
|
{
|
||||||
|
updateListeners.add(listener);
|
||||||
|
}
|
||||||
|
public void removeThreadedOperationUpdateListener(ThreadedOperationUpdateListener listener)
|
||||||
|
{
|
||||||
|
updateListeners.remove(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void fireUpdate(ThreadedOperationUpdateArgs updateArgs)
|
||||||
|
{
|
||||||
|
for (ThreadedOperationUpdateListener listener:updateListeners)
|
||||||
|
listener.threadedOperationUpdate(updateArgs);
|
||||||
|
}
|
||||||
|
protected void fireUpdate(Integer progressOperation,Integer progressStep)
|
||||||
|
{
|
||||||
|
fireUpdate(new ThreadedOperationUpdateArgs(progressOperation,progressStep));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void fireUpdate(Integer progressOperation,Integer progressStep,String statusText)
|
||||||
|
{
|
||||||
|
fireUpdate(new ThreadedOperationUpdateArgs(progressOperation,progressStep,statusText));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void fireUpdate(Integer progressOperation,Integer progressStep,String statusText,String stepLabel)
|
||||||
|
{
|
||||||
|
fireUpdate(new ThreadedOperationUpdateArgs(progressOperation,progressStep,statusText,stepLabel));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void fireFinished(int code)
|
||||||
|
{
|
||||||
|
for (ThreadedOperationUpdateListener listener:updateListeners)
|
||||||
|
listener.threadedOperationFinished(code);
|
||||||
|
}
|
||||||
|
protected void fireFinished()
|
||||||
|
{
|
||||||
|
fireFinished(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void run();
|
||||||
|
|
||||||
|
public String getOperationName() {
|
||||||
|
return operationName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOperationName(String operationName) {
|
||||||
|
this.operationName = operationName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,77 @@
|
||||||
|
package org.hwo.thread;
|
||||||
|
|
||||||
|
public class ThreadedOperationUpdateArgs {
|
||||||
|
|
||||||
|
private Integer progressOperation;
|
||||||
|
private Integer progressStep;
|
||||||
|
private String stepLabel;
|
||||||
|
private String statusText;
|
||||||
|
private String titleText;
|
||||||
|
|
||||||
|
public ThreadedOperationUpdateArgs()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public ThreadedOperationUpdateArgs(Integer progressStep)
|
||||||
|
{
|
||||||
|
this.progressStep = progressStep;
|
||||||
|
}
|
||||||
|
public ThreadedOperationUpdateArgs(Integer progressOperation,Integer progressStep)
|
||||||
|
{
|
||||||
|
this.progressOperation = progressOperation;
|
||||||
|
this.progressStep = progressStep;
|
||||||
|
}
|
||||||
|
public ThreadedOperationUpdateArgs(Integer progressOperation,Integer progressStep,String statusText)
|
||||||
|
{
|
||||||
|
this.progressOperation = progressOperation;
|
||||||
|
this.progressStep = progressStep;
|
||||||
|
this.statusText = statusText;
|
||||||
|
}
|
||||||
|
public ThreadedOperationUpdateArgs(Integer progressOperation,Integer progressStep,String statusText,String stepLabel)
|
||||||
|
{
|
||||||
|
this.progressOperation = progressOperation;
|
||||||
|
this.progressStep = progressStep;
|
||||||
|
this.statusText = statusText;
|
||||||
|
this.stepLabel = stepLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStepLabel() {
|
||||||
|
return stepLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStepLabel(String stepLabel) {
|
||||||
|
this.stepLabel = stepLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getProgressStep() {
|
||||||
|
return progressStep;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProgressStep(Integer progressStep) {
|
||||||
|
this.progressStep = progressStep;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getProgressOperation() {
|
||||||
|
return progressOperation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProgressOperation(Integer progressOperation) {
|
||||||
|
this.progressOperation = progressOperation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatusText() {
|
||||||
|
return statusText;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatusText(String statusText) {
|
||||||
|
this.statusText = statusText;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitleText() {
|
||||||
|
return titleText;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitleText(String titleText) {
|
||||||
|
this.titleText = titleText;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
package org.hwo.thread;
|
||||||
|
|
||||||
|
public interface ThreadedOperationUpdateListener {
|
||||||
|
public void threadedOperationUpdate(ThreadedOperationUpdateArgs args);
|
||||||
|
public void threadedOperationFinished(int result);
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package org.hwo.ui;
|
||||||
|
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
|
||||||
|
import org.hwo.ui.treetable.TreeTable;
|
||||||
|
|
||||||
|
public interface CellEditor {
|
||||||
|
|
||||||
|
public void addCellEditorListener(CellEditorListener listener);
|
||||||
|
public void removeCellEditorListener(CellEditorListener listener);
|
||||||
|
|
||||||
|
public boolean editBegin(TreeTable treeTable,Rectangle rect,Object value);
|
||||||
|
public void editCancel();
|
||||||
|
public void editFinish();
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
package org.hwo.ui;
|
||||||
|
|
||||||
|
import org.hwo.ui.treetable.TreeTable;
|
||||||
|
|
||||||
|
public class CellEditorArgs {
|
||||||
|
|
||||||
|
private CellEditor cellEditor;
|
||||||
|
private Object value;
|
||||||
|
private TreeTable treeTable;
|
||||||
|
|
||||||
|
public CellEditorArgs(CellEditor cellEditor,Object value,TreeTable treeTable)
|
||||||
|
{
|
||||||
|
this.cellEditor = cellEditor;
|
||||||
|
this.value = value;
|
||||||
|
this.treeTable = treeTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CellEditor getCellEditor() {
|
||||||
|
return cellEditor;
|
||||||
|
}
|
||||||
|
public void setCellEditor(CellEditor cellEditor) {
|
||||||
|
this.cellEditor = cellEditor;
|
||||||
|
}
|
||||||
|
public Object getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
public void setValue(Object value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
public TreeTable getTreeTable() {
|
||||||
|
return treeTable;
|
||||||
|
}
|
||||||
|
public void setTreeTable(TreeTable treeTable) {
|
||||||
|
this.treeTable = treeTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package org.hwo.ui;
|
||||||
|
|
||||||
|
public interface CellEditorListener {
|
||||||
|
|
||||||
|
public void editBegin(CellEditorArgs args);
|
||||||
|
public void editCanceled(CellEditorArgs args);
|
||||||
|
public void editFinished(CellEditorArgs args);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package org.hwo.ui;
|
||||||
|
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
|
||||||
|
public interface CellRenderer {
|
||||||
|
|
||||||
|
public void renderCell(Graphics g,int row,int column,Rectangle cellRect,Object value,Object rowObject);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,102 @@
|
||||||
|
package org.hwo.ui;
|
||||||
|
|
||||||
|
import java.awt.Container;
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
|
||||||
|
import org.hwo.ui.treetable.TreeTable;
|
||||||
|
|
||||||
|
public class DefaultCellEditor implements CellEditor {
|
||||||
|
|
||||||
|
private List<CellEditorListener> editorListeners;
|
||||||
|
|
||||||
|
private JTextField textField;
|
||||||
|
private TreeTable treeTable;
|
||||||
|
private Object value;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addCellEditorListener(CellEditorListener listener) {
|
||||||
|
editorListeners.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeCellEditorListener(CellEditorListener listener) {
|
||||||
|
editorListeners.remove(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fireEditBegin()
|
||||||
|
{
|
||||||
|
CellEditorArgs args = new CellEditorArgs(this, value, treeTable);
|
||||||
|
for (CellEditorListener listener: editorListeners)
|
||||||
|
listener.editBegin(args);
|
||||||
|
}
|
||||||
|
private void fireEditFinish()
|
||||||
|
{
|
||||||
|
CellEditorArgs args = new CellEditorArgs(this, value, treeTable);
|
||||||
|
for (CellEditorListener listener: editorListeners)
|
||||||
|
listener.editFinished(args);
|
||||||
|
}
|
||||||
|
private void fireEditCancel()
|
||||||
|
{
|
||||||
|
CellEditorArgs args = new CellEditorArgs(this, value, treeTable);
|
||||||
|
for (CellEditorListener listener: editorListeners)
|
||||||
|
listener.editCanceled(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void destroyTextField()
|
||||||
|
{
|
||||||
|
textField.setVisible(false);
|
||||||
|
Container parent = textField.getParent();
|
||||||
|
|
||||||
|
parent.remove(textField);
|
||||||
|
|
||||||
|
textField = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean editBegin(TreeTable treeTable, Rectangle rect, Object value) {
|
||||||
|
if (textField != null)
|
||||||
|
editCancel();
|
||||||
|
|
||||||
|
this.treeTable = treeTable;
|
||||||
|
this.value = value;
|
||||||
|
|
||||||
|
this.textField = new JTextField();
|
||||||
|
treeTable.add(textField);
|
||||||
|
|
||||||
|
textField.setBounds(rect);
|
||||||
|
textField.requestFocusInWindow();
|
||||||
|
textField.repaint();
|
||||||
|
|
||||||
|
fireEditBegin();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void editCancel() {
|
||||||
|
if (textField != null)
|
||||||
|
{
|
||||||
|
destroyTextField();
|
||||||
|
|
||||||
|
fireEditCancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void editFinish() {
|
||||||
|
if (this.textField != null)
|
||||||
|
{
|
||||||
|
this.value = this.textField.getText();
|
||||||
|
destroyTextField();
|
||||||
|
|
||||||
|
fireEditFinish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package org.hwo.ui;
|
||||||
|
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
|
||||||
|
public class DefaultCellRenderer implements CellRenderer{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renderCell(Graphics g,int row,int column, Rectangle cellRect, Object value,Object rowObject)
|
||||||
|
{
|
||||||
|
if (value != null)
|
||||||
|
{
|
||||||
|
g.drawString( value.toString(),
|
||||||
|
cellRect.x + 2,
|
||||||
|
cellRect.y + cellRect.height - 4
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,66 @@
|
||||||
|
package org.hwo.ui;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.swing.JTable;
|
||||||
|
import javax.swing.event.ListSelectionListener;
|
||||||
|
|
||||||
|
import org.hwo.models.FlexibleObjectTableModel;
|
||||||
|
|
||||||
|
public class FlexibleJTable<T> extends JTable {
|
||||||
|
private FlexibleObjectTableModel<T> model;
|
||||||
|
|
||||||
|
public FlexibleJTable(Class class_t)
|
||||||
|
{
|
||||||
|
this.model = new FlexibleObjectTableModel<T>(class_t);
|
||||||
|
this.setModel(this.model);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FlexibleObjectTableModel<T> getModel()
|
||||||
|
{
|
||||||
|
return this.model;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T getSelectedObject()
|
||||||
|
{
|
||||||
|
if (this.getSelectedRow()==-1)
|
||||||
|
return null;
|
||||||
|
return this.model.getRows().get(this.getSelectedRow());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addListSelectionListener(ListSelectionListener listener)
|
||||||
|
{
|
||||||
|
this.getSelectionModel().addListSelectionListener(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeListSelectionListener(ListSelectionListener listener)
|
||||||
|
{
|
||||||
|
this.getSelectionModel().removeListSelectionListener(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addColumn(String column)
|
||||||
|
{
|
||||||
|
this.addColumn(column, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addColumn(String column,boolean readonly)
|
||||||
|
{
|
||||||
|
this.model.addColumn(column,readonly);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRows(List<T> rows)
|
||||||
|
{
|
||||||
|
this.model.setRows(rows);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addRow(T o)
|
||||||
|
{
|
||||||
|
this.model.addRow(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRowCount()
|
||||||
|
{
|
||||||
|
return this.model.getRowCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,75 @@
|
||||||
|
package org.hwo.ui;
|
||||||
|
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.event.MouseListener;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.swing.DefaultListModel;
|
||||||
|
import javax.swing.JList;
|
||||||
|
|
||||||
|
import org.hwo.interactiveobjects.IInteractiveObjectEditor;
|
||||||
|
import org.hwo.interactiveobjects.InteractiveObjectHelper;
|
||||||
|
|
||||||
|
public class InteractiveObjectListView extends JList {
|
||||||
|
|
||||||
|
DefaultListModel pModel;
|
||||||
|
|
||||||
|
public InteractiveObjectListView()
|
||||||
|
{
|
||||||
|
this.addMouseListener(new MouseListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseReleased(MouseEvent arg0) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent arg0) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseExited(MouseEvent arg0) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseEntered(MouseEvent arg0) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent arg0) {
|
||||||
|
if (arg0.getClickCount()==2)
|
||||||
|
openEditor();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
pModel = new DefaultListModel();
|
||||||
|
setModel(pModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void openEditor()
|
||||||
|
{
|
||||||
|
if (getSelectedIndex() != -1)
|
||||||
|
{
|
||||||
|
IInteractiveObjectEditor oe = InteractiveObjectHelper.getEditor(getSelectedValue());
|
||||||
|
if (oe != null)
|
||||||
|
oe.setVisible(true);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setItems(List items)
|
||||||
|
{
|
||||||
|
pModel.clear();
|
||||||
|
for (Object o:items)
|
||||||
|
{
|
||||||
|
pModel.addElement(o);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,93 @@
|
||||||
|
package org.hwo.ui;
|
||||||
|
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
|
||||||
|
import java.awt.GridBagLayout;
|
||||||
|
import java.awt.GridBagConstraints;
|
||||||
|
import java.awt.Insets;
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
|
||||||
|
public class JCalendar extends JPanel {
|
||||||
|
private JTextField tfDate;
|
||||||
|
|
||||||
|
private Date date;
|
||||||
|
private JButton btnLookup;
|
||||||
|
private boolean nullable;
|
||||||
|
|
||||||
|
public JCalendar() {
|
||||||
|
setMaximumSize(new Dimension(32767, 30));
|
||||||
|
GridBagLayout gridBagLayout = new GridBagLayout();
|
||||||
|
gridBagLayout.columnWidths = new int[]{100, 134, 0};
|
||||||
|
gridBagLayout.rowHeights = new int[]{29, 0};
|
||||||
|
gridBagLayout.columnWeights = new double[]{1.0, 0.0, Double.MIN_VALUE};
|
||||||
|
gridBagLayout.rowWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||||
|
setLayout(gridBagLayout);
|
||||||
|
|
||||||
|
tfDate = new JTextField();
|
||||||
|
GridBagConstraints gbc_tfDate = new GridBagConstraints();
|
||||||
|
gbc_tfDate.fill = GridBagConstraints.BOTH;
|
||||||
|
gbc_tfDate.insets = new Insets(0, 0, 0, 5);
|
||||||
|
gbc_tfDate.gridx = 0;
|
||||||
|
gbc_tfDate.gridy = 0;
|
||||||
|
add(tfDate, gbc_tfDate);
|
||||||
|
tfDate.setColumns(10);
|
||||||
|
|
||||||
|
btnLookup = new JButton("X");
|
||||||
|
btnLookup.setMaximumSize(new Dimension(25, 29));
|
||||||
|
btnLookup.setPreferredSize(new Dimension(25, 29));
|
||||||
|
btnLookup.setMinimumSize(new Dimension(25, 29));
|
||||||
|
GridBagConstraints gbc_btnLookup = new GridBagConstraints();
|
||||||
|
gbc_btnLookup.fill = GridBagConstraints.BOTH;
|
||||||
|
gbc_btnLookup.gridx = 1;
|
||||||
|
gbc_btnLookup.gridy = 0;
|
||||||
|
add(btnLookup, gbc_btnLookup);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateView()
|
||||||
|
{
|
||||||
|
tfDate.setEnabled(false);
|
||||||
|
|
||||||
|
if (date != null)
|
||||||
|
{
|
||||||
|
btnLookup.setEnabled(false);
|
||||||
|
tfDate.setText( SimpleDateFormat.getInstance().format(date));
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
btnLookup.setEnabled(false);
|
||||||
|
tfDate.setText("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Date getDate() {
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDate(Date date) {
|
||||||
|
this.date = date;
|
||||||
|
updateView();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(Object value)
|
||||||
|
{
|
||||||
|
setDate((Date)value);
|
||||||
|
}
|
||||||
|
public Object getValue()
|
||||||
|
{
|
||||||
|
return this.getDate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isNullable() {
|
||||||
|
return nullable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNullable(boolean nullable) {
|
||||||
|
this.nullable = nullable;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package org.hwo.ui;
|
||||||
|
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
|
||||||
|
public abstract class MousePopupListener extends MouseAdapter {
|
||||||
|
|
||||||
|
public void mouseClicked(MouseEvent arg0) {
|
||||||
|
checkPopup(arg0);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent arg0) {
|
||||||
|
checkPopup(arg0);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void mouseReleased(MouseEvent arg0) {
|
||||||
|
checkPopup(arg0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkPopup(MouseEvent e)
|
||||||
|
{
|
||||||
|
if (e.isPopupTrigger())
|
||||||
|
popupTriggered(e.getX(),e.getY());
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void popupTriggered(int x,int y);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,183 @@
|
||||||
|
package org.hwo.ui;
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.FlowLayout;
|
||||||
|
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JDialog;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.border.EmptyBorder;
|
||||||
|
|
||||||
|
import java.awt.GridBagLayout;
|
||||||
|
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
|
||||||
|
import java.awt.GridBagConstraints;
|
||||||
|
import java.awt.Insets;
|
||||||
|
import java.awt.Font;
|
||||||
|
|
||||||
|
import javax.swing.JProgressBar;
|
||||||
|
import javax.swing.border.TitledBorder;
|
||||||
|
import javax.swing.JTextArea;
|
||||||
|
|
||||||
|
import org.hwo.thread.ThreadedOperation;
|
||||||
|
import org.hwo.thread.ThreadedOperationUpdateArgs;
|
||||||
|
import org.hwo.thread.ThreadedOperationUpdateListener;
|
||||||
|
|
||||||
|
import java.awt.Dialog.ModalExclusionType;
|
||||||
|
import java.awt.Dialog.ModalityType;
|
||||||
|
import java.awt.event.WindowAdapter;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
|
||||||
|
public class ProgressDialog extends JDialog implements ThreadedOperationUpdateListener{
|
||||||
|
|
||||||
|
private final JPanel contentPanel = new JPanel();
|
||||||
|
private JProgressBar pSchritt;
|
||||||
|
private JProgressBar pGesamt;
|
||||||
|
private JTextArea taStatus;
|
||||||
|
private JLabel lblSchritt;
|
||||||
|
|
||||||
|
private int operationResult;
|
||||||
|
private boolean operationFinished;
|
||||||
|
|
||||||
|
|
||||||
|
public static int executeOperation(ThreadedOperation operation)
|
||||||
|
{
|
||||||
|
ProgressDialog dialog = new ProgressDialog();
|
||||||
|
operation.addThreadedOperationUpdateListener(dialog);
|
||||||
|
dialog.setTitle(operation.getName());
|
||||||
|
operation.start();
|
||||||
|
dialog.setVisible(true);
|
||||||
|
operation.removeThreadedOperationUpdateListener(dialog);
|
||||||
|
return dialog.getOperationResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the dialog.
|
||||||
|
*/
|
||||||
|
protected ProgressDialog() {
|
||||||
|
addWindowListener(new WindowAdapter() {
|
||||||
|
@Override
|
||||||
|
public void windowClosing(WindowEvent arg0) {
|
||||||
|
if (!operationFinished)
|
||||||
|
setVisible(true);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void windowOpened(WindowEvent e) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
setModalityType(ModalityType.APPLICATION_MODAL);
|
||||||
|
setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE);
|
||||||
|
setBounds(100, 100, 691, 270);
|
||||||
|
getContentPane().setLayout(new BorderLayout());
|
||||||
|
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||||
|
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
||||||
|
GridBagLayout gbl_contentPanel = new GridBagLayout();
|
||||||
|
gbl_contentPanel.columnWidths = new int[] {0};
|
||||||
|
gbl_contentPanel.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0};
|
||||||
|
gbl_contentPanel.columnWeights = new double[]{1.0};
|
||||||
|
gbl_contentPanel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
|
||||||
|
contentPanel.setLayout(gbl_contentPanel);
|
||||||
|
{
|
||||||
|
JLabel lblBitteWarten = new JLabel("Bitte warten...");
|
||||||
|
lblBitteWarten.setFont(new Font("Lucida Grande", Font.PLAIN, 32));
|
||||||
|
GridBagConstraints gbc_lblBitteWarten = new GridBagConstraints();
|
||||||
|
gbc_lblBitteWarten.insets = new Insets(0, 0, 5, 0);
|
||||||
|
gbc_lblBitteWarten.gridx = 0;
|
||||||
|
gbc_lblBitteWarten.gridy = 0;
|
||||||
|
contentPanel.add(lblBitteWarten, gbc_lblBitteWarten);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
JLabel lblGesamtfortschritt = new JLabel("Gesamtfortschritt:");
|
||||||
|
GridBagConstraints gbc_lblGesamtfortschritt = new GridBagConstraints();
|
||||||
|
gbc_lblGesamtfortschritt.insets = new Insets(0, 0, 5, 0);
|
||||||
|
gbc_lblGesamtfortschritt.gridx = 0;
|
||||||
|
gbc_lblGesamtfortschritt.gridy = 1;
|
||||||
|
contentPanel.add(lblGesamtfortschritt, gbc_lblGesamtfortschritt);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
pGesamt = new JProgressBar();
|
||||||
|
GridBagConstraints gbc_pGesamt = new GridBagConstraints();
|
||||||
|
gbc_pGesamt.insets = new Insets(0, 0, 5, 0);
|
||||||
|
gbc_pGesamt.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
gbc_pGesamt.gridx = 0;
|
||||||
|
gbc_pGesamt.gridy = 2;
|
||||||
|
contentPanel.add(pGesamt, gbc_pGesamt);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
lblSchritt = new JLabel("Arbeitsschritt:");
|
||||||
|
GridBagConstraints gbc_lblSchritt = new GridBagConstraints();
|
||||||
|
gbc_lblSchritt.insets = new Insets(0, 0, 5, 0);
|
||||||
|
gbc_lblSchritt.gridx = 0;
|
||||||
|
gbc_lblSchritt.gridy = 3;
|
||||||
|
contentPanel.add(lblSchritt, gbc_lblSchritt);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
pSchritt = new JProgressBar();
|
||||||
|
GridBagConstraints gbc_pSchritt = new GridBagConstraints();
|
||||||
|
gbc_pSchritt.insets = new Insets(0, 0, 5, 0);
|
||||||
|
gbc_pSchritt.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
gbc_pSchritt.gridx = 0;
|
||||||
|
gbc_pSchritt.gridy = 4;
|
||||||
|
contentPanel.add(pSchritt, gbc_pSchritt);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
JPanel panel = new JPanel();
|
||||||
|
panel.setBorder(new TitledBorder(null, "Status", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||||
|
GridBagConstraints gbc_panel = new GridBagConstraints();
|
||||||
|
gbc_panel.fill = GridBagConstraints.BOTH;
|
||||||
|
gbc_panel.gridx = 0;
|
||||||
|
gbc_panel.gridy = 5;
|
||||||
|
contentPanel.add(panel, gbc_panel);
|
||||||
|
GridBagLayout gbl_panel = new GridBagLayout();
|
||||||
|
gbl_panel.columnWidths = new int[]{0, 0};
|
||||||
|
gbl_panel.rowHeights = new int[]{0, 0};
|
||||||
|
gbl_panel.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||||
|
gbl_panel.rowWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||||
|
panel.setLayout(gbl_panel);
|
||||||
|
{
|
||||||
|
taStatus = new JTextArea();
|
||||||
|
GridBagConstraints gbc_taStatus = new GridBagConstraints();
|
||||||
|
gbc_taStatus.fill = GridBagConstraints.BOTH;
|
||||||
|
gbc_taStatus.gridx = 0;
|
||||||
|
gbc_taStatus.gridy = 0;
|
||||||
|
panel.add(taStatus, gbc_taStatus);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int getOperationResult() {
|
||||||
|
return operationResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setOperationResult(int operationResult) {
|
||||||
|
this.operationResult = operationResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void threadedOperationUpdate(ThreadedOperationUpdateArgs args) {
|
||||||
|
if (args.getProgressOperation()!=null)
|
||||||
|
pGesamt.setValue(args.getProgressOperation());
|
||||||
|
if (args.getProgressStep()!=null)
|
||||||
|
pSchritt.setValue(args.getProgressStep());
|
||||||
|
if (args.getStepLabel()!=null)
|
||||||
|
lblSchritt.setText(args.getStepLabel());
|
||||||
|
if (args.getStatusText()!=null)
|
||||||
|
taStatus.setText(args.getStatusText());
|
||||||
|
if (args.getTitleText()!=null)
|
||||||
|
setTitle(args.getTitleText());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void threadedOperationFinished(int result) {
|
||||||
|
operationResult = result;
|
||||||
|
operationFinished = true;
|
||||||
|
setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package org.hwo.ui.shapes;
|
||||||
|
|
||||||
|
import java.awt.Polygon;
|
||||||
|
|
||||||
|
public class Triangle extends Polygon {
|
||||||
|
|
||||||
|
public Triangle(int x1,int y1,int x2,int y2,int x3,int y3)
|
||||||
|
{
|
||||||
|
super(new int[]{x1,x2,x3},new int[]{y1,y2,y3},3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,198 @@
|
||||||
|
package org.hwo.ui.treetable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.hwo.ui.CellRenderer;
|
||||||
|
|
||||||
|
public class DefaultTreeTableColumnModel implements TreeTableColumnModel {
|
||||||
|
|
||||||
|
public class Column
|
||||||
|
{
|
||||||
|
private String label;
|
||||||
|
private int width;
|
||||||
|
private int modelColumn;
|
||||||
|
private CellRenderer
|
||||||
|
cellRenderer;
|
||||||
|
private TreeTablePopupListener
|
||||||
|
popupListener;
|
||||||
|
|
||||||
|
public String getLabel() {
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
public void setLabel(String label) {
|
||||||
|
this.label = label;
|
||||||
|
fireColumnsChanged();
|
||||||
|
}
|
||||||
|
public int getWidth() {
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
public Column setWidth(int width) {
|
||||||
|
this.width = width;
|
||||||
|
fireColumnsChanged();
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public int getModelColumn() {
|
||||||
|
return modelColumn;
|
||||||
|
}
|
||||||
|
public Column setModelColumn(int modelColumn) {
|
||||||
|
this.modelColumn = modelColumn;
|
||||||
|
fireColumnsChanged();
|
||||||
|
|
||||||
|
return this; }
|
||||||
|
public CellRenderer getCellRenderer() {
|
||||||
|
return cellRenderer;
|
||||||
|
}
|
||||||
|
public Column setCellRenderer(CellRenderer cellRenderer) {
|
||||||
|
this.cellRenderer = cellRenderer;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public TreeTablePopupListener getPopupListener() {
|
||||||
|
return popupListener;
|
||||||
|
}
|
||||||
|
public Column setPopupListener(TreeTablePopupListener popupListener) {
|
||||||
|
this.popupListener = popupListener;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Column> columns;
|
||||||
|
private List<TreeTableModelListener> treeTableModelListener;
|
||||||
|
|
||||||
|
public DefaultTreeTableColumnModel()
|
||||||
|
{
|
||||||
|
treeTableModelListener = new LinkedList<TreeTableModelListener>();
|
||||||
|
|
||||||
|
columns = new ArrayList<DefaultTreeTableColumnModel.Column>();
|
||||||
|
Column column = new Column();
|
||||||
|
column.label = "";
|
||||||
|
column.width = 280;
|
||||||
|
columns.add(column);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Column addColumn(String label)
|
||||||
|
{
|
||||||
|
return addColumn(label,100);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Column addColumn(String label,int width)
|
||||||
|
{
|
||||||
|
return addColumn(label, width, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Column addColumn(String label,int width,int modelColumn)
|
||||||
|
{
|
||||||
|
Column column = new Column();
|
||||||
|
column.label = label;
|
||||||
|
column.width = width;
|
||||||
|
columns.add(column);
|
||||||
|
|
||||||
|
if (modelColumn == -1)
|
||||||
|
column.modelColumn = columns.indexOf(column);
|
||||||
|
else
|
||||||
|
column.modelColumn = modelColumn;
|
||||||
|
|
||||||
|
fireColumnsChanged();
|
||||||
|
return column;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeColumn(int column)
|
||||||
|
{
|
||||||
|
columns.remove(column);
|
||||||
|
fireColumnsChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Column getColumn(int column)
|
||||||
|
{
|
||||||
|
return columns.get(column);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int indexOfColumn(Column column)
|
||||||
|
{
|
||||||
|
return columns.indexOf(column);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getColumnCount() {
|
||||||
|
return columns.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getColumnLabel(int column) {
|
||||||
|
return columns.get(column).getLabel();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getColumnWidth(int column) {
|
||||||
|
return columns.get(column).getWidth();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getColumnPos(int column) {
|
||||||
|
int x = 0;
|
||||||
|
for (int i=0;i<column;i++)
|
||||||
|
x += getColumnWidth(i);
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addTreeTableModelListener(TreeTableModelListener listener) {
|
||||||
|
treeTableModelListener.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeTreeTableModelListener(TreeTableModelListener listener) {
|
||||||
|
treeTableModelListener.remove(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fireColumnsChanged()
|
||||||
|
{
|
||||||
|
for (TreeTableModelListener listener:treeTableModelListener)
|
||||||
|
listener.rowsChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getColumnAtX(int x) {
|
||||||
|
for (int i=0;i<columns.size();i++)
|
||||||
|
{
|
||||||
|
if (x < getColumnPos(i+1))
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CellRenderer getColumnCellRenderer(int column) {
|
||||||
|
return columns.get(column).getCellRenderer();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getColumnModelColumn(int x)
|
||||||
|
{
|
||||||
|
return getColumn(x).modelColumn;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TreeTablePopupListener getPopup(int row, int column) {
|
||||||
|
TreeTablePopupListener listener;
|
||||||
|
|
||||||
|
listener = getPopupFromColumn(column);
|
||||||
|
if (listener == null)
|
||||||
|
listener = getPopupFromRow(row);
|
||||||
|
|
||||||
|
return listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected TreeTablePopupListener getPopupFromRow(int row)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected TreeTablePopupListener getPopupFromColumn(int column)
|
||||||
|
{
|
||||||
|
return columns.get(column).getPopupListener();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,83 @@
|
||||||
|
package org.hwo.ui.treetable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DefaultTreeTableModel implements TreeTableModel {
|
||||||
|
|
||||||
|
private TreeTableElement rootNode;
|
||||||
|
private List<TreeTableModelListener> treeTableModelListener;
|
||||||
|
|
||||||
|
public DefaultTreeTableModel()
|
||||||
|
{
|
||||||
|
treeTableModelListener = new LinkedList<TreeTableModelListener>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getParent(Object node) {
|
||||||
|
return ((TreeTableElement)node).getParent();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getChildCount(Object parent) {
|
||||||
|
return ((TreeTableElement)parent).getChildCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getChild(Object parent, int index) {
|
||||||
|
return ((TreeTableElement)parent).getChild(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getRoot() {
|
||||||
|
return getRootNode();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeaf(Object node) {
|
||||||
|
if (((TreeTableElement)node).getChildCount()==0)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getValue(Object node, int column) {
|
||||||
|
return ((TreeTableElement)node).getValue(column);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public TreeTableElement getRootNode() {
|
||||||
|
return rootNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRootNode(TreeTableElement rootNode) {
|
||||||
|
this.rootNode = rootNode;
|
||||||
|
fireRowsChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TreeTableColumnModel getDefaultColumnModel() {
|
||||||
|
return new DefaultTreeTableColumnModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addTreeTableModelListener(TreeTableModelListener listener) {
|
||||||
|
treeTableModelListener.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeTreeTableModelListener(TreeTableModelListener listener) {
|
||||||
|
treeTableModelListener.remove(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fireRowsChanged()
|
||||||
|
{
|
||||||
|
for (TreeTableModelListener listener:treeTableModelListener)
|
||||||
|
listener.rowsChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,623 @@
|
||||||
|
package org.hwo.ui.treetable;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.FlowLayout;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.GridLayout;
|
||||||
|
import java.awt.Point;
|
||||||
|
import java.awt.Polygon;
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.event.MouseListener;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Hashtable;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.swing.JViewport;
|
||||||
|
import javax.swing.Scrollable;
|
||||||
|
import javax.swing.SwingConstants;
|
||||||
|
|
||||||
|
import org.hwo.ui.CellEditor;
|
||||||
|
import org.hwo.ui.CellEditorArgs;
|
||||||
|
import org.hwo.ui.CellEditorListener;
|
||||||
|
import org.hwo.ui.CellRenderer;
|
||||||
|
import org.hwo.ui.DefaultCellEditor;
|
||||||
|
import org.hwo.ui.DefaultCellRenderer;
|
||||||
|
import org.hwo.ui.shapes.Triangle;
|
||||||
|
import org.hwo.ui.treetable.DefaultTreeTableColumnModel.Column;
|
||||||
|
|
||||||
|
public class TreeTable extends JComponent implements Scrollable, TreeTableModelListener, CellEditorListener {
|
||||||
|
|
||||||
|
class NodeState
|
||||||
|
{
|
||||||
|
private boolean opened;
|
||||||
|
|
||||||
|
public int indentation;
|
||||||
|
|
||||||
|
public boolean isOpened() {
|
||||||
|
return opened;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOpened(boolean opened) {
|
||||||
|
this.opened = opened;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class HeaderView extends JComponent
|
||||||
|
{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paint(Graphics g) {
|
||||||
|
|
||||||
|
g.drawLine(0, getHeight()-1, TreeTable.this.preferredSize.width - 1, getHeight()-1);
|
||||||
|
|
||||||
|
for (int i=0;i<columnModel.getColumnCount();i++)
|
||||||
|
{
|
||||||
|
int left = columnModel.getColumnPos(i);
|
||||||
|
int width = columnModel.getColumnWidth(i);
|
||||||
|
int right = left + width - 1;
|
||||||
|
|
||||||
|
g.setColor(getForeground());
|
||||||
|
g.drawString(columnModel.getColumnLabel(i), left + 2, rowHeight - 3);
|
||||||
|
g.drawLine( right, 0, right, getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private TreeTableModel model;
|
||||||
|
private TreeTableColumnModel
|
||||||
|
columnModel;
|
||||||
|
|
||||||
|
private int rowHeight;
|
||||||
|
|
||||||
|
private List<Object> rowObjects;
|
||||||
|
private Hashtable<Object, NodeState>
|
||||||
|
nodeStates;
|
||||||
|
|
||||||
|
private Hashtable<Class<?>, CellRenderer> cellRendererList;
|
||||||
|
private Hashtable<Class<?>, CellEditor> cellEditorList;
|
||||||
|
|
||||||
|
private JViewport headerViewport;
|
||||||
|
private Dimension preferredSize;
|
||||||
|
|
||||||
|
private List<TreeTablePopupListener> popupListener;
|
||||||
|
private List<TreeTableMouseListener> mouseListener;
|
||||||
|
|
||||||
|
private CellEditor activeEditor;
|
||||||
|
|
||||||
|
|
||||||
|
public TreeTable()
|
||||||
|
{
|
||||||
|
popupListener = new LinkedList<TreeTablePopupListener>();
|
||||||
|
mouseListener = new LinkedList<TreeTableMouseListener>();
|
||||||
|
|
||||||
|
preferredSize = new Dimension(1,1);
|
||||||
|
|
||||||
|
rowHeight = 20;
|
||||||
|
setBackground(Color.WHITE);
|
||||||
|
|
||||||
|
cellRendererList = new Hashtable<Class<?>, CellRenderer>();
|
||||||
|
cellRendererList.put(Object.class, new DefaultCellRenderer());
|
||||||
|
|
||||||
|
cellEditorList = new Hashtable<Class<?>, CellEditor>();
|
||||||
|
addCellEditor(Object.class, new DefaultCellEditor());
|
||||||
|
|
||||||
|
rowObjects = new ArrayList<Object>();
|
||||||
|
nodeStates = new Hashtable<Object, TreeTable.NodeState>();
|
||||||
|
setModel(new DefaultTreeTableModel());
|
||||||
|
|
||||||
|
addMouseListener(new MouseListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseReleased(MouseEvent e) {
|
||||||
|
if (e.isPopupTrigger())
|
||||||
|
firePopupRequestedFromMouseEvent(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent e) {
|
||||||
|
if (e.isPopupTrigger())
|
||||||
|
firePopupRequestedFromMouseEvent(e);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseExited(MouseEvent e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseEntered(MouseEvent e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
int row,column;
|
||||||
|
|
||||||
|
row = e.getY() / rowHeight;
|
||||||
|
column = columnModel.getColumnAtX(e.getX());
|
||||||
|
|
||||||
|
TreeTable.this.mouseClicked(e.getX(), e.getY(), e.getClickCount(), row, column);
|
||||||
|
|
||||||
|
if (e.isPopupTrigger())
|
||||||
|
firePopupRequestedFromMouseEvent(e);
|
||||||
|
else
|
||||||
|
fireMouseClicked(e);
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
prepareWidth();
|
||||||
|
prepareHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Point mouseToCell(int x,int y)
|
||||||
|
{
|
||||||
|
Point p = new Point();
|
||||||
|
p.x = columnModel.getColumnAtX(x);
|
||||||
|
p.y = y / rowHeight;
|
||||||
|
|
||||||
|
if ((p.x >= columnModel.getColumnCount()) || (p.y >= rowObjects.size()))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getRowObject(int row)
|
||||||
|
{
|
||||||
|
return this.rowObjects.get(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
private CellRenderer findCellRenderer(Class<?> clazz)
|
||||||
|
{
|
||||||
|
if (clazz == null)
|
||||||
|
return new DefaultCellRenderer();
|
||||||
|
if (cellRendererList.containsKey(clazz))
|
||||||
|
return cellRendererList.get(clazz);
|
||||||
|
if (clazz.getSuperclass()!=null)
|
||||||
|
return findCellRenderer(clazz.getSuperclass());
|
||||||
|
return new DefaultCellRenderer();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addCellEditor(Class<?> clazz,CellEditor editor)
|
||||||
|
{
|
||||||
|
editor.addCellEditorListener(this);
|
||||||
|
cellEditorList.put(clazz,editor);
|
||||||
|
}
|
||||||
|
|
||||||
|
private CellEditor findCellEditor(Class<?> clazz)
|
||||||
|
{
|
||||||
|
if (clazz == null)
|
||||||
|
return null;
|
||||||
|
if (cellEditorList.containsKey(clazz))
|
||||||
|
return cellEditorList.get(clazz);
|
||||||
|
|
||||||
|
return cellEditorList.get(Object.class);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void mouseClicked(int x,int y,int clickCount,int row,int column)
|
||||||
|
{
|
||||||
|
System.err.println("Click: " + x + "/" + y + " ( " + row + " : " + column + " )");
|
||||||
|
if (clickCount == 1)
|
||||||
|
{
|
||||||
|
if (column == 0)
|
||||||
|
{
|
||||||
|
if (x < rowHeight)
|
||||||
|
{
|
||||||
|
NodeState state = getState(rowObjects.get(row));
|
||||||
|
setOpened(rowObjects.get(row), !state.opened);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void prepareWidth()
|
||||||
|
{
|
||||||
|
preferredSize.width = columnModel.getColumnPos(columnModel.getColumnCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void prepareHeight()
|
||||||
|
{
|
||||||
|
prepareRows();
|
||||||
|
preferredSize.height = rowHeight * rowObjects.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void prepareRow(Object row)
|
||||||
|
{
|
||||||
|
if (row!=null)
|
||||||
|
{
|
||||||
|
int ind = getState(row).indentation;
|
||||||
|
|
||||||
|
rowObjects.add(row);
|
||||||
|
if (model.getChildCount(row)>0)
|
||||||
|
{
|
||||||
|
if (getState(row).isOpened())
|
||||||
|
{
|
||||||
|
for (int i=0;i<model.getChildCount(row);i++)
|
||||||
|
{
|
||||||
|
Object child = model.getChild(row, i);
|
||||||
|
getState(child).indentation = ind + 1 ;
|
||||||
|
prepareRow( child );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void prepareRows()
|
||||||
|
{
|
||||||
|
if (rowObjects == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
rowObjects.clear();
|
||||||
|
|
||||||
|
if (model.getRoot()!=null)
|
||||||
|
{
|
||||||
|
getState(model.getRoot()).indentation = 0;
|
||||||
|
prepareRow(model.getRoot());
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private NodeState getState(Object node)
|
||||||
|
{
|
||||||
|
if (!nodeStates.containsKey(node))
|
||||||
|
nodeStates.put(node, new NodeState());
|
||||||
|
return nodeStates.get(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Rectangle getCellRect(int row,int column)
|
||||||
|
{
|
||||||
|
int left = columnModel.getColumnPos(column);
|
||||||
|
int width = columnModel.getColumnWidth(column);
|
||||||
|
int top = rowHeight * row;
|
||||||
|
|
||||||
|
return new Rectangle(left, top, width, rowHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paint(Graphics g) {
|
||||||
|
prepareRows();
|
||||||
|
|
||||||
|
g.setColor(getBackground());
|
||||||
|
g.fillRect(0, 0, getWidth(), getHeight());
|
||||||
|
|
||||||
|
for (int i=0;i<rowObjects.size();i++)
|
||||||
|
{
|
||||||
|
Object ro = rowObjects.get(i);
|
||||||
|
NodeState state = getState(ro);
|
||||||
|
int top = rowHeight * i;
|
||||||
|
int bottom = top + rowHeight - 1;
|
||||||
|
|
||||||
|
g.setColor(Color.black);
|
||||||
|
g.drawLine(0, bottom, getWidth(), bottom);
|
||||||
|
|
||||||
|
for (int column = 0; column < columnModel.getColumnCount(); column++)
|
||||||
|
{
|
||||||
|
int left = columnModel.getColumnPos(column);
|
||||||
|
int width = columnModel.getColumnWidth(column);
|
||||||
|
int right = left + width - 1;
|
||||||
|
|
||||||
|
g.drawLine(right , top, right, bottom);
|
||||||
|
|
||||||
|
|
||||||
|
if (column==0)
|
||||||
|
{
|
||||||
|
int a = rowHeight / 4;
|
||||||
|
int b = rowHeight / 2;
|
||||||
|
|
||||||
|
left += state.indentation * 5;
|
||||||
|
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
|
||||||
|
if (model.getChildCount(ro)>0)
|
||||||
|
{
|
||||||
|
if (!state.isOpened())
|
||||||
|
{
|
||||||
|
g.drawPolygon(new Triangle(left + a, top + a, left + b, top + b, left + a, bottom - a));
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
g.drawPolygon(new Triangle(left + a, top + b, left + a + b, top + b, left + b, bottom - a ));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
left += rowHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
g.setColor(getForeground());
|
||||||
|
|
||||||
|
Object value = model.getValue(ro, columnModel.getColumnModelColumn(column));
|
||||||
|
CellRenderer renderer = columnModel.getColumnCellRenderer(column);
|
||||||
|
|
||||||
|
if (renderer == null)
|
||||||
|
if (value != null)
|
||||||
|
renderer = findCellRenderer(value.getClass());
|
||||||
|
else
|
||||||
|
renderer = findCellRenderer(null);
|
||||||
|
|
||||||
|
Rectangle rect = new Rectangle(left, top, width, rowHeight);
|
||||||
|
|
||||||
|
Rectangle clipRestore = g.getClipBounds();
|
||||||
|
|
||||||
|
if (clipRestore.intersects(rect))
|
||||||
|
{
|
||||||
|
Rectangle rectClip = clipRestore.intersection(rect);
|
||||||
|
|
||||||
|
g.setClip(rectClip);
|
||||||
|
renderer.renderCell(g, i, column, rect, value, ro);
|
||||||
|
g.setClip(clipRestore);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void firePopupRequestedFromMouseEvent(MouseEvent event)
|
||||||
|
{
|
||||||
|
Point p = mouseToCell(event.getX(), event.getY());
|
||||||
|
TreeTablePopupArgs args = new TreeTablePopupArgs(this, p.y,p.x, event.getX(), event.getY());
|
||||||
|
firePopupRequested(args);
|
||||||
|
}
|
||||||
|
private void firePopupRequested(TreeTablePopupArgs args)
|
||||||
|
{
|
||||||
|
TreeTablePopupListener listener = columnModel.getPopup(args.getRow(), args.getColumn());
|
||||||
|
if (listener != null)
|
||||||
|
listener.popupRequest(args);
|
||||||
|
else
|
||||||
|
for (TreeTablePopupListener l:popupListener)
|
||||||
|
l.popupRequest(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addPopupListener(TreeTablePopupListener listener)
|
||||||
|
{
|
||||||
|
popupListener.add(listener);
|
||||||
|
}
|
||||||
|
public void removePopupListener(TreeTablePopupListener listener)
|
||||||
|
{
|
||||||
|
popupListener.remove(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fireMouseClicked(MouseEvent event)
|
||||||
|
{
|
||||||
|
TreeTableMouseArgs args = new TreeTableMouseArgs(this,event);
|
||||||
|
|
||||||
|
if (args.getMouseEvent().getClickCount()==2)
|
||||||
|
{
|
||||||
|
if (args.getRowObject() != null)
|
||||||
|
{
|
||||||
|
startEditor(args.getRow(),args.getColumn());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (TreeTableMouseListener listener:mouseListener)
|
||||||
|
listener.mouseClicked(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addMouseListener(TreeTableMouseListener listener)
|
||||||
|
{
|
||||||
|
mouseListener.add(listener);
|
||||||
|
}
|
||||||
|
public void removeMouseListener(TreeTableMouseListener listener)
|
||||||
|
{
|
||||||
|
mouseListener.remove(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dimension getPreferredScrollableViewportSize() {
|
||||||
|
return getPreferredSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getScrollableBlockIncrement(Rectangle visibleRect,
|
||||||
|
int orientation, int direction) {
|
||||||
|
if (orientation == SwingConstants.HORIZONTAL)
|
||||||
|
return visibleRect.width / 2;
|
||||||
|
else
|
||||||
|
return visibleRect.height / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getScrollableTracksViewportHeight() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getScrollableTracksViewportWidth() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getScrollableUnitIncrement(Rectangle visibleRect,
|
||||||
|
int orientation, int direction) {
|
||||||
|
if (orientation == SwingConstants.HORIZONTAL)
|
||||||
|
return 10;
|
||||||
|
else
|
||||||
|
return rowHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TreeTableModel getModel() {
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultTreeTableModel getDefaultModel()
|
||||||
|
{
|
||||||
|
return (DefaultTreeTableModel)model;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setModel(TreeTableModel model) {
|
||||||
|
|
||||||
|
if (this.model != null)
|
||||||
|
this.model.removeTreeTableModelListener(this);
|
||||||
|
|
||||||
|
rowObjects.clear();
|
||||||
|
nodeStates.clear();
|
||||||
|
|
||||||
|
this.model = model;
|
||||||
|
this.model.addTreeTableModelListener(this);
|
||||||
|
|
||||||
|
TreeTableColumnModel cm = model.getDefaultColumnModel();
|
||||||
|
if (cm != null)
|
||||||
|
setColumnModel(cm);
|
||||||
|
|
||||||
|
prepareRows();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRowHeight() {
|
||||||
|
return rowHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRowHeight(int rowHeight) {
|
||||||
|
this.rowHeight = rowHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setOpened(Object node,boolean opened)
|
||||||
|
{
|
||||||
|
getState(node).opened = opened;
|
||||||
|
prepareHeight();
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
public TreeTableColumnModel getColumnModel() {
|
||||||
|
return columnModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColumnModel(TreeTableColumnModel columnModel) {
|
||||||
|
if (this.columnModel != null)
|
||||||
|
this.columnModel.removeTreeTableModelListener(this);
|
||||||
|
this.columnModel = columnModel;
|
||||||
|
|
||||||
|
this.columnModel.addTreeTableModelListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void columnsChanged() {
|
||||||
|
buildHeader();
|
||||||
|
prepareWidth();
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void rowsChanged() {
|
||||||
|
prepareHeight();
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void repaint() {
|
||||||
|
invalidate();
|
||||||
|
|
||||||
|
if (getParent()!=null)
|
||||||
|
getParent().validate();
|
||||||
|
|
||||||
|
super.repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buildHeader()
|
||||||
|
{
|
||||||
|
if (headerViewport == null)
|
||||||
|
headerViewport = new JViewport();
|
||||||
|
|
||||||
|
headerViewport.removeAll();
|
||||||
|
|
||||||
|
HeaderView hv = new HeaderView();
|
||||||
|
hv.setSize(columnModel.getColumnPos(columnModel.getColumnCount()),24);
|
||||||
|
hv.setPreferredSize(new Dimension(columnModel.getColumnPos(columnModel.getColumnCount()),24));
|
||||||
|
headerViewport.setView(hv);
|
||||||
|
}
|
||||||
|
|
||||||
|
private JViewport getHeaderViewport()
|
||||||
|
{
|
||||||
|
if (headerViewport == null)
|
||||||
|
buildHeader();
|
||||||
|
return headerViewport;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void configureEnclosingScrollPane()
|
||||||
|
{
|
||||||
|
prepareWidth();
|
||||||
|
prepareHeight();
|
||||||
|
|
||||||
|
if (JViewport.class.isInstance(getParent()) && JScrollPane.class.isInstance(getParent().getParent()))
|
||||||
|
{
|
||||||
|
JScrollPane sp = (JScrollPane)getParent().getParent();
|
||||||
|
sp.setColumnHeader(getHeaderViewport());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addNotify() {
|
||||||
|
configureEnclosingScrollPane();
|
||||||
|
super.addNotify();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeNotify() {
|
||||||
|
super.removeNotify();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dimension getPreferredSize() {
|
||||||
|
return preferredSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void cancelEditor()
|
||||||
|
{
|
||||||
|
if (activeEditor != null)
|
||||||
|
{
|
||||||
|
activeEditor.editCancel();
|
||||||
|
activeEditor = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startEditor(int row,int column)
|
||||||
|
{
|
||||||
|
if (activeEditor != null)
|
||||||
|
cancelEditor();
|
||||||
|
|
||||||
|
Object value = getModel().getValue(rowObjects.get(row), column);
|
||||||
|
|
||||||
|
activeEditor = findCellEditor(value.getClass());
|
||||||
|
|
||||||
|
if (activeEditor != null)
|
||||||
|
{
|
||||||
|
activeEditor.editBegin(this, getCellRect(row, column), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void editBegin(CellEditorArgs args) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void editCanceled(CellEditorArgs args) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void editFinished(CellEditorArgs args) {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package org.hwo.ui.treetable;
|
||||||
|
|
||||||
|
import org.hwo.ui.CellRenderer;
|
||||||
|
|
||||||
|
public interface TreeTableColumnModel {
|
||||||
|
|
||||||
|
public void addTreeTableModelListener(TreeTableModelListener listener);
|
||||||
|
public void removeTreeTableModelListener(TreeTableModelListener listener);
|
||||||
|
|
||||||
|
public int getColumnCount();
|
||||||
|
public String getColumnLabel(int column);
|
||||||
|
public int getColumnWidth(int column);
|
||||||
|
|
||||||
|
public int getColumnPos(int column);
|
||||||
|
|
||||||
|
public int getColumnAtX(int x);
|
||||||
|
|
||||||
|
public int getColumnModelColumn(int x);
|
||||||
|
|
||||||
|
public CellRenderer
|
||||||
|
getColumnCellRenderer(int column);
|
||||||
|
|
||||||
|
public TreeTablePopupListener
|
||||||
|
getPopup(int row,int column);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package org.hwo.ui.treetable;
|
||||||
|
|
||||||
|
public interface TreeTableElement {
|
||||||
|
|
||||||
|
public TreeTableElement
|
||||||
|
getParent();
|
||||||
|
|
||||||
|
public Object getValue(int column);
|
||||||
|
|
||||||
|
public int getChildCount();
|
||||||
|
public TreeTableElement
|
||||||
|
getChild(int index);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package org.hwo.ui.treetable;
|
||||||
|
|
||||||
|
public interface TreeTableModel {
|
||||||
|
|
||||||
|
public void addTreeTableModelListener(TreeTableModelListener listener);
|
||||||
|
public void removeTreeTableModelListener(TreeTableModelListener listener);
|
||||||
|
|
||||||
|
public Object getParent(Object node);
|
||||||
|
|
||||||
|
public int getChildCount(Object parent);
|
||||||
|
public Object getChild(Object parent,int index);
|
||||||
|
|
||||||
|
public Object getRoot();
|
||||||
|
|
||||||
|
public boolean isLeaf(Object node);
|
||||||
|
|
||||||
|
public Object getValue(Object node,int column);
|
||||||
|
|
||||||
|
public TreeTableColumnModel
|
||||||
|
getDefaultColumnModel();
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package org.hwo.ui.treetable;
|
||||||
|
|
||||||
|
public interface TreeTableModelListener {
|
||||||
|
|
||||||
|
public void columnsChanged();
|
||||||
|
public void rowsChanged();
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
package org.hwo.ui.treetable;
|
||||||
|
|
||||||
|
import java.awt.Point;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
|
||||||
|
public class TreeTableMouseArgs {
|
||||||
|
|
||||||
|
private MouseEvent mouseEvent;
|
||||||
|
private int row, column;
|
||||||
|
private TreeTable treeTable;
|
||||||
|
|
||||||
|
private Object rowObject;
|
||||||
|
|
||||||
|
|
||||||
|
public TreeTableMouseArgs(TreeTable treeTable,MouseEvent event)
|
||||||
|
{
|
||||||
|
this.treeTable = treeTable;
|
||||||
|
mouseEvent = event;
|
||||||
|
|
||||||
|
Point p = treeTable.mouseToCell(event.getX(), event.getY());
|
||||||
|
|
||||||
|
row = p.y;
|
||||||
|
column = p.x;
|
||||||
|
|
||||||
|
rowObject = treeTable.getRowObject(row);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public MouseEvent getMouseEvent() {
|
||||||
|
return mouseEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMouseEvent(MouseEvent mouseEvent) {
|
||||||
|
this.mouseEvent = mouseEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRow() {
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRow(int row) {
|
||||||
|
this.row = row;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getColumn() {
|
||||||
|
return column;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColumn(int column) {
|
||||||
|
this.column = column;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TreeTable getTreeTable() {
|
||||||
|
return treeTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTreeTable(TreeTable treeTable) {
|
||||||
|
this.treeTable = treeTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getRowObject() {
|
||||||
|
return rowObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRowObject(Object rowObject) {
|
||||||
|
this.rowObject = rowObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package org.hwo.ui.treetable;
|
||||||
|
|
||||||
|
public interface TreeTableMouseListener {
|
||||||
|
|
||||||
|
public void mouseClicked(TreeTableMouseArgs args);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
package org.hwo.ui.treetable;
|
||||||
|
|
||||||
|
public class TreeTablePopupArgs {
|
||||||
|
|
||||||
|
private TreeTable treeTable;
|
||||||
|
private int row,
|
||||||
|
column;
|
||||||
|
private int mouseX,
|
||||||
|
mouseY;
|
||||||
|
|
||||||
|
public TreeTablePopupArgs(TreeTable treeTable,int row,int column,int x,int y)
|
||||||
|
{
|
||||||
|
this.setTreeTable(treeTable);
|
||||||
|
this.setRow(row);
|
||||||
|
this.setColumn(column);
|
||||||
|
this.setMouseX(x);
|
||||||
|
this.setMouseY(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getColumn() {
|
||||||
|
return column;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColumn(int column) {
|
||||||
|
this.column = column;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TreeTable getTreeTable() {
|
||||||
|
return treeTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTreeTable(TreeTable treeTable) {
|
||||||
|
this.treeTable = treeTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRow() {
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRow(int row) {
|
||||||
|
this.row = row;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMouseX() {
|
||||||
|
return mouseX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMouseX(int mouseX) {
|
||||||
|
this.mouseX = mouseX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMouseY() {
|
||||||
|
return mouseY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMouseY(int mouseY) {
|
||||||
|
this.mouseY = mouseY;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package org.hwo.ui.treetable;
|
||||||
|
|
||||||
|
public interface TreeTablePopupListener {
|
||||||
|
|
||||||
|
public void popupRequest(TreeTablePopupArgs args);
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue