Commit a4f4985d authored by Frank Bergmann's avatar Frank Bergmann

Initial Import

parents
Pipeline #1010 failed with stages
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="build/classes"/>
</classpath>
nbproject
doc
.settings
build
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>PO-Timesheet</name>
<comment>
]project-open[ Time Sheet is a light weight desktop time sheet
logging application written in Java. ]po[ Time Sheet is designed
to work with the ]project-open[ project management on the server
side for managing the project hierarchy, advanced reporting,
billing and financials.
</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.jem.beaninfo.BeanInfoNature</nature>
</natures>
</projectDescription>
Copyright 2005 Sun Microsystems, Inc. ALL RIGHTS RESERVED
Use of this software is authorized pursuant to the terms
of the license found at
http://developers.sun.com/berkeley_license.html
Code Sample License
Copyright 1994-2005 Sun Microsystems, Inc.
All Rights Reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided
that the following conditions are met:
Redistribution of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
Redistribution in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
Neither the name of Sun Microsystems, Inc. or the
names of contributors may be used to endorse or
promote products derived from this software
without specific prior written permission.
This software is provided "AS IS," without a warranty
of any kind. ALL EXPRESS OR IMPLIED CONDITIONS,
REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED
WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT
BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A
RESULT OF USING, MODIFYING OR DISTRIBUTING THIS
SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE,
PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES,
HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
LIABILITY, ARISING OUT OF THE USE OF OR INABILITY
TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED
OF THE POSSIBILITY OF SUCH DAMAGES.
You acknowledge that this software is not designed,
licensed or intended for use in the design,
construction, operation or maintenance of any
nuclear facility.
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<project name="SystemTrayExample" default="default" basedir=".">
<description>Builds, tests, and runs the project PO-Timesheet.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar-with-manifest: JAR building (if you are using a manifest)
-do-jar-without-manifest: JAR building (if you are not using a manifest)
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="SystemTrayExample-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->
</project>
#--- User account to access ]project-open[ server ---
#Fri May 21 16:01:37 CEST 2010
port=
password=ben
email=bbigboss@tigerpond.com
server=http\://po34demo.project-open.net
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build
po-icon.gif

151 Bytes

package org.projectopen.timesheet;
/*
* Copyright (C) 2010 ]project-open[
*
* This program is free software. You can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software Foundation;
* either version 2 of the License, or (at your option)
* any later version. This program is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* @author Frank Bergmann (frank.bergmann@project-open.com)
*/
import java.awt.GridBagLayout;
import javax.swing.JPanel;
import javax.swing.JButton;
import java.awt.GridBagConstraints;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import org.w3c.dom.Document;
/*
* A GUI panel to configure the connection parameters
* of for the REST Web Service:
* server, port, email and password.
*/
public class ConfigPanel extends JPanel {
private static final long serialVersionUID = 1L;
private JLabel emailLabel = null;
private JTextField emailTextField = null;
private JLabel serverLabel = null;
private JTextField serverTextField = null;
private JLabel passwordLabel = null;
private JPasswordField passwordPasswordField = null;
private JButton testButton = null;
private JPanel buttonPanel = null;
private JButton saveButton = null;
private JLabel emptyLabel = null;
private URL url;
private JLabel statusLabel = null;
private JTextField statusTextField = null;
public String getServer() {
return serverTextField.getText();
}
public String getEmail() {
return emailTextField.getText();
}
@SuppressWarnings("deprecation")
public String getPassword() {
return passwordPasswordField.getText();
}
/**
* This method initializes emailTextField
*
* @return javax.swing.JTextField
*/
private JTextField getEmailTextField() {
if (emailTextField == null) {
emailTextField = new JTextField();
emailTextField.setText(SystemTrayTest.getEmail());
emailTextField.setHorizontalAlignment(JTextField.LEFT);
emailTextField.setPreferredSize(new Dimension(200, 20));
}
return emailTextField;
}
/**
* This method initializes serverTextField
*
* @return javax.swing.JTextField
*/
private JTextField getServerTextField() {
if (serverTextField == null) {
serverTextField = new JTextField();
serverTextField.setPreferredSize(new Dimension(200, 20));
serverTextField.setText(SystemTrayTest.getServer());
}
return serverTextField;
}
/**
* This method initializes passwordPasswordField
*
* @return javax.swing.JPasswordField
*/
private JPasswordField getPasswordPasswordField() {
if (passwordPasswordField == null) {
passwordPasswordField = new JPasswordField();
passwordPasswordField.setPreferredSize(new Dimension(200, 20));
passwordPasswordField.setText("ben");
}
return passwordPasswordField;
}
/**
* This method initializes testButton
*
* @return javax.swing.JButton
*/
private JButton getTestButton() {
if (testButton == null) {
// Test the connection
ActionListener testButtonListener = new ActionListener() {
@SuppressWarnings("deprecation")
public void actionPerformed(ActionEvent e) {
System.out.println("TestButton pressed...");
try {
url = new URL(serverTextField.getText() + "/intranet-rest/index");
} catch (Exception x) { System.err.println(x); }
// boolean quiet, String method, URL url, String username, String password, InputStream body
Document dom = null;
try {
dom = RESTClient.request(
true, new String("GET"), url, emailTextField.getText(), passwordPasswordField.getText() , null
);
} catch (Exception x) { System.err.println(x); }
if (dom != null) {
statusLabel.setText("Status");
statusTextField.setText("Successfully Connected");
statusTextField.setVisible(true);
}
}
};
testButton = new JButton();
testButton.setText("Test Connection");
testButton.addActionListener(testButtonListener);
}
return testButton;
}
/**
* This method initializes buttonPanel
*
* @return javax.swing.JPanel
*/
private JPanel getButtonPanel() {
if (buttonPanel == null) {
GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
gridBagConstraints1.gridx = -1;
gridBagConstraints1.gridy = -1;
GridBagConstraints gridBagConstraints10 = new GridBagConstraints();
gridBagConstraints10.gridx = -1;
gridBagConstraints10.anchor = GridBagConstraints.WEST;
gridBagConstraints10.gridy = -1;
buttonPanel = new JPanel();
buttonPanel.setLayout(new GridBagLayout());
buttonPanel.add(getTestButton(), gridBagConstraints10);
buttonPanel.add(getSaveButton(), gridBagConstraints1);
}
return buttonPanel;
}
/**
* This method initializes saveButton
*
* @return javax.swing.JButton
*/
private JButton getSaveButton() {
if (saveButton == null) {
// Save the new parameters
ActionListener saveButtonListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("SaveButton pressed...");
}
};
saveButton = new JButton();
saveButton.setText("Save");
saveButton.addActionListener(saveButtonListener);
}
return saveButton;
}
/**
* This method initializes statusTextField
*
* @return javax.swing.JTextField
*/
private JTextField getStatusTextField() {
if (statusTextField == null) {
statusTextField = new JTextField();
statusTextField.setPreferredSize(new Dimension(200, 20));
statusTextField.setEnabled(false);
statusTextField.setText("untested");
statusTextField.setVisible(true);
}
return statusTextField;
}
/**
* This is the default constructor
*/
public ConfigPanel(SystemTrayTest p) {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
gridBagConstraints3.fill = GridBagConstraints.VERTICAL;
gridBagConstraints3.gridy = 4;
gridBagConstraints3.weightx = 1.0;
gridBagConstraints3.anchor = GridBagConstraints.WEST;
gridBagConstraints3.gridx = 1;
GridBagConstraints gridBagConstraints12 = new GridBagConstraints();
gridBagConstraints12.gridx = 0;
gridBagConstraints12.anchor = GridBagConstraints.EAST;
gridBagConstraints12.gridy = 4;
statusLabel = new JLabel();
statusLabel.setText("Status");
statusLabel.setEnabled(false);
statusLabel.setVisible(true);
GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
gridBagConstraints11.gridx = 0;
gridBagConstraints11.gridy = 0;
emptyLabel = new JLabel();
emptyLabel.setText("");
GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.anchor = GridBagConstraints.WEST;
gridBagConstraints.gridy = 5;
GridBagConstraints gridBagConstraints9 = new GridBagConstraints();
gridBagConstraints9.fill = GridBagConstraints.VERTICAL;
gridBagConstraints9.gridy = 3;
gridBagConstraints9.weightx = 1.0;
gridBagConstraints9.anchor = GridBagConstraints.WEST;
gridBagConstraints9.gridx = 1;
GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
gridBagConstraints8.gridx = 0;
gridBagConstraints8.anchor = GridBagConstraints.EAST;
gridBagConstraints8.gridy = 3;
passwordLabel = new JLabel();
passwordLabel.setText("Password");
GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
gridBagConstraints7.fill = GridBagConstraints.VERTICAL;
gridBagConstraints7.gridy = 1;
gridBagConstraints7.weightx = 1.0;
gridBagConstraints7.anchor = GridBagConstraints.WEST;
gridBagConstraints7.gridx = 1;
GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
gridBagConstraints6.gridx = 0;
gridBagConstraints6.anchor = GridBagConstraints.EAST;
gridBagConstraints6.gridy = 1;
serverLabel = new JLabel();
serverLabel.setText("Server");
GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
gridBagConstraints5.fill = GridBagConstraints.VERTICAL;
gridBagConstraints5.gridy = 2;
gridBagConstraints5.weightx = 1.0;
gridBagConstraints5.anchor = GridBagConstraints.WEST;
gridBagConstraints5.gridx = 1;
GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
gridBagConstraints4.gridx = 0;
gridBagConstraints4.anchor = GridBagConstraints.EAST;
gridBagConstraints4.gridy = 2;
emailLabel = new JLabel();
emailLabel.setText("Email ");
this.setSize(328, 154);
this.setLayout(new GridBagLayout());
this.add(emailLabel, gridBagConstraints4);
this.add(getEmailTextField(), gridBagConstraints5);
this.add(serverLabel, gridBagConstraints6);
this.add(getServerTextField(), gridBagConstraints7);
this.add(passwordLabel, gridBagConstraints8);
this.add(getPasswordPasswordField(), gridBagConstraints9);
this.add(getButtonPanel(), gridBagConstraints);
this.add(emptyLabel, gridBagConstraints11);
this.add(statusLabel, gridBagConstraints12);
this.add(getStatusTextField(), gridBagConstraints3);
}
} // @jve:decl-index=0:visual-constraint="10,10"
package org.projectopen.timesheet;
/*
* Copyright (C) 2010 ]project-open[
*
* This program is free software. You can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software Foundation;
* either version 2 of the License, or (at your option)
* any later version. This program is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* @author Frank Bergmann (frank.bergmann@project-open.com)
*
*/
import java.io.*;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
import com.sun.org.apache.xerces.internal.parsers.DOMParser;
/**
* Simple XML Document printer.
* This class is used to debug the replies from the
* ]po[ REST Web Service.
*
* @autor Frank Bergmann <frank.bergmann@project-open.com>
*/
public class DomPrinter
{
boolean validation = true;
DOMParser myDOMParser;
String xmlFile = null;
InputStream stream = null;
Document doc;
public DomPrinter(String fileName) { xmlFile = fileName; }
public DomPrinter(InputStream s) { stream = s; }
/**
* Print out the contents of an correctly initialized
* DomPrinter.
*
* However, to print out an Element it's easier to use
* the static walk() method below.
*/
public void print()
{
try {
myDOMParser = (DOMParser) new DOMParser();
//To validate or not
myDOMParser.setFeature( "http://xml.org/sax/features/validation", validation);
if (xmlFile != null) {
myDOMParser.parse(xmlFile);
} else {
InputSource source = new InputSource (stream);
myDOMParser.parse(source);
}
doc = myDOMParser.getDocument();
walk(doc);
}
catch(Exception e) { System.out.println("Errors " + e); }
}
/**
* Walk the DOM tree and print as you go
* @param node
*/
public static void walk(Node node)
{
if (node == null) { return; }
int type = node.getNodeType();
switch(type) {
case Node.DOCUMENT_NODE: {
System.out.println("<?xml version=\"1.0\" encoding=\"" + "UTF-8" + "\"?>");
break;
}
case Node.ELEMENT_NODE: {
System.out.print('<' + node.getNodeName() );
NamedNodeMap nnm = node.getAttributes();
if(nnm != null ) {
int len = nnm.getLength() ;
Attr attr;
for ( int i = 0; i < len; i++ ) {
attr = (Attr)nnm.item(i);
System.out.print(' ' + attr.getNodeName() + "=\"" + attr.getNodeValue() + '"' );
}
}
System.out.print('>');
break;
}
case Node.ENTITY_REFERENCE_NODE: {
System.out.print('&' + node.getNodeName() + ';' );
break;
}
case Node.CDATA_SECTION_NODE: {
System.out.print( "<![CDATA[" + node.getNodeValue() + "]]>" );
break;
}
case Node.TEXT_NODE: {
System.out.print(node.getNodeValue());
break;
}
case Node.PROCESSING_INSTRUCTION_NODE: {
System.out.print("<?" + node.getNodeName());
String data = node.getNodeValue();
if ( data != null && data.length() > 0 ) {
System.out.print(' ');
System.out.print(data);
}
System.out.println("?>");
break;
}
}
// recurse
for(Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
walk(child);
}
// without this the ending tags will miss
if ( type == Node.ELEMENT_NODE ) {
System.out.print("</" + node.getNodeName() + ">");
}
}
}
\ No newline at end of file
package org.projectopen.timesheet;
/*
* Copyright (C) 2010 ]project-open[
*
* This program is free software. You can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software Foundation;
* either version 2 of the License, or (at your option)
* any later version. This program is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* @author Frank Bergmann (frank.bergmann@project-open.com)
*/
import java.awt.Component;
import java.text.NumberFormat;
import java.util.Locale;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
/**
*
* Slightly customized TableCellRenderer that prints out
* numbers right-aligned and with US-American locale format,
* to be consistent with the ]project-open[ Web application.
*
* @author Frank Bergmann
*
*/
public class NumberRenderer extends DefaultTableCellRenderer {
private static final long serialVersionUID = -4523810862313323910L;
NumberFormat formatter;
public NumberRenderer() {
super();
}
/*
* Modify the formatting rules to use a US American locale
*/
public void setValue(Object value) {
// formatter = null;
if (formatter==null) {
formatter = NumberFormat.getInstance(Locale.US);
formatter.setMinimumFractionDigits(1);
}
setText((value == null) ? "" : formatter.format(value));
}
/*
* Make sure the result is right aligned
*/
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
JLabel renderedLabel = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
renderedLabel.setHorizontalAlignment(SwingConstants.RIGHT);
return renderedLabel;
}
}
\ No newline at end of file
package org.projectopen.timesheet;
/*
* Copyright (C) 2010 ]project-open[
*
* This program is free software. You can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software Foundation;
* either version 2 of the License, or (at your option)
* any later version. This program is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* @author Frank Bergmann (frank.bergmann@project-open.com)
*
*/
import java.util.Iterator;
import java.util.List;
import org.projectopen.treetable.AbstractTreeTableModel;
import org.projectopen.treetable.TreeTableModel;
@SuppressWarnings("unchecked")
/**
* Data model for JTreeTable.
* This class basically delegates getValueAt and setValueAt calls
* from the JTreeTable to the REST interface, apart from interfacing
* with the project hierarchy.
*/
public class ProjectTreeTableModel extends AbstractTreeTableModel implements TreeTableModel {
static protected String[] cNames = {"Name", "Hours", "Note"};
static protected Class[] cTypes = {TreeTableModel.class, Float.class, String.class};
public ProjectTreeTableModel() {
super(new ProjopProject());
System.out.println("ProjectTreeTableModel.ProjectTreeTableModel");
initialize();
}
private void initialize() {
System.out.println("ProjectTreeTableModel.initialize");
// create a dummy project at the top of the tree
root = new ProjopProject();
((ProjopProject)root).set("project_name", "]project-open[ Projects");
// here we will store the last parents of each level,
// in order to create a hierarchy of projects.
ProjopProject[] node = new ProjopProject[10];
node[0] = ((ProjopProject)root);
// count the level of depth of the projects.
int level;
// get the list of projects to which the current user can
// log hours.
List projects = RESTClient.projopMyTimesheetProjects();
// go through the list and add them to the project hierarchy
Iterator itr = projects.iterator();
while(itr.hasNext()) {
// get the next project
ProjopProject p = (ProjopProject) itr.next();
// Main-Projects in ]po[ have level=0, but here they are
// level=1, because the are located below the ficticous
// "]project-open[ Projects" node which occupies level=0
String levelString = p.get("level");
level = 1 + Integer.parseInt(levelString.trim());
// Set the parent as the project one above in the hierarchy
p.setParent(node[level-1]);
// set the new projectNode as the parent for the next projects..
node[level] = p;
// add this project to the list of parent's children
node[level-1].getChildProjects().add(p);
}
System.out.println("ProjectTreeTableModel.initialize end");
}
public Class getColumnClass(int column) {
return cTypes[column];
}
public int getColumnCount() {
return cTypes.length;
}
public String getColumnName(int column) {
return cNames[column];
}
public Object getValueAt(Object node, int column) {
int projectId = ((ProjopProject)node).getObjectId();
ProjopHour h = RESTClient.projopMyHours(projectId);
switch(column) {
case 0: {
// return a string with the name of the project.
if (projectId == 0) { return ""; }
return node.toString();
}
case 1: {
// return the number of hours logged
if (h != null) {
String hoursString = h.get("hours");
if ("" != hoursString) {
return new Double(hoursString);
}
}
return null;
}
case 2: {
if (h != null) {
return h.get("note");
}
return null;
}
}
return null;
}
public void setValueAt(Object aValue, Object node, int column) {
int projectId = ((ProjopProject)node).getObjectId();
if (projectId == 0) { return; }
switch(column) {
case 0: {
// Don't change the project name...
break;
}
case 1: {
// store the new number of hours
RESTClient.setMyHours("hours", projectId, aValue);
break;
}
case 2: {
// store the new comment about the logged hours
if (aValue == null) { aValue = ""; }
aValue = ProjopObject.htmlEncode(aValue.toString());
RESTClient.setMyHours("note", projectId, aValue);
break;
}
}
}
@Override
public boolean isCellEditable(Object node, int column) {
switch(column) {
case 0: return true;
case 1: return true;
case 2: return true;
}
return false;
}
@Override
public Object getChild(Object parent, int index) {
Object child = ((ProjopProject) parent).getChildProjects().get(index);
return child;
}
public Object[] getChildren(Object node) {
Object[] children = ((ProjopProject)node).getChildProjects().toArray();
return children;
}
@Override
public int getChildCount(Object parent) {
int count = ((ProjopProject) parent).getChildProjects().size();
return count;
}
public boolean isLeaf(Object node) {
int count = ((ProjopProject) node).getChildProjects().size();
boolean r = (count == 0);
return r;
}
}
package org.projectopen.timesheet;
/*
* Copyright (C) 2010 ]project-open[
*
* This program is free software. You can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software Foundation;
* either version 2 of the License, or (at your option)
* any later version. This program is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* @author Frank Bergmann (frank.bergmann@project-open.com)
*
*/
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class ProjopHour extends ProjopObject {
public ProjopHour() {
super("im_hour");
}
/*
* Create a new Hour from a list of MyHours report:
* <row>
* <hour_id>45624</hour_id>
* <user_id>625</Hour_name>
* <project_id>12345</level>
* <day>2010-01-01</Hour_type>
* </row>
*/
public static ProjopHour hourFromMyHoursXML (Element hourEl) {
//Create a new object
ProjopHour h = new ProjopHour();
int hourId = getIntValue(hourEl,"hour_id");
h.setObjectId(hourId);
// Iterate through the list of <row> entries,
// adding the data to the list of projects.
NodeList nl = hourEl.getChildNodes();
if(nl != null && nl.getLength() > 0) {
for(int i = 0 ; i < nl.getLength();i++) {
Node el = (Node)nl.item(i);
int type = el.getNodeType();
// skip everything except for element nodes ("real" nodes).
if (type != Node.ELEMENT_NODE) { continue; }
String value = el.getTextContent();
String name = el.getNodeName();
h.set(name, value);
}
}
return h;
}
}
package org.projectopen.timesheet;
/*
* Copyright (C) 2010 ]project-open[
*
* This program is free software. You can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software Foundation;
* either version 2 of the License, or (at your option)
* any later version. This program is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* @author Frank Bergmann (frank.bergmann@project-open.com)
*
*/
import java.util.Hashtable;
import java.util.Enumeration;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
@SuppressWarnings("unchecked")
/*
* A ProjopObject mainly consists of a lists of variables
*/
public class ProjopObject {
private String objectType;
private int objectId;
private Hashtable vars;
public static int getIntValue(Element ele, String tagName) {
//in production application you would catch the exception
return Integer.parseInt(getTextValue(ele,tagName));
}
public static ProjopObject objectFromXML(Element el) {
return null;
}
public String toXMLString() {
StringBuffer buf = new StringBuffer();
Enumeration e = vars.keys();
while(e.hasMoreElements()){
Object var = e.nextElement();
buf.append("<"+var.toString()+">"+vars.get(var)+"</"+var.toString()+">\n");
}
String result = "<" + objectType + ">\n" + buf + "\n</" + objectType + ">\n";
return result;
}
public static String getTextValue(Element ele, String tagName) {
String textVal = null;
NodeList nl = ele.getElementsByTagName(tagName);
if(nl != null && nl.getLength() > 0) {
Element el = (Element)nl.item(0);
textVal = el.getFirstChild().getNodeValue();
}
return textVal;
}
/*
* Small helper for working with XML in string representation
*/
public static String htmlEncode(String s) {
String result = s;
result = result.replaceAll("&", "&amp;");
result = result.replaceAll("<", "&lt;");
result = result.replaceAll(">", "&gt;");
result = result.replaceAll("\"", "&quot;");
return result;
}
public String get(String varName) { return (String)vars.get(varName); }
public void set(String varName, String value) { vars.put(varName, value); }
public String getObjectType() { return objectType; }
public int getObjectId() { return objectId; }
public void setObjectId(int objectId) { this.objectId = objectId; }
public void setObjectType(String objectType) { this.objectType = objectType; }
public Hashtable getVars() { return vars; }
public ProjopObject(String objectType) {
this.objectType = objectType;
vars = new Hashtable(20);
}
public String toString() {
return objectType + ":" + objectId + ":" + vars;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
ProjopObject o1 = new ProjopObject("im_project");
System.out.println("Retriving all keys from the Hashtable");
Enumeration e = o1.getVars().keys();
while( e.hasMoreElements() ){
System.out.println( e.nextElement() );
}
}
}
package org.projectopen.timesheet;
/*
* Copyright (C) 2010 ]project-open[
*
* This program is free software. You can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software Foundation;
* either version 2 of the License, or (at your option)
* any later version. This program is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* @author Frank Bergmann (frank.bergmann@project-open.com)
*
*/
import java.util.Collections;
import java.util.Vector;
import org.w3c.dom.Element;
@SuppressWarnings("unchecked")
public class ProjopProject extends ProjopObject implements Comparable {
private ProjopProject parentProject = null;
private Vector childProjects = new Vector();
public ProjopProject() {
super("im_project");
}
public ProjopProject getParent() {
return parentProject;
}
public void setParent(ProjopProject parentProject) {
this.parentProject = parentProject;
}
public void setChildProjects(Vector childProjects) {
this.childProjects = childProjects;
}
public Vector getChildProjects() {
Collections.sort(childProjects);
return childProjects;
}
public String toString() {
String name = get("project_name");
if (name == null) { name = super.toString(); }
return name;
}
/*
* Create a mew Project from a list of MyTimesheetProjects:
* <row>
* <project_id>45624</project_id>
* <project_name>Big Customer Mailman Issue</project_name>
* <level>1</level>
* <project_type>Ticket</project_type>
* <project_status>Open</project_status>
* </row>
* Projects are ordered in such a way that a parent is always
* returned before its children, so we can be sure that the lookup
* of the parent will be successful.
*/
public static ProjopProject projectFromMyTimesheetProjectsXML (Element el) {
String projectName = getTextValue(el,"project_name");
int projectId = getIntValue(el,"project_id");
int level = getIntValue(el,"level");
//Create a new Employee with the value read from the xml nodes
ProjopProject p = new ProjopProject();
p.setObjectId(projectId);
p.set("project_id", projectId + "");
p.set("project_name", projectName);
p.set("level", level + "");
return p;
}
public int compareTo(Object arg0) {
String projectName = this.toString();
return projectName.compareTo(arg0.toString());
}
}
package org.projectopen.timesheet;
/*
* Copyright (C) 2010 ]project-open[
*
* This program is free software. You can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software Foundation;
* either version 2 of the License, or (at your option)
* any later version. This program is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* @author Frank Bergmann (frank.bergmann@project-open.com)
*
*/
public class ProjopUser extends ProjopObject {
public ProjopUser() {
super("user");
}
public String toString() {
String name = get("username");
if (name == null) { name = super.toString(); }
return name;
}
}
This diff is collapsed.
This diff is collapsed.
package org.projectopen.treetable;
/*
* %W% %E%
*
* Copyright 1997, 1998 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* Neither the name of Sun Microsystems, Inc. or the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any
* kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
* WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
* EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY
* DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR
* RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE OR
* ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE
* FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT,
* SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
* CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF
* THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS
* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed, licensed or
* intended for use in the design, construction, operation or
* maintenance of any nuclear facility.
*/
import java.util.EventObject;
import javax.swing.CellEditor;
import javax.swing.event.CellEditorListener;
import javax.swing.event.ChangeEvent;
import javax.swing.event.EventListenerList;
/**
* A base class for CellEditors, providing default implementations for all
* methods in the CellEditor interface and support for managing a series
* of listeners.
*
* @author Philip Milne
*/
public class AbstractCellEditor implements CellEditor {
protected EventListenerList listenerList = new EventListenerList();
public Object getCellEditorValue() {
return null;
}
public boolean isCellEditable(EventObject e) { return true; }
public boolean shouldSelectCell(EventObject anEvent) { return false; }
public boolean stopCellEditing() { return true; }
public void cancelCellEditing() {}
public void addCellEditorListener(CellEditorListener l) {
listenerList.add(CellEditorListener.class, l);
}
public void removeCellEditorListener(CellEditorListener l) {
listenerList.remove(CellEditorListener.class, l);
}
/**
* Notify all listeners that have registered interest for
* notification on this event type.
* @see EventListenerList
*/
protected void fireEditingStopped() {
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==CellEditorListener.class) {
((CellEditorListener)listeners[i+1]).editingStopped(new ChangeEvent(this));
}
}
}
/**
* Notify all listeners that have registered interest for
* notification on this event type.
* @see EventListenerList
*/
protected void fireEditingCanceled() {
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==CellEditorListener.class) {
((CellEditorListener)listeners[i+1]).editingCanceled(new ChangeEvent(this));
}
}
}
}
package org.projectopen.treetable;
/*
* %W% %E%
*
* Copyright 1997, 1998 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* Neither the name of Sun Microsystems, Inc. or the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any
* kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
* WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
* EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY
* DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR
* RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE OR
* ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE
* FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT,
* SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
* CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF
* THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS
* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed, licensed or
* intended for use in the design, construction, operation or
* maintenance of any nuclear facility.
*/
import javax.swing.event.EventListenerList;
import javax.swing.event.TreeModelEvent;
import javax.swing.event.TreeModelListener;
import javax.swing.tree.TreePath;
/**
* An abstract implementation of the TreeTableModel interface, handling
* the list of listeners.
*
* @version %I% %G%
*
* @author Philip Milne
*/
public abstract class AbstractTreeTableModel implements TreeTableModel {
protected Object root;
protected EventListenerList listenerList = new EventListenerList();
public AbstractTreeTableModel(Object root) {
this.root = root;
}
public Object getRoot() {
return root;
}
public boolean isLeaf(Object node) {
return getChildCount(node) == 0;
}
public void valueForPathChanged(TreePath path, Object newValue) {}
// This is not called in the JTree's default mode: use a naive implementation.
public int getIndexOfChild(Object parent, Object child) {
for (int i = 0; i < getChildCount(parent); i++) {
if (getChild(parent, i).equals(child)) {
return i;
}
}
return -1;
}
public void addTreeModelListener(TreeModelListener l) {
listenerList.add(TreeModelListener.class, l);
}
public void removeTreeModelListener(TreeModelListener l) {
listenerList.remove(TreeModelListener.class, l);
}
/*
* Notify all listeners that have registered interest for
* notification on this event type. The event instance
* is lazily created using the parameters passed into
* the fire method.
* @see EventListenerList
*/
protected void fireTreeNodesChanged(Object source, Object[] path,
int[] childIndices,
Object[] children) {
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
TreeModelEvent e = null;
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==TreeModelListener.class) {
// Lazily create the event:
if (e == null)
e = new TreeModelEvent(source, path,
childIndices, children);
((TreeModelListener)listeners[i+1]).treeNodesChanged(e);
}
}
}
/*
* Notify all listeners that have registered interest for
* notification on this event type. The event instance
* is lazily created using the parameters passed into
* the fire method.
* @see EventListenerList
*/
protected void fireTreeNodesInserted(Object source, Object[] path,
int[] childIndices,
Object[] children) {
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
TreeModelEvent e = null;
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==TreeModelListener.class) {
// Lazily create the event:
if (e == null)
e = new TreeModelEvent(source, path,
childIndices, children);
((TreeModelListener)listeners[i+1]).treeNodesInserted(e);
}
}
}
/*
* Notify all listeners that have registered interest for
* notification on this event type. The event instance
* is lazily created using the parameters passed into
* the fire method.
* @see EventListenerList
*/
protected void fireTreeNodesRemoved(Object source, Object[] path,
int[] childIndices,
Object[] children) {
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
TreeModelEvent e = null;
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==TreeModelListener.class) {
// Lazily create the event:
if (e == null)
e = new TreeModelEvent(source, path,
childIndices, children);
((TreeModelListener)listeners[i+1]).treeNodesRemoved(e);
}
}
}
/*
* Notify all listeners that have registered interest for
* notification on this event type. The event instance
* is lazily created using the parameters passed into
* the fire method.
* @see EventListenerList
*/
protected void fireTreeStructureChanged(Object source, Object[] path,
int[] childIndices,
Object[] children) {
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
TreeModelEvent e = null;
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==TreeModelListener.class) {
// Lazily create the event:
if (e == null)
e = new TreeModelEvent(source, path,
childIndices, children);
((TreeModelListener)listeners[i+1]).treeStructureChanged(e);
}
}
}
//
// Default impelmentations for methods in the TreeTableModel interface.
//
@SuppressWarnings("unchecked")
public Class getColumnClass(int column) { return Object.class; }
/** By default, make the column with the Tree in it the only editable one.
* Making this column editable causes the JTable to forward mouse
* and keyboard events in the Tree column to the underlying JTree.
*/
public boolean isCellEditable(Object node, int column) {
return getColumnClass(column) == TreeTableModel.class;
}
public void setValueAt(Object aValue, Object node, int column) {}
// Left to be implemented in the subclass:
/*
* public Object getChild(Object parent, int index)
* public int getChildCount(Object parent)
* public int getColumnCount()
* public String getColumnName(Object node, int column)
* public Object getValueAt(Object node, int column)
*/
}
package org.projectopen.treetable;
/*
* %W% %E%
*
* Copyright 1997, 1998 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* Neither the name of Sun Microsystems, Inc. or the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any
* kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
* WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
* EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY
* DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR
* RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE OR
* ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE
* FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT,
* SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
* CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF
* THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS
* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed, licensed or
* intended for use in the design, construction, operation or
* maintenance of any nuclear facility.
*/
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.JTable;
import javax.swing.JTree;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import javax.swing.tree.DefaultTreeSelectionModel;
import javax.swing.tree.TreeModel;
/**
* This example shows how to create a simple JTreeTable component,
* by using a JTree as a renderer (and editor) for the cells in a
* particular column in the JTable.
*
* @version %I% %G%
*
* @author Philip Milne
* @author Scott Violet
*/
public class JTreeTable extends JTable {
private static final long serialVersionUID = 3799703529762739559L;
protected TreeTableCellRenderer tree;
@SuppressWarnings("serial")
public JTreeTable(TreeTableModel treeTableModel) {
super();
// Create the tree. It will be used as a renderer and editor.
tree = new TreeTableCellRenderer(treeTableModel);
// Install a tableModel representing the visible rows in the tree.
super.setModel(new TreeTableModelAdapter(treeTableModel, tree));
// Force the JTable and JTree to share their row selection models.
tree.setSelectionModel(new DefaultTreeSelectionModel() {
// Extend the implementation of the constructor, as if:
/* public this() */ {
setSelectionModel(listSelectionModel);
}
});
// Make the tree and table row heights the same.
tree.setRowHeight(getRowHeight());
// Install the tree editor renderer and editor.
setDefaultRenderer(TreeTableModel.class, tree);
setDefaultEditor(TreeTableModel.class, new TreeTableCellEditor());
setShowGrid(false);
setIntercellSpacing(new Dimension(0, 0));
}
/* Workaround for BasicTableUI anomaly. Make sure the UI never tries to
* paint the editor. The UI currently uses different techniques to
* paint the renderers and editors and overriding setBounds() below
* is not the right thing to do for an editor. Returning -1 for the
* editing row in this case, ensures the editor is never painted.
*/
public int getEditingRow() {
return (getColumnClass(editingColumn) == TreeTableModel.class) ? -1 : editingRow;
}
//
// The renderer used to display the tree nodes, a JTree.
//
public class TreeTableCellRenderer extends JTree implements TableCellRenderer {
private static final long serialVersionUID = -7267418638553234230L;
protected int visibleRow;
public TreeTableCellRenderer(TreeModel model) {
super(model);
}
public void setBounds(int x, int y, int w, int h) {
super.setBounds(x, 0, w, JTreeTable.this.getHeight());
}
public void paint(Graphics g) {
g.translate(0, -visibleRow * getRowHeight());
super.paint(g);
}
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row, int column) {
if(isSelected)
setBackground(table.getSelectionBackground());
else
setBackground(table.getBackground());
visibleRow = row;
return this;
}
}
//
// The editor used to interact with tree nodes, a JTree.
//
public class TreeTableCellEditor extends AbstractCellEditor implements TableCellEditor {
public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected, int r, int c) {
return tree;
}
}
}
package org.projectopen.treetable;
/*
* %W% %E%
*
* Copyright 1997, 1998 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* Neither the name of Sun Microsystems, Inc. or the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any
* kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
* WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
* EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY
* DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR
* RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE OR
* ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE
* FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT,
* SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
* CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF
* THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS
* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed, licensed or
* intended for use in the design, construction, operation or
* maintenance of any nuclear facility.
*/
/**
* An implementation of MergeSort, needs to be subclassed to provide a
* comparator.
*
* @version %I% %G%
*
* @author Scott Violet
*/
public abstract class MergeSort extends Object {
protected Object toSort[];
protected Object swapSpace[];
public void sort(Object array[]) {
if(array != null && array.length > 1)
{
int maxLength;
maxLength = array.length;
swapSpace = new Object[maxLength];
toSort = array;
this.mergeSort(0, maxLength - 1);
swapSpace = null;
toSort = null;
}
}
public abstract int compareElementsAt(int beginLoc, int endLoc);
protected void mergeSort(int begin, int end) {
if(begin != end)
{
int mid;
mid = (begin + end) / 2;
this.mergeSort(begin, mid);
this.mergeSort(mid + 1, end);
this.merge(begin, mid, end);
}
}
protected void merge(int begin, int middle, int end) {
int firstHalf, secondHalf, count;
firstHalf = count = begin;
secondHalf = middle + 1;
while((firstHalf <= middle) && (secondHalf <= end))
{
if(this.compareElementsAt(secondHalf, firstHalf) < 0)
swapSpace[count++] = toSort[secondHalf++];
else
swapSpace[count++] = toSort[firstHalf++];
}
if(firstHalf <= middle)
{
while(firstHalf <= middle)
swapSpace[count++] = toSort[firstHalf++];
}
else
{
while(secondHalf <= end)
swapSpace[count++] = toSort[secondHalf++];
}
for(count = begin;count <= end;count++)
toSort[count] = swapSpace[count];
}
}
package org.projectopen.treetable;
/*
* %W% %E%
*
* Copyright 1997, 1998 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* Neither the name of Sun Microsystems, Inc. or the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any
* kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
* WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
* EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY
* DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR
* RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE OR
* ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE
* FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT,
* SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
* CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF
* THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS
* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed, licensed or
* intended for use in the design, construction, operation or
* maintenance of any nuclear facility.
*/
import javax.swing.tree.TreeModel;
/**
* TreeTableModel is the model used by a JTreeTable. It extends TreeModel
* to add methods for getting inforamtion about the set of columns each
* node in the TreeTableModel may have. Each column, like a column in
* a TableModel, has a name and a type associated with it. Each node in
* the TreeTableModel can return a value for each of the columns and
* set that value if isCellEditable() returns true.
*
* @version %I% %G%
*
* @author Philip Milne
* @author Scott Violet
*/
public interface TreeTableModel extends TreeModel
{
/**
* Returns the number ofs availible column.
*/
public int getColumnCount();
/**
* Returns the name for column number <code>column</code>.
*/
public String getColumnName(int column);
/**
* Returns the type for column number <code>column</code>.
*/
@SuppressWarnings("unchecked")
public Class getColumnClass(int column);
/**
* Returns the value to be displayed for node <code>node</code>,
* at column number <code>column</code>.
*/
public Object getValueAt(Object node, int column);
/**
* Indicates whether the the value for node <code>node</code>,
* at column number <code>column</code> is editable.
*/
public boolean isCellEditable(Object node, int column);
/**
* Sets the value for node <code>node</code>,
* at column number <code>column</code>.
*/
public void setValueAt(Object aValue, Object node, int column);
}
package org.projectopen.treetable;
/*
* %W% %E%
*
* Copyright 1997, 1998 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* Neither the name of Sun Microsystems, Inc. or the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any
* kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
* WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
* EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY
* DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR
* RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE OR
* ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE
* FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT,
* SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
* CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF
* THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS
* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed, licensed or
* intended for use in the design, construction, operation or
* maintenance of any nuclear facility.
*/
import javax.swing.JTree;
import javax.swing.event.TreeExpansionEvent;
import javax.swing.event.TreeExpansionListener;
import javax.swing.table.AbstractTableModel;
import javax.swing.tree.TreePath;
/**
* This is a wrapper class takes a TreeTableModel and implements
* the table model interface. The implementation is trivial, with
* all of the event dispatching support provided by the superclass:
* the AbstractTableModel.
*
* @version %I% %G%
*
* @author Philip Milne
* @author Scott Violet
*/
public class TreeTableModelAdapter extends AbstractTableModel
{
private static final long serialVersionUID = -1721083867886788730L;
JTree tree;
TreeTableModel treeTableModel;
public TreeTableModelAdapter(TreeTableModel treeTableModel, JTree tree) {
this.tree = tree;
this.treeTableModel = treeTableModel;
tree.addTreeExpansionListener(new TreeExpansionListener() {
// Don't use fireTableRowsInserted() here;
// the selection model would get updated twice.
public void treeExpanded(TreeExpansionEvent event) {
fireTableDataChanged();
}
public void treeCollapsed(TreeExpansionEvent event) {
fireTableDataChanged();
}
});
}
// Wrappers, implementing TableModel interface.
public int getColumnCount() {
return treeTableModel.getColumnCount();
}
public String getColumnName(int column) {
return treeTableModel.getColumnName(column);
}
@SuppressWarnings("unchecked")
public Class getColumnClass(int column) {
return treeTableModel.getColumnClass(column);
}
public int getRowCount() {
return tree.getRowCount();
}
protected Object nodeForRow(int row) {
TreePath treePath = tree.getPathForRow(row);
return treePath.getLastPathComponent();
}
public Object getValueAt(int row, int column) {
return treeTableModel.getValueAt(nodeForRow(row), column);
}
public boolean isCellEditable(int row, int column) {
return treeTableModel.isCellEditable(nodeForRow(row), column);
}
public void setValueAt(Object value, int row, int column) {
treeTableModel.setValueAt(value, nodeForRow(row), column);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment