private void doPop(MouseEvent e) { PopUpDemo menu = new PopUpDemo(); menu.show(e.getComponent(), e.getX(), e.getY()); table.editCellAt(-1, -1); }
@Override public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("addTask")) { taskList.add(new Task("new Task")); /// @todo A new created task should be editable right away. table.editCellAt(taskList.getRowCount() - 1, 0); } if (e.getActionCommand().equals("deleteTask") && (table.getSelectedRow() != -1)) { taskList.remove(table.getSelectedRow()); } if (e.getActionCommand().equals("cross") && (table.getSelectedRow() != -1)) { taskList.get(table.getSelectedRow()).setState(State.crossed); } if (e.getActionCommand().equals("dismiss") && (table.getSelectedRow() != -1)) { taskList.get(table.getSelectedRow()).setState(State.dismissed); } if (e.getActionCommand().equals("workedOn") && (table.getSelectedRow() != -1)) { Task task = taskList.get(table.getSelectedRow()); task.setState(State.crossed); taskList.add(new Task(task.getName())); } // File handling File file = null; Writer writer = null; JAXBContext context; if (e.getActionCommand().equals("save")) { Marshaller m = null; int returnVal = fileChooser.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fileChooser.getSelectedFile(); if (!file.getName().endsWith(".xml")) { /// @TODO Append automaticly .xml } try { context = JAXBContext.newInstance(TaskList.class); m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); writer = new FileWriter(file); m.marshal(taskList, writer); } catch (JAXBException exeption) { exeption.printStackTrace(); } catch (IOException exeption) { exeption.printStackTrace(); } finally { try { writer.close(); } catch (Exception exeption) { } } } } if (e.getActionCommand().equals("open")) { Unmarshaller um = null; int returnVal = fileChooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fileChooser.getSelectedFile(); // if(!file.getName().endsWith(".xml")){ /// @TODO Append automaticly .xml // } try { context = JAXBContext.newInstance(TaskList.class); um = context.createUnmarshaller(); taskList = (TaskList) um.unmarshal(file); table.setModel(taskList); table.getColumnModel().getColumn(0).setCellRenderer(new TaskRenderer()); } catch (JAXBException exeption) { exeption.printStackTrace(); } finally { try { writer.close(); } catch (Exception exeption) { } } } } taskList.fireTableDataChanged(); }