Package com.acelet.s.workflow

Source Code of com.acelet.s.workflow.TaskTablePanel

/* Copyright 1999-2008 Acelet.org. All rights reserved. GPL v2 license */
/** @author Wei Jiang */

package com.acelet.s.workflow;

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;

import com.acelet.lib.*;
import com.acelet.s.chore.Chore;
import com.acelet.s.job.*;
import com.acelet.s.scheduler.*;
import com.acelet.s.task.*;

public class TaskTablePanel extends TablePanel {
  String selectedName;
  String selectedDescription;
  String selectedBrief;
  boolean modified;

  JButton okButton;
  JButton cancelButton;

  boolean isCallerSuperWatchdog;

  public TaskTablePanel(String selectedName) {
    this.selectedName = selectedName;

    String helpTopic = "WorkflowWindows.TaskTablePanel";
    ShowHelp.setHelpTopic(this, helpTopic);

    isCallerSuperWatchdog = new WhichCaller().isCallerSuperWatchdog();
  }

  public void actionPerformed(ActionEvent event) {
    try {
      Object source = event.getSource();
      if (source == okButton) {
        getSelectedName();
        close();
      } else if (source == cancelButton) {
        SwingUtilities.windowForComponent(this).dispose();
        return;
      }
    } catch (Throwable ex) {
      InfoBox.exhibit(this, InfoBox.OK, ex);
    }
  }

  protected void cleanup() {
  }

  protected Vector getColumnNameVector() {
    Vector vector = new Vector();
    vector.addElement(Phrase.get("TX_NAME"));
    vector.addElement(Phrase.get("TX_BRIEF"));
    vector.addElement(Phrase.get("TX_DESCRIPTION"));
    return vector;
  }

  protected String getPropertyNameForColumns() {
    return "Workflow.TaskTable.PropertiesColumns";
  }

  protected String getPropertyNameForSize() {
    return "Workflow.TaskTable.PropertiesSize";
  }

  public boolean getReady() throws Exception {
    if (super.getReady()) {
      setSelectedName();
      statusTextField.setVisible(false);
      return true;
    } else
      return false;
  }

  void getSelectedName() {
    int[] selection = checkOneSelected();
    if (selection == null)
      return;
     
    int index = selection[0];
    Vector rowVector = (Vector) tableDataVector.elementAt(index);
    String newName = (String) rowVector.elementAt(0);
    String newDescription = (String) rowVector.elementAt(1);
    String newBrief = (String) rowVector.elementAt(2);
    if (newName.equals(selectedName) == false) {
      selectedName = newName;
      modified = true;
    }
    if (newBrief.equals(selectedBrief) == false) {
      selectedBrief = newBrief;
      modified = true;
    }
    if (newDescription.equals(selectedDescription) == false) {
      selectedDescription = newDescription;
      modified = true;
    }
  }

  protected SuperProperties getSuperProperties()  throws Exception{
    return new WorkflowProperties();
  }

  protected JMenuBar makeMenuBar() {
    LoadFile loadFile = new LoadFile();
    ImageIcon okImageIcon = loadFile.receiveImageIcon("ok.gif");
    ImageIcon cancelImageIcon = loadFile.receiveImageIcon("cancel.gif");

    okButton = new JButton(Phrase.get("TX_OK"), okImageIcon);
    okButton.addActionListener(this);
    okButton.setMargin(buttonInsets);

    cancelButton = new JButton(Phrase.get("TX_CANCEL"), cancelImageIcon);
    cancelButton.addActionListener(this);
    cancelButton.setMargin(buttonInsets);

    JMenuBar menuBar = new JMenuBar();
    menuBar.add(okButton);
    menuBar.add(cancelButton);
    return menuBar;
  }

  protected boolean prepareData() throws Exception {
    if (isCallerSuperWatchdog) {
      Vector allComingChores = com.acelet.s.watchdog.Delegate.selectAllChores();
      int choreSize = allComingChores.size();
      for (int i = 0; i < choreSize; i++) {
        Chore chore = (Chore) allComingChores.elementAt(i);
        String choreName = chore.name;
        String brief = chore.getBrief();
        String description = chore.description;
       
        Vector rowVector = new Vector();
        rowVector.add(choreName);
        rowVector.add(brief);
        rowVector.add(description);
        tableDataVector.add(rowVector);
      }
    } else {
      Vector allComingTasks = Delegate.selectAllTasks();
      int taskSize = allComingTasks.size();
      for (int i = 0; i < taskSize; i++) {
        Task task = (Task) allComingTasks.elementAt(i);
        String taskName = task.name;
        String brief = task.getBrief();
        String description = task.description;
       
        Vector rowVector = new Vector();
        rowVector.add(taskName);
        rowVector.add(brief);
        rowVector.add(description);
        tableDataVector.add(rowVector);
      }
    }
    return true;
  }

  void setSelectedName() {
    if (selectedName == null)
      return;

    for (int i = 0; i < tableDataVector.size(); i++) {
      Vector rowVector = (Vector) tableDataVector.get(i);
      String name = (String) rowVector.get(0);
      if (name.equals(selectedName)) {
        table.addRowSelectionInterval(i, i);
      }
    }
  }
}
TOP

Related Classes of com.acelet.s.workflow.TaskTablePanel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.