/** * Show a project * * @param function the action being taken * @param p the project * @param parentId the parent project id * @throws Exception */ private void showProject(Action function, Project p, Integer parentId) throws Exception { // set the link panel to show this project's links linkPanel.setOwner(p); // show all possible parent projects parentProjectComboBox.removeAllItems(); parentProjectComboBox.addItem(""); Collection<Project> projects = TaskModel.getReference().getProjects(); if (projects != null) { for (Project project : projects) { // add open projects that are not the current one if ((p == null || p.getKey() != project.getKey()) && project.getStatus().equals(Resource.getResourceString("OPEN"))) parentProjectComboBox.addItem(getProjectString(project)); } } // if we are showing an existing project - fill in the gui fields for it if (p != null) { // task number projectIdText.setText(Integer.toString(p.getKey())); projectIdText.setEditable(false); // window title - "Item N" windowTitle = Resource.getResourceString("Item_") + " " + p.getKey(); // due date GregorianCalendar gc = new GregorianCalendar(); Date dd = p.getDueDate(); if (dd != null) { gc.setTime(dd); dueDateChooser.setCalendar(gc); } GregorianCalendar gc2 = new GregorianCalendar(); dd = p.getStartDate(); if (dd != null) gc2.setTime(dd); startDateChooser.setCalendar(gc2); int daysleft = DateUtil.daysLeft(p.getDueDate()); daysLeftText.setText(Integer.toString(daysleft)); String cat = p.getCategory(); if (cat != null && !cat.equals("")) { categoryBox.setSelectedItem(cat); } else { categoryBox.setSelectedIndex(0); } description.setText(p.getDescription()); statusComboBox.setEditable(false); Collection<Task> ptasks = TaskModel.getReference().getTasks(p.getKey()); totalTaskCount.setText(Integer.toString(ptasks.size())); int openTasks = 0; for (Task pt : ptasks) { if (!TaskModel.isClosed(pt)) { openTasks++; } } openTaskCount.setText(Integer.toString(openTasks)); // set parent project Integer pid = p.getParent(); if (pid != null) { Project par = TaskModel.getReference().getProject(pid.intValue()); if (TaskModel.isClosed(par)) { // if parent closed - would not have been added before parentProjectComboBox.addItem(getProjectString(par)); } parentProjectComboBox.setSelectedItem(getProjectString(par)); } // add the task list if (taskPanel == null) { taskPanel = new TaskListPanel(TaskView.getProjectString(p)); taskPanel.addClosedTaskFilter(); taskBorder.add( taskPanel, GridBagConstraintsFactory.create(0, 0, GridBagConstraints.BOTH, 1.0, 1.0)); } } else { // set fields for a new project projectIdText.setText("NEW"); projectIdText.setEditable(false); // title windowTitle = Resource.getResourceString("NEW_Item"); statusComboBox.addItem(Resource.getResourceString("OPEN")); statusComboBox.setEnabled(false); categoryBox.setSelectedIndex(0); description.setText(""); // desc totalTaskCount.setText(""); openTaskCount.setText(""); // parent id may have been passed in if (parentId != null) { Project par = TaskModel.getReference().getProject(parentId.intValue()); if (TaskModel.isClosed(par)) { parentProjectComboBox.addItem(getProjectString(par)); } parentProjectComboBox.setSelectedItem(getProjectString(par)); String cat = par.getCategory(); if (cat != null && !cat.equals("")) { categoryBox.setSelectedItem(cat); } else { categoryBox.setSelectedIndex(0); } GregorianCalendar gc = new GregorianCalendar(); Date dd = par.getDueDate(); if (dd != null) { gc.setTime(dd); dueDateChooser.setCalendar(gc); } Date sd = par.getStartDate(); if (sd != null) { gc.setTime(sd); startDateChooser.setCalendar(gc); } } } // can't change status on a new project if (p == null) { statusComboBox.setEnabled(false); } // cloning takes the fields filled in for an existing task and resets // only those // that don't apply to the clone if (function == Action.CLONE) { // need new task number projectIdText.setText("CLONE"); projectIdText.setEditable(false); statusComboBox.removeAllItems(); statusComboBox.addItem(Resource.getResourceString("OPEN")); statusComboBox.setEnabled(false); } // change existing task else if (function == Action.CHANGE) { String state = null; if (p != null) state = p.getStatus(); // set next state pulldown - projects only move between open and // closed statusComboBox.removeAllItems(); statusComboBox.addItem(Resource.getResourceString("OPEN")); statusComboBox.addItem(Resource.getResourceString("CLOSED")); statusComboBox.setSelectedItem(state); statusComboBox.setEnabled(true); } }
/** Initialize the UI. */ private void initComponents() // GEN-BEGIN:initComponents { setLayout(new GridBagLayout()); /* * project info panel */ JPanel projectInfoPanel = new JPanel(); projectInfoPanel.setLayout(new GridBagLayout()); projectInfoPanel.setBorder(new TitledBorder(Resource.getResourceString("ProjectInformation"))); projectIdText = new JTextField(); projectIdText.setText("projectIdText"); description = new JTextField(); JLabel lblItemNum = new JLabel(); lblItemNum.setText(Resource.getResourceString("Item_#")); dueDateChooser = new JDateChooser(); JLabel lblStartDate = new JLabel(); JLabel lblDueDate = new JLabel(); statusComboBox = new JComboBox(); JLabel catlabel = new JLabel(); JLabel lblStatus = new JLabel(); ResourceHelper.setText(lblStatus, "Status"); lblStatus.setLabelFor(statusComboBox); startDateChooser = new JDateChooser(); ResourceHelper.setText(lblStartDate, "Start_Date"); lblStartDate.setLabelFor(startDateChooser); ResourceHelper.setText(lblDueDate, "Due_Date"); lblDueDate.setLabelFor(dueDateChooser); ResourceHelper.setText(catlabel, "Category"); categoryBox = new JComboBox(); catlabel.setLabelFor(categoryBox); projectInfoPanel.add( lblItemNum, GridBagConstraintsFactory.create(0, 0, GridBagConstraints.BOTH)); projectInfoPanel.add( lblStatus, GridBagConstraintsFactory.create(0, 1, GridBagConstraints.BOTH)); projectInfoPanel.add(catlabel, GridBagConstraintsFactory.create(0, 2, GridBagConstraints.BOTH)); JLabel descLabel = new JLabel(); descLabel.setText(Resource.getResourceString("Description")); projectInfoPanel.add( descLabel, GridBagConstraintsFactory.create(0, 3, GridBagConstraints.BOTH)); projectInfoPanel.add( projectIdText, GridBagConstraintsFactory.create(1, 0, GridBagConstraints.BOTH)); projectInfoPanel.add( statusComboBox, GridBagConstraintsFactory.create(1, 1, GridBagConstraints.BOTH, 1.0, 0.0)); projectInfoPanel.add( categoryBox, GridBagConstraintsFactory.create(1, 2, GridBagConstraints.BOTH, 1.0, 0.0)); GridBagConstraints dgbc = GridBagConstraintsFactory.create(1, 3, GridBagConstraints.BOTH, 1.0, 0.0); dgbc.gridwidth = 5; projectInfoPanel.add(description, dgbc); JLabel parentLabel = new JLabel(Resource.getResourceString("parent")); projectInfoPanel.add( parentLabel, GridBagConstraintsFactory.create(2, 0, GridBagConstraints.BOTH)); projectInfoPanel.add( lblStartDate, GridBagConstraintsFactory.create(2, 1, GridBagConstraints.BOTH)); projectInfoPanel.add( lblDueDate, GridBagConstraintsFactory.create(2, 2, GridBagConstraints.BOTH)); projectInfoPanel.add( parentProjectComboBox, GridBagConstraintsFactory.create(3, 0, GridBagConstraints.BOTH, 1.0, 0.0)); projectInfoPanel.add( startDateChooser, GridBagConstraintsFactory.create(3, 1, GridBagConstraints.BOTH, 1.0, 0.0)); projectInfoPanel.add( dueDateChooser, GridBagConstraintsFactory.create(3, 2, GridBagConstraints.BOTH, 1.0, 0.0)); JLabel daysLeftLabel = new JLabel(); daysLeftLabel.setText(Resource.getResourceString("Days_Left")); daysLeftLabel.setHorizontalTextPosition(SwingConstants.RIGHT); daysLeftLabel.setHorizontalAlignment(SwingConstants.RIGHT); projectInfoPanel.add(daysLeftLabel, GridBagConstraintsFactory.create(4, 0)); JLabel totalLabel = new JLabel(); totalLabel.setText(Resource.getResourceString("total_tasks")); projectInfoPanel.add(totalLabel, GridBagConstraintsFactory.create(4, 1)); JLabel openLabel = new JLabel(); openLabel.setText(Resource.getResourceString("open_tasks")); projectInfoPanel.add(openLabel, GridBagConstraintsFactory.create(4, 2)); daysLeftText = new JTextField(); daysLeftText.setEditable(false); projectInfoPanel.add( daysLeftText, GridBagConstraintsFactory.create(5, 0, GridBagConstraints.BOTH, 1.0, 0.0)); totalTaskCount = new JTextField(); totalTaskCount.setEditable(false); projectInfoPanel.add( totalTaskCount, GridBagConstraintsFactory.create(5, 1, GridBagConstraints.BOTH, 1.0, 0.0)); openTaskCount = new JTextField(); openTaskCount.setEditable(false); projectInfoPanel.add( openTaskCount, GridBagConstraintsFactory.create(5, 2, GridBagConstraints.BOTH, 1.0, 0.0)); add( projectInfoPanel, GridBagConstraintsFactory.create(0, 0, GridBagConstraints.BOTH, 1.0, 0.0)); /* * button panel */ JPanel buttonPanel = new JPanel(); JButton savebutton = new JButton(); savebutton.setIcon(new ImageIcon(getClass().getResource("/resource/Save16.gif"))); ResourceHelper.setText(savebutton, "Save"); savebutton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { saveProject(); } }); buttonPanel.add(savebutton, savebutton.getName()); GridBagConstraints bc = GridBagConstraintsFactory.create(0, 7, GridBagConstraints.BOTH, 0.0, 0.0); bc.gridwidth = 6; projectInfoPanel.add(buttonPanel, bc); /* * link panel */ linkPanel.setBorder(new TitledBorder(Resource.getResourceString("links"))); add(linkPanel, GridBagConstraintsFactory.create(0, 2, GridBagConstraints.BOTH)); /* * panel that will contain the project's task list */ taskBorder = new JPanel(); taskBorder.setBorder(new TitledBorder(Resource.getResourceString("tasks"))); taskBorder.setLayout(new GridBagLayout()); add(taskBorder, GridBagConstraintsFactory.create(0, 3, GridBagConstraints.BOTH, 1.0, 1.0)); }