From 0ec8481c10cd8277d84c7c1a785483a0a739e5a0 Mon Sep 17 00:00:00 2001 From: abranson Date: Thu, 4 Aug 2011 00:42:34 +0200 Subject: More code cleanup: Refactored Entity Proxy Subscription to handle generics better Rewrote RemoteMap to use TreeMap instead of the internal array for order. It now sorts its keys by number if they parse, else as strings. Removed a no-longer-in-progress outcome form class --- source/com/c2kernel/gui/tabs/JobListPane.java | 85 ++++++++++++++++----------- 1 file changed, 51 insertions(+), 34 deletions(-) (limited to 'source/com/c2kernel/gui/tabs/JobListPane.java') diff --git a/source/com/c2kernel/gui/tabs/JobListPane.java b/source/com/c2kernel/gui/tabs/JobListPane.java index b9ff0e5..619a589 100644 --- a/source/com/c2kernel/gui/tabs/JobListPane.java +++ b/source/com/c2kernel/gui/tabs/JobListPane.java @@ -25,10 +25,10 @@ import javax.swing.JTable; import javax.swing.table.AbstractTableModel; import com.c2kernel.common.ObjectNotFoundException; -import com.c2kernel.entity.C2KLocalObject; import com.c2kernel.entity.agent.Job; import com.c2kernel.entity.agent.JobList; import com.c2kernel.entity.proxy.EntityProxyObserver; +import com.c2kernel.entity.proxy.MemberSubscription; import com.c2kernel.gui.MainFrame; import com.c2kernel.lifecycle.instance.stateMachine.Transitions; import com.c2kernel.persistency.ClusterStorage; @@ -43,7 +43,7 @@ import com.c2kernel.utils.Logger; * @version $Revision: 1.4 $ $Date: 2004/10/21 08:02:21 $ * @author $Author: abranson $ */ -public class JobListPane extends EntityTabPane implements ActionListener, EntityProxyObserver { +public class JobListPane extends EntityTabPane implements ActionListener, EntityProxyObserver { JobList joblist; JoblistTableModel model; @@ -54,7 +54,7 @@ public class JobListPane extends EntityTabPane implements ActionListener, Entity JButton endButton = new JButton(">>"); public static final int SIZE = 30; int currentSize = SIZE; - + public JobListPane() { super("Job List", "Agent Job List"); initPanel(); @@ -63,18 +63,18 @@ public class JobListPane extends EntityTabPane implements ActionListener, Entity Box navBox = Box.createHorizontalBox(); navBox.add(startButton); navBox.add(prevButton); navBox.add(nextButton); navBox.add(endButton); - + // setup buttons //startButton.setEnabled(false); nextButton.setEnabled(false); //prevButton.setEnabled(false); endButton.setEnabled(false); startButton.setActionCommand("start"); startButton.addActionListener(this); prevButton.setActionCommand("prev"); - prevButton.addActionListener(this); + prevButton.addActionListener(this); nextButton.setActionCommand("next"); - nextButton.addActionListener(this); + nextButton.addActionListener(this); endButton.setActionCommand("end"); - endButton.addActionListener(this); + endButton.addActionListener(this); getGridBagConstraints(); c.gridx = 0; c.gridy = 1; c.anchor = GridBagConstraints.NORTHWEST; @@ -83,29 +83,31 @@ public class JobListPane extends EntityTabPane implements ActionListener, Entity gridbag.setConstraints(navBox, c); add(navBox); - + // Create table eventTable = new JTable(); JScrollPane eventScroll= new JScrollPane(eventTable); c.weightx = 1.0; c.weighty = 1.0; - c.fill = GridBagConstraints.BOTH; c.gridy++; + c.fill = GridBagConstraints.BOTH; c.gridy++; gridbag.setConstraints(eventScroll, c); add(eventScroll); - + // detect double clicked jobs eventTable.addMouseListener(new JobListMouseListener()); } - public void reload() { + @Override + public void reload() { joblist.clear(); jumpToEnd(); } - public void run() { + @Override + public void run() { Thread.currentThread().setName("Joblist Pane Builder"); try { joblist = (JobList)sourceEntity.getEntity().getObject(ClusterStorage.JOB); - sourceEntity.getEntity().subscribe(this, ClusterStorage.JOB, false); + sourceEntity.getEntity().subscribe(new MemberSubscription(this, ClusterStorage.JOB, false)); } catch (ObjectNotFoundException e) { Logger.error(e); } @@ -113,8 +115,8 @@ public class JobListPane extends EntityTabPane implements ActionListener, Entity eventTable.setModel(model); jumpToEnd(); } - - + + public void jumpToEnd() { int lastEvent = joblist.getLastId(); int firstEvent = 0; currentSize = SIZE; @@ -124,27 +126,30 @@ public class JobListPane extends EntityTabPane implements ActionListener, Entity model.setView(firstEvent, currentSize); } - public void add(C2KLocalObject contents) { + @Override + public void add(Job contents) { reload(); } - public void remove(String id) { + @Override + public void remove(String id) { reload(); - } - + } + + @Override public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("end")) { jumpToEnd(); return; } - + int lastEvent = joblist.getLastId(); int startEvent = model.getStartId(); if (e.getActionCommand().equals("start")) { currentSize = SIZE; startEvent = 0; } - + else if (e.getActionCommand().equals("prev")) { currentSize = SIZE; startEvent-=currentSize; @@ -161,20 +166,20 @@ public class JobListPane extends EntityTabPane implements ActionListener, Entity } model.setView(startEvent, currentSize); - } - + } + private class JoblistTableModel extends AbstractTableModel { Job[] job; Integer[] ids; String[] itemNames; int loaded = 0; int startId = 0; - + public JoblistTableModel(JobList joblist) { job = new Job[0]; ids = new Integer[0]; - } - + } + public int getStartId() { return startId; } @@ -185,12 +190,11 @@ public class JobListPane extends EntityTabPane implements ActionListener, Entity itemNames = new String[size]; this.startId = startId; int count = 0; - for (Iterator i = joblist.keySet().iterator(); i.hasNext();) { + for (Iterator i = joblist.keySet().iterator(); i.hasNext();) { Integer thisJobId = new Integer((String)i.next()); if (count >= startId) { int idx = count-startId; ids[idx] = thisJobId; - Job thisJob = joblist.getJob(thisJobId.intValue()); job[idx] = joblist.getJob(thisJobId.intValue()); itemNames[idx] = "Item Not Found"; try { @@ -198,7 +202,7 @@ public class JobListPane extends EntityTabPane implements ActionListener, Entity } catch (Exception ex) { Logger.error(ex); } - + } count++; loaded = count-startId; @@ -209,6 +213,7 @@ public class JobListPane extends EntityTabPane implements ActionListener, Entity /** * @see javax.swing.table.TableModel#getColumnClass(int) */ + @Override public Class getColumnClass(int columnIndex) { switch(columnIndex) { case 0: @@ -221,6 +226,7 @@ public class JobListPane extends EntityTabPane implements ActionListener, Entity /** * @see javax.swing.table.TableModel#getColumnCount() */ + @Override public int getColumnCount() { return 4; } @@ -228,6 +234,7 @@ public class JobListPane extends EntityTabPane implements ActionListener, Entity /** * @see javax.swing.table.TableModel#getColumnName(int) */ + @Override public String getColumnName(int columnIndex) { switch(columnIndex) { case 0: return Language.translate("ID"); @@ -241,6 +248,7 @@ public class JobListPane extends EntityTabPane implements ActionListener, Entity /** * @see javax.swing.table.TableModel#getRowCount() */ + @Override public int getRowCount() { return loaded; } @@ -248,6 +256,7 @@ public class JobListPane extends EntityTabPane implements ActionListener, Entity /** * @see javax.swing.table.TableModel#getValueAt(int, int) */ + @Override public Object getValueAt(int rowIndex, int columnIndex) { if (job.length <= rowIndex || job[rowIndex] == null) return ""; @@ -257,8 +266,8 @@ public class JobListPane extends EntityTabPane implements ActionListener, Entity case 1: return itemNames[rowIndex]; case 2: return job[rowIndex].getStepName(); case 3: return Transitions.getTransitionName(job[rowIndex].getPossibleTransition()); - default: return ""; - } + default: return ""; + } } catch (Exception e) { return null; } @@ -267,10 +276,11 @@ public class JobListPane extends EntityTabPane implements ActionListener, Entity /** * @see javax.swing.table.TableModel#isCellEditable(int, int) */ + @Override public boolean isCellEditable(int rowIndex, int columnIndex) { return false; } - + public Job getJobAtRow(int rowIndex) { return job[rowIndex]; } @@ -279,7 +289,8 @@ public class JobListPane extends EntityTabPane implements ActionListener, Entity private class JobListMouseListener extends MouseAdapter { - public void mouseClicked(MouseEvent e) { + @Override + public void mouseClicked(MouseEvent e) { super.mouseClicked(e); if (e.getClickCount() == 2) { Job selectedJob = model.getJobAtRow(eventTable.getSelectedRow()); @@ -289,7 +300,13 @@ public class JobListPane extends EntityTabPane implements ActionListener, Entity Logger.error(ex); JOptionPane.showMessageDialog(null, "No Item Found", "Job references an unknown item", JOptionPane.ERROR_MESSAGE); } - } + } } } + + @Override + public void control(String control, String msg) { + // TODO Auto-generated method stub + + } } -- cgit v1.2.3