public interface RightAndMandatoryConstants {

  public static final int GAP_ROWHEADER = 10;

  public static final int GAP_LINEBREAK = 6;

  public static final int CELL_WIDTH = 18;

  public static final int CELL_HEIGHT = 18;

  public static final int COLUMN_HEADER_HEIGHT_MAX = 240;

  public static final Color COLOR_BACKGROUND = Color.WHITE;

  public static final Color COLOR_GRID = new Color(216, 220, 228);

  public static final Color COLOR_SELECTION_BACKGROUND = new Color(135, 146, 165);

  public static final Color COLOR_MARKER_BACKGROUND = new Color(242, 243, 246);

  public static final Color COLOR_MARKER_GRID = new Color(128, 128, 128);

  public static final Icon ICON_NO_RIGHT = Icons.getInstance().getIconJobUnknown();

  public static final Icon ICON_READ = Icons.getInstance().getIconJobWarning();

  public static final Icon ICON_WRITE = Icons.getInstance().getIconJobSuccessful();

  public static final boolean DEV_MODUS = ApplicationProperties.getInstance().isFunctionBlockDev();
}
Esempio n. 2
0
  @Override
  public Icon getIcon() {

    Icon result = null;
    switch (((RuleNode) getUserObject()).getNodeType()) {
      case RULE:
        result =
            ((RuleNode) getUserObject()).isActive()
                ? Icons.getInstance().getIconRuleNode()
                : Icons.getInstance().getIconRuleNodeDisabled();
        break;

      default:
        result = null;
        break;
    }

    return result;
  }
Esempio n. 3
0
  protected List<JComponent> getToolBarComponents() {
    List<JComponent> components = new ArrayList<JComponent>();
    components.add(
        new JButton(
            new AbstractAction("", Icons.getInstance().getIconRefresh16()) {

              @Override
              public void actionPerformed(ActionEvent e) {
                UIUtils.runCommand(
                    DefaultExplorerView.this.getParent(),
                    new CommonRunnable() {
                      @Override
                      public void run() throws CommonFinderException {
                        Main.getInstance()
                            .getMainController()
                            .getExplorerController()
                            .refreshTab(DefaultExplorerView.this);
                      }
                    });
              }
            }));
    return components;
  }
Esempio n. 4
0
  private void setupActions(final JTable table) {
    super.addRefreshIntervalActionsToSingleScheduledRefreshable();

    // assign popup menu:
    table.addMouseListener(new PopupMenuListener(this.popupTimelimit, table));

    // add mouse listeners for double click in table:
    table.addMouseListener(new DoubleClickListener(timelimittaskview));

    final Action actRefresh =
        new CommonAbstractAction(
            Icons.getInstance().getIconRefresh16(),
            getSpringLocaleDelegate()
                .getMessage("TimelimitTaskController.10", "Fristenliste aktualisieren")) {

          @Override
          public void actionPerformed(ActionEvent ev) {
            TimelimitTaskController.this.cmdRefreshTimelimitTaskView();
          }
        };

    actPerformTask.setEnabled(false);
    actRemoveTask.setEnabled(false);
    actFinishTask.setEnabled(false);

    timelimittaskview.getRefreshButton().setAction(actRefresh);
    timelimittaskview.getPerformMenuItem().setAction(actPerformTask);
    timelimittaskview.getRemoveMenuItem().setAction(actRemoveTask);
    timelimittaskview.getFinishButton().setAction(actFinishTask);
    timelimittaskview.getPrintMenuItem().setAction(actPrint);

    // use only action listener for "show finished" button:
    timelimittaskview.btnShowAllTasks.addActionListener(actRefresh);

    setRefreshIntervalForSingleViewRefreshable(readIntervalTasksFromPreferences());

    table
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              @Override
              public void valueChanged(ListSelectionEvent ev) {
                if (!ev.getValueIsAdjusting()) {
                  final ListSelectionModel lsm = (ListSelectionModel) ev.getSource();
                  final boolean bSelectionEmpty = lsm.isSelectionEmpty();
                  final Boolean bFinished;
                  final Boolean bHasGenericObject;

                  if (bSelectionEmpty) {
                    bFinished = null;
                    bHasGenericObject = null;
                  } else {
                    final int iSelectedRow =
                        TimelimitTaskController.this.timelimittaskview.getTable().getSelectedRow();
                    CollectableTimelimitTask taskclct =
                        TimelimitTaskController.this
                            .timelimittaskview
                            .getTimelimitTaskTableModel()
                            .getCollectable(iSelectedRow);
                    final TimelimitTaskVO taskvo = taskclct.getTimelimitTaskVO();
                    bFinished = Boolean.valueOf(taskvo.getCompleted() != null);
                    bHasGenericObject = Boolean.valueOf(taskvo.getGenericObjectId() != null);
                  }

                  final boolean bTaskSelected = !bSelectionEmpty;
                  final boolean bFinishedTaskSelected = bTaskSelected && bFinished.booleanValue();

                  actRemoveTask.setEnabled(bTaskSelected);
                  actPerformTask.setEnabled(bTaskSelected && bHasGenericObject.booleanValue());
                  actFinishTask.setEnabled(bTaskSelected);
                  timelimittaskview.getFinishButton().setSelected(bFinishedTaskSelected);
                }
              }
            });
  }
Esempio n. 5
0
/**
 * Controller for <code>TimelimitTaskView</code>. <br>
 * <br>
 * Created by Novabit Informationssysteme GmbH <br>
 * Please visit <a href="http://www.novabit.de">www.novabit.de</a>
 *
 * @author <a href="mailto:[email protected]">Uwe.Allner</a>
 * @version 01.00.00
 * @todo refactor (copied from PersonalTaskController)
 */
public class TimelimitTaskController extends RefreshableTaskController {

  private static final Logger LOG = Logger.getLogger(TimelimitTaskController.class);

  private static final String PREFS_NODE_TIMELIMITTASKS = "timelimitTasks";
  private static final String PREFS_NODE_SELECTEDFIELDS = "selectedFields";
  private static final String PREFS_NODE_SELECTEDFIELDWIDTHS = "selectedFieldWidths";
  private static final String PREFS_NODE_TIMELIMITTASKS_REFRESH_INTERVAL_SELECTED =
      "timelimitTasksRefreshSelected";

  /** popup menu for list of timelimit tasks */
  private final TimelimitTasksPopupMenu popupTimelimit;

  private final TimelimitTaskView timelimittaskview;

  private final TimelimitTaskDelegate tltaskDelegate;

  private ExplorerController ctlExplorer;

  private final Preferences prefs;

  private MainFrameTab tab;

  private final Action actPerformTask =
      new CommonAbstractAction(
          "Zugeordnete Objekte anzeigen",
          Icons.getInstance().getIconModule(),
          getSpringLocaleDelegate()
              .getMessage("TimelimitTaskController.16", "Zugeordnete Objekte anzeigen")) {

        @Override
        public void actionPerformed(ActionEvent ev) {
          TimelimitTaskController.this.cmdPerformTimelimitTask(timelimittaskview);
        }
      };

  private final Action actRemoveTask =
      new CommonAbstractAction(
          "L\u00f6schen...",
          Icons.getInstance().getIconDelete16(),
          getSpringLocaleDelegate()
              .getMessage("TimelimitTaskController.2", "Ausgew\u00e4hlte Frist l\u00f6schen")) {

        @Override
        public void actionPerformed(ActionEvent ev) {
          TimelimitTaskController.this.cmdRemoveTimelimitTask(timelimittaskview, true);
        }
      };

  private final Action actFinishTask =
      new CommonAbstractAction(
          "Erledigt",
          Icons.getInstance().getIconProperties16(),
          getSpringLocaleDelegate()
              .getMessage(
                  "TimelimitTaskController.1",
                  "Ausgew\u00e4hlte Frist als erledigt/unerledigt markieren")) {

        @Override
        public void actionPerformed(ActionEvent ev) {
          TimelimitTaskController.this.cmdFinishOrUnfinishTimelimitTask(timelimittaskview, true);
        }
      };

  final Action actPrint =
      new CommonAbstractAction(
          getSpringLocaleDelegate()
              .getMessage("TimelimitTaskController.11", "Fristenliste drucken"),
          Icons.getInstance().getIconPrintReport16(),
          null) {

        @Override
        public void actionPerformed(ActionEvent ev) {
          TimelimitTaskController.this.cmdPrintTimelimitTaskView();
        }
      };

  public TimelimitTaskController(Preferences prefsParent, TimelimitTaskDelegate tltaskDelegate) {
    super();

    this.timelimittaskview = new TimelimitTaskView();
    this.timelimittaskview.init();
    this.tltaskDelegate = tltaskDelegate;
    this.popupTimelimit = new TimelimitTasksPopupMenu(timelimittaskview);
    this.prefs = prefsParent.node(PREFS_NODE_TIMELIMITTASKS);

    this.timelimittaskview.setTimelimitTaskTableModel(newTimelimitTaskTableModel());

    final JTable tblTimelimit = timelimittaskview.getTable();
    tblTimelimit.setTableHeader(
        new ToolTipsTableHeader(
            this.timelimittaskview.getTimelimitTaskTableModel(), tblTimelimit.getColumnModel()));
    TableUtils.addMouseListenerForSortingToTableHeader(
        tblTimelimit,
        this.timelimittaskview.getTimelimitTaskTableModel(),
        new CommonRunnable() {
          @Override
          public void run() {
            timelimittaskview.getTimelimitTaskTableModel().sort();
            storeOrderBySelectedColumnToPreferences();
          }
        });

    /** todo calculate row height */
    tblTimelimit.setRowHeight(20);

    setupRenderers(tblTimelimit);
    setupColumnModelListener(tblTimelimit);
    setupActions(tblTimelimit);
    setupDataTransfer(tblTimelimit);
    setupTableModelSorting();

    KeyBinding keybinding = KeyBindingProvider.REFRESH;
    this.timelimittaskview
        .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
        .put(keybinding.getKeystroke(), keybinding.getKey());
    this.timelimittaskview
        .getActionMap()
        .put(
            keybinding.getKey(),
            new AbstractAction() {

              @Override
              public void actionPerformed(ActionEvent e) {
                TimelimitTaskController.this.cmdRefreshTimelimitTaskView();
              }
            });
  }

  private void setupRenderers(JTable table) {
    // setup a table cell renderer for each column:
    for (Enumeration<TableColumn> enumeration = table.getColumnModel().getColumns();
        enumeration.hasMoreElements(); ) {
      final TableColumn column = enumeration.nextElement();
      final int iModelIndex = column.getModelIndex();
      final CollectableEntityField clctef =
          this.timelimittaskview
              .getTimelimitTaskTableModel()
              .getCollectableEntityField(iModelIndex);
      final CollectableComponent clctcomp =
          CollectableComponentFactory.getInstance().newCollectableComponent(clctef, null, false);
      column.setCellRenderer(clctcomp.getTableCellRenderer(false));
    }
  }

  private void setupColumnModelListener(final JTable tbl) {
    tbl.getColumnModel()
        .addColumnModelListener(
            new TableColumnModelListener() {
              @Override
              public void columnAdded(TableColumnModelEvent ev) {
                // do nothing
              }

              @Override
              public void columnRemoved(TableColumnModelEvent ev) {
                // do nothing
              }

              @Override
              public void columnMoved(TableColumnModelEvent ev) {
                if (ev.getFromIndex() != ev.getToIndex()) {
                  try {
                    TimelimitTaskController.this.storeColumnOrder(tbl);
                  } catch (PreferencesException ex) {
                    final String sMessage =
                        getSpringLocaleDelegate()
                            .getMessage(
                                "TimelimitTaskController.7",
                                "Die Spaltenreihenfolge konnte nicht gespeichert werden.");
                    Errors.getInstance().showExceptionDialog(tbl, sMessage, ex);
                  }
                }
              }

              @Override
              public void columnMarginChanged(ChangeEvent ev) {
                try {
                  storeColumnWidthsInPrefs(tbl);
                } catch (PreferencesException ex) {
                  final String sMessage =
                      getSpringLocaleDelegate()
                          .getMessage(
                              "PersonalTaskController.28",
                              "Die Spaltenbreite konnte nicht gespeichert werden.");
                  Errors.getInstance().showExceptionDialog(tbl, sMessage, ex);
                }
              }

              @Override
              public void columnSelectionChanged(ListSelectionEvent ev) {
                // do nothing
              }
            });
  }

  public void storeIntervalTasksToPreferences() {
    final Integer[] refreshInterval = {
      new Integer((getSingleScheduledRefreshableView().getRefreshInterval()))
    };
    try {
      PreferencesUtils.putIntegerArray(
          prefs, PREFS_NODE_TIMELIMITTASKS_REFRESH_INTERVAL_SELECTED, refreshInterval);
    } catch (PreferencesException e1) {
      Errors.getInstance()
          .showExceptionDialog(
              this.getTabbedPane().getComponentPanel(),
              getSpringLocaleDelegate()
                  .getMessage(
                      "PersonalTaskController.18", "Fehler beim Abspeichern der Einstellungen"),
              e1);
    }
  }

  public void storeOrderBySelectedColumnToPreferences() {
    try {
      PreferencesUtils.writeSortKeysToPrefs(
          this.prefs, this.timelimittaskview.getTimelimitTaskTableModel().getSortKeys());
    } catch (PreferencesException e1) {
      Errors.getInstance()
          .showExceptionDialog(
              this.getTabbedPane().getComponentPanel(),
              getSpringLocaleDelegate()
                  .getMessage(
                      "PersonalTaskController.19", "Fehler beim Abspeichern der Einstellungen"),
              e1);
    }
  }

  private int readIntervalTasksFromPreferences() {
    List<Integer> refreshIntervalTasksSelectedList;
    try {
      refreshIntervalTasksSelectedList =
          PreferencesUtils.getIntegerList(
              prefs, PREFS_NODE_TIMELIMITTASKS_REFRESH_INTERVAL_SELECTED);
    } catch (PreferencesException ex) {
      LOG.error(
          getSpringLocaleDelegate()
              .getMessage(
                  "PersonalTaskController.10",
                  "Der Filterzustand konnte nicht aus den Einstellungen gelesen werden"),
          ex);
      return 0;
    }
    if (refreshIntervalTasksSelectedList.isEmpty()) return 0;
    return refreshIntervalTasksSelectedList.get(0);
  }

  /** stores the order of the columns in the table */
  private void storeColumnOrder(JTable tbl) throws PreferencesException {
    this.storeSelectedFieldNamesInPrefs(CollectableTableHelper.getFieldNamesFromColumns(tbl));
  }

  /** stores the selected columns (fields) in user preferences */
  private void storeSelectedFieldNamesInPrefs(List<String> lstSelectedFieldNames)
      throws PreferencesException {
    PreferencesUtils.putStringList(this.prefs, PREFS_NODE_SELECTEDFIELDS, lstSelectedFieldNames);
  }

  private void storeColumnWidthsInPrefs(JTable tbl) throws PreferencesException {
    PreferencesUtils.putIntegerList(
        this.prefs, PREFS_NODE_SELECTEDFIELDWIDTHS, CollectableTableHelper.getColumnWidths(tbl));
  }

  private void setupActions(final JTable table) {
    super.addRefreshIntervalActionsToSingleScheduledRefreshable();

    // assign popup menu:
    table.addMouseListener(new PopupMenuListener(this.popupTimelimit, table));

    // add mouse listeners for double click in table:
    table.addMouseListener(new DoubleClickListener(timelimittaskview));

    final Action actRefresh =
        new CommonAbstractAction(
            Icons.getInstance().getIconRefresh16(),
            getSpringLocaleDelegate()
                .getMessage("TimelimitTaskController.10", "Fristenliste aktualisieren")) {

          @Override
          public void actionPerformed(ActionEvent ev) {
            TimelimitTaskController.this.cmdRefreshTimelimitTaskView();
          }
        };

    actPerformTask.setEnabled(false);
    actRemoveTask.setEnabled(false);
    actFinishTask.setEnabled(false);

    timelimittaskview.getRefreshButton().setAction(actRefresh);
    timelimittaskview.getPerformMenuItem().setAction(actPerformTask);
    timelimittaskview.getRemoveMenuItem().setAction(actRemoveTask);
    timelimittaskview.getFinishButton().setAction(actFinishTask);
    timelimittaskview.getPrintMenuItem().setAction(actPrint);

    // use only action listener for "show finished" button:
    timelimittaskview.btnShowAllTasks.addActionListener(actRefresh);

    setRefreshIntervalForSingleViewRefreshable(readIntervalTasksFromPreferences());

    table
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              @Override
              public void valueChanged(ListSelectionEvent ev) {
                if (!ev.getValueIsAdjusting()) {
                  final ListSelectionModel lsm = (ListSelectionModel) ev.getSource();
                  final boolean bSelectionEmpty = lsm.isSelectionEmpty();
                  final Boolean bFinished;
                  final Boolean bHasGenericObject;

                  if (bSelectionEmpty) {
                    bFinished = null;
                    bHasGenericObject = null;
                  } else {
                    final int iSelectedRow =
                        TimelimitTaskController.this.timelimittaskview.getTable().getSelectedRow();
                    CollectableTimelimitTask taskclct =
                        TimelimitTaskController.this
                            .timelimittaskview
                            .getTimelimitTaskTableModel()
                            .getCollectable(iSelectedRow);
                    final TimelimitTaskVO taskvo = taskclct.getTimelimitTaskVO();
                    bFinished = Boolean.valueOf(taskvo.getCompleted() != null);
                    bHasGenericObject = Boolean.valueOf(taskvo.getGenericObjectId() != null);
                  }

                  final boolean bTaskSelected = !bSelectionEmpty;
                  final boolean bFinishedTaskSelected = bTaskSelected && bFinished.booleanValue();

                  actRemoveTask.setEnabled(bTaskSelected);
                  actPerformTask.setEnabled(bTaskSelected && bHasGenericObject.booleanValue());
                  actFinishTask.setEnabled(bTaskSelected);
                  timelimittaskview.getFinishButton().setSelected(bFinishedTaskSelected);
                }
              }
            });
  }

  private void setupDataTransfer(JTable table) {
    table.setTransferHandler(new TransferHandler(null));
  }

  private void setupTableModelSorting() {
    final TimelimitTaskTableModel tblmdl = this.timelimittaskview.getTimelimitTaskTableModel();
    if (tblmdl.getColumnCount() > 0) {
      List<SortKey> sortKeys = readColumnOrderFromPreferences();
      if (sortKeys.isEmpty()) {
        sortKeys =
            Collections.singletonList(
                new SortKey(
                    tblmdl.findColumnByFieldName(CollectableTask.FIELDNAME_SCHEDULED),
                    SortOrder.ASCENDING));
      }
      try {
        tblmdl.setSortKeys(sortKeys, false);
      } catch (Exception e) {
      }
    }
  }

  private TimelimitTaskTableModel newTimelimitTaskTableModel() {
    final TimelimitTaskTableModel result = new TimelimitTaskTableModel();

    // add columns:
    final List<String> lstFieldNames =
        new LinkedList<String>(CollectableTimelimitTask.clcte.getFieldNames());

    // sort using the order stored in the preferences:
    List<String> lstFieldNameOrderTemp;
    try {
      lstFieldNameOrderTemp = PreferencesUtils.getStringList(this.prefs, PREFS_NODE_SELECTEDFIELDS);
    } catch (PreferencesException ex) {
      LOG.error(
          "Failed to retrieve list of selected fields from the preferences. They will be empty.");
      lstFieldNameOrderTemp = new ArrayList<String>();
    }
    final List<String> lstFieldNameOrder = lstFieldNameOrderTemp;

    Collections.sort(
        lstFieldNames,
        new Comparator<String>() {
          private int getOrder(Object o) {
            int result = lstFieldNameOrder.indexOf(o);
            if (result == -1) {
              // new fields are shown at the end:
              result = lstFieldNameOrder.size();
            }
            return result;
          }

          @Override
          public int compare(String o1, String o2) {
            int iDiff = getOrder(o1) - getOrder(o2);
            return (iDiff == 0) ? 0 : (iDiff / Math.abs(iDiff));
          }
        });

    int iColumn = 0;
    final List<String> lstNamesOfFieldsToDisplay =
        CollectableTimelimitTask.clcte.getNamesOfFieldsToDisplay();
    for (Iterator<String> iter = lstFieldNames.iterator(); iter.hasNext(); ) {
      final String sFieldName = iter.next();
      final CollectableEntityField clctef =
          CollectableTimelimitTask.clcte.getEntityField(sFieldName);
      if (lstNamesOfFieldsToDisplay.contains(sFieldName)) {
        result.addColumn(iColumn++, clctef);
      }
    }

    if (result.getColumnCount() > 0) {
      result.setSortKeys(Collections.singletonList(new SortKey(0, SortOrder.ASCENDING)), false);
    }

    return result;
  }

  private void removeTimelimitTaskTab() {
    this.tab = null;
  }

  public void cmdShowTimelimitTasks() {
    if (tab == null) {
      UIUtils.runCommandForTabbedPane(
          this.getTabbedPane(),
          new Runnable() {
            @Override
            public void run() {
              try {
                showTimelimitTasks(new MainFrameTab());
                MainFrame.addTab(tab);
              } catch (Exception e) {
                LOG.error("cmdShowTimelimitTasks failed: " + e, e);
              }
            }
          });
    }

    MainFrame.setSelectedTab(tab);
  }

  public void showTimelimitTasks(MainFrameTab tab) {
    if (this.tab != null) {
      throw new IllegalArgumentException("Timelimit Tasks already shown");
    }
    tab.addMainFrameTabListener(
        new MainFrameTabAdapter() {
          @Override
          public void tabClosing(MainFrameTab tab, ResultListener<Boolean> rl) {
            removeTimelimitTaskTab();
            rl.done(true);
          }

          @Override
          public void tabClosed(MainFrameTab tab) {
            tab.removeMainFrameTabListener(this);
          }
        });

    tab.setTitle(getSpringLocaleDelegate().getMessage("tabTimelimits", "Fristen"));
    tab.setTabIconFromSystem("getIconTabTimtlimit");
    tab.setLayeredComponent(TimelimitTaskController.this.timelimittaskview);
    tab.setTabStoreController(
        new TaskController.TaskTabStoreController(
            TaskController.RestorePreferences.TIMELIMIT,
            TimelimitTaskController.this.timelimittaskview));
    TimelimitTaskController.this.tab = tab;
  }

  /**
   * finishes or "unfinishes" the selected task
   *
   * @param taskview
   * @param bRefresh Refresh the lists afterwards?
   */
  private void cmdFinishOrUnfinishTimelimitTask(
      final TimelimitTaskView taskview, final boolean bRefresh) {
    List<TimelimitTaskVO> lstSelectedTimelimitTasks = getSelectedTimelimitTasks(taskview);
    if (!lstSelectedTimelimitTasks.isEmpty() && lstSelectedTimelimitTasks != null) {
      final boolean bFinished = areTasksCompleted(lstSelectedTimelimitTasks);
      if (bFinished) {
        cmdUnfinishTimelimitTask(taskview, bRefresh);
      } else {
        cmdFinishTimelimitTask(taskview, bRefresh);
      }
    }
  }

  /**
   * "unfinishes" the selected tasks
   *
   * @param taskview
   * @param bRefresh Refresh the lists afterwards?
   */
  private void cmdUnfinishTimelimitTask(final TimelimitTaskView taskview, final boolean bRefresh) {
    final List<TimelimitTaskVO> lstSelectedTimelimitTasks = getSelectedTimelimitTasks(taskview);
    if (!lstSelectedTimelimitTasks.isEmpty() && lstSelectedTimelimitTasks != null) {

      final String sMessage =
          getSpringLocaleDelegate()
              .getMessage(
                  "TimelimitTaskController.12",
                  "Soll(en) die ausgew\u00e4hlte(n) Frist(e) als unerledigt markiert werden?");
      final int iBtn =
          JOptionPane.showConfirmDialog(
              this.getTabbedPane().getComponentPanel(),
              sMessage,
              getSpringLocaleDelegate()
                  .getMessage("TimelimitTaskController.9", "Friste als unerledigt markieren"),
              JOptionPane.YES_NO_OPTION);
      if (iBtn == JOptionPane.YES_OPTION) {
        UIUtils.runCommandForTabbedPane(
            this.getTabbedPane(),
            new Runnable() {
              @Override
              public void run() {
                try {
                  for (TimelimitTaskVO taskvo : lstSelectedTimelimitTasks)
                    tltaskDelegate.unfinish(taskvo);
                  if (bRefresh) {
                    refreshTimelimitTaskView();
                  }
                } catch (/* CommonBusiness */ Exception ex) {
                  Errors.getInstance().showExceptionDialog(getTabbedPane().getComponentPanel(), ex);
                }
              }
            });
      } else {
        // undo selection of the button:
        timelimittaskview.getFinishButton().setSelected(false);
      }
    }
  }

  /**
   * finishes the selected tasks
   *
   * @param taskview
   * @param bRefresh Refresh the lists afterwards?
   */
  private void cmdFinishTimelimitTask(final TimelimitTaskView taskview, final boolean bRefresh) {
    final List<TimelimitTaskVO> lstSelectedTimelimitTasks = getSelectedTimelimitTasks(taskview);
    if (!lstSelectedTimelimitTasks.isEmpty() && lstSelectedTimelimitTasks != null) {
      UIUtils.runCommandForTabbedPane(
          this.getTabbedPane(),
          new Runnable() {
            @Override
            public void run() {
              try {
                for (TimelimitTaskVO taskvo : lstSelectedTimelimitTasks)
                  taskvo = tltaskDelegate.finish(taskvo);
                if (bRefresh) {
                  refreshTimelimitTaskView();
                }
              } catch (/* CommonBusiness */ Exception ex) {
                Errors.getInstance().showExceptionDialog(getTabbedPane().getComponentPanel(), ex);
              }
            }
          });
    }
  }

  /**
   * removes the currently selected tasks
   *
   * @param taskview
   * @param bRefresh Refresh the lists afterwards?
   */
  private void cmdRemoveTimelimitTask(TimelimitTaskView taskview, final boolean bRefresh) {
    final List<TimelimitTaskVO> lstSelectedTimelimitTasks = getSelectedTimelimitTasks(taskview);

    if (!lstSelectedTimelimitTasks.isEmpty() && lstSelectedTimelimitTasks != null) {
      final String sMessage;
      if (lstSelectedTimelimitTasks.size() == 1)
        sMessage =
            getSpringLocaleDelegate()
                    .getMessage(
                        "TimelimitTaskController.14",
                        "Wollen Sie den ausgew\u00e4hlten Eintrag wirklich l\u00f6schen?")
                + "\n";
      else
        sMessage =
            getSpringLocaleDelegate()
                    .getMessage(
                        "TimelimitTaskController.15",
                        "Wollen Sie die ausgew\u00e4hlten Eintr\u00e4ge wirklich l\u00f6schen?")
                + "\n";

      final int btn =
          JOptionPane.showConfirmDialog(
              this.getTabbedPane().getComponentPanel(),
              sMessage,
              getSpringLocaleDelegate()
                  .getMessage("TimelimitTaskController.8", "Eintr\u00e4ge l\u00f6schen"),
              JOptionPane.YES_NO_OPTION);

      if (btn == JOptionPane.YES_OPTION) {
        UIUtils.runCommandForTabbedPane(
            this.getTabbedPane(),
            new Runnable() {
              @Override
              public void run() {
                try {
                  for (TimelimitTaskVO taskvo : lstSelectedTimelimitTasks)
                    TimelimitTaskController.this.tltaskDelegate.remove(taskvo);
                } catch (CommonBusinessException ex) {
                  Errors.getInstance().showExceptionDialog(getTabbedPane().getComponentPanel(), ex);
                }
                if (bRefresh) {
                  refreshTimelimitTaskView();
                }
              }
            });
      }
    }
  }

  private void cmdRefreshTimelimitTaskView() {
    UIUtils.runCommandForTabbedPane(
        this.getTabbedPane(),
        new Runnable() {
          @Override
          public void run() {
            refreshTimelimitTaskView();
          }
        });
  }

  private void cmdPrintTimelimitTaskView() {
    UIUtils.runCommandForTabbedPane(
        this.getTabbedPane(),
        new Runnable() {
          @Override
          public void run() {
            printTimelimitTaskView();
          }
        });
  }

  public void refreshTimelimitTaskView() {
    boolean bUnfinishedOnly = !this.timelimittaskview.btnShowAllTasks.getModel().isSelected();
    final Collection<TimelimitTaskVO> colltaskvo =
        this.tltaskDelegate.getTimelimitTasks(bUnfinishedOnly);
    final List<CollectableTimelimitTask> lstclct =
        CollectionUtils.transform(colltaskvo, new CollectableTimelimitTask.MakeCollectable());

    final TimelimitTaskTableModel tblmdl = this.timelimittaskview.getTimelimitTaskTableModel();
    tblmdl.setCollectables(lstclct);

    // TableUtils.setOptimalColumnWidths(this.timelimittaskview.getTable());
    TaskController.setColumnWidths(
        readColumnWidthsFromPreferences(), this.timelimittaskview.getTable());

    // todo: sorting order? / UA
    //		final int iColumnScheduled =
    // tblmdl.findColumnByFieldName(CollectableTimelimitTask.FIELDNAME_SCHEDULED);
    //		tblmdl.setSortingOrder(iColumnScheduled, true, true);

    //	NUCLOS-642
    setupRenderers(timelimittaskview.getTable());
  }

  private List<Integer> readColumnWidthsFromPreferences() {
    List<Integer> lstColumnWidths = null;
    try {
      lstColumnWidths = PreferencesUtils.getIntegerList(this.prefs, PREFS_NODE_SELECTEDFIELDWIDTHS);
    } catch (PreferencesException ex) {
      LOG.error("Die Spaltenbreite konnte nicht aus den Preferences geladen werden.", ex);
      return lstColumnWidths;
    }

    return lstColumnWidths;
  }

  private List<SortKey> readColumnOrderFromPreferences() {
    try {
      return PreferencesUtils.readSortKeysFromPrefs(this.prefs);
    } catch (PreferencesException ex) {
      LOG.error("The column order could not be loaded from preferences.", ex);
      return Collections.emptyList();
    }
  }

  void printTimelimitTaskView() {
    try {
      new ReportController(getTab()).export(this.timelimittaskview.getTable(), null);
    } catch (CommonBusinessException ex) {
      Errors.getInstance().showExceptionDialog(this.getTabbedPane().getComponentPanel(), ex);
    }
  }

  private void cmdPerformTimelimitTask(TimelimitTaskView taskview) {
    final List<TimelimitTaskVO> collSelectedTimilimitTasks = getSelectedTimelimitTasks(taskview);

    if (!collSelectedTimilimitTasks.isEmpty() && collSelectedTimilimitTasks != null) {
      UIUtils.runCommandForTabbedPane(
          this.getTabbedPane(),
          new CommonRunnable() {
            @Override
            public void run() throws CommonBusinessException {
              final Collection<Integer> collGenericObjectIds = new ArrayList<Integer>();

              Integer iCommonModuleId = new Integer(0);
              for (TimelimitTaskVO tovo : collSelectedTimilimitTasks) {
                collGenericObjectIds.add(tovo.getGenericObjectId().intValue());
                if (iCommonModuleId != null && !iCommonModuleId.equals(tovo.getModuleId())) {
                  if (iCommonModuleId.equals(0)) {
                    iCommonModuleId = tovo.getModuleId();
                  } else {
                    iCommonModuleId = null;
                  }
                }
              }

              if (collGenericObjectIds.size() == 1) {
                final GenericObjectCollectController ctlGenericObject =
                    NuclosCollectControllerFactory.getInstance()
                        .newGenericObjectCollectController(
                            iCommonModuleId,
                            null,
                            ClientParameterProvider.getInstance()
                                .getValue(ParameterProvider.KEY_LAYOUT_CUSTOM_KEY));
                ctlGenericObject.runViewSingleCollectableWithId(
                    collGenericObjectIds.iterator().next());
              } else if (iCommonModuleId != null && iCommonModuleId != 0) {
                final GenericObjectCollectController ctlGenericObject =
                    NuclosCollectControllerFactory.getInstance()
                        .newGenericObjectCollectController(
                            iCommonModuleId,
                            null,
                            ClientParameterProvider.getInstance()
                                .getValue(ParameterProvider.KEY_LAYOUT_CUSTOM_KEY));
                ctlGenericObject.runViewResults(
                    getSearchConditionForRelatedObjects(collGenericObjectIds));
              }
            }
          });
    } else {
      final String sMessage =
          getSpringLocaleDelegate()
              .getMessage("TimelimitTaskController.6", "Dieser Frist ist kein Objekt zugeordnet.");
      JOptionPane.showMessageDialog(
          taskview,
          sMessage,
          getSpringLocaleDelegate()
              .getMessage("TimelimitTaskController.18", "Zugeordnetes Objekt anzeigen"),
          JOptionPane.ERROR_MESSAGE);
    }
  }

  private List<TimelimitTaskVO> getSelectedTimelimitTasks(final TimelimitTaskView taskview) {
    final List<Integer> lstSelectedRowNumbers =
        CollectionUtils.asList(taskview.getTable().getSelectedRows());
    final List<TimelimitTaskVO> result =
        CollectionUtils.transform(
            lstSelectedRowNumbers,
            new Transformer<Integer, TimelimitTaskVO>() {
              @Override
              public TimelimitTaskVO transform(Integer iRowNo) {
                return taskview.getTimelimitTaskTableModel().getTimelimitTask(iRowNo);
              }
            });
    assert result != null;
    return result;
  }

  private boolean areTasksCompleted(List<TimelimitTaskVO> lsttaskvo) {
    for (TimelimitTaskVO taskvo : lsttaskvo) if (taskvo.getCompleted() == null) return false;

    return true;
  }

  private boolean existsRelatedObjectsFor(List<TimelimitTaskVO> lsttaskvo) {
    for (TimelimitTaskVO taskvo : lsttaskvo) if (taskvo.getGenericObjectId() == null) return false;

    return true;
  }

  /**
   * Build a search condition if there are more than one related objects
   *
   * @param collGenericObjectIds
   * @return OR condition over all related object ids
   */
  private CollectableSearchCondition getSearchConditionForRelatedObjects(
      Collection<Integer> collGenericObjectIds) {
    CompositeCollectableSearchCondition result =
        new CompositeCollectableSearchCondition(LogicalOperator.OR);

    for (Integer iId : collGenericObjectIds) {
      result.addOperand(new CollectableIdCondition(iId));
    }

    return result;
  }

  public void setExplorerController(ExplorerController ctlExplorer) {
    this.ctlExplorer = ctlExplorer;
  }

  public ExplorerController getExplorerController() {
    assert this.ctlExplorer != null;
    return this.ctlExplorer;
  }

  /** inner class: Popup menu for Timelimit tasks */
  private class TimelimitTasksPopupMenu extends JPopupMenu {
    /**
     * menu item: perform task (jump to leased object) todo must be disabled when there is no leased
     * object
     */
    private final JMenuItem miPerform = new JMenuItem();
    /** menu item: mark the task as finished (so it disappears from the task lists) */
    private final JCheckBoxMenuItem miFinish = new JCheckBoxMenuItem();
    /** menu item: delete task from the database */
    private final JMenuItem miRemove = new JMenuItem();

    public TimelimitTasksPopupMenu(final TimelimitTaskView taskview) {
      this.add(miPerform);
      this.add(miRemove);
      this.add(miFinish);

      miPerform.setAction(actPerformTask);
      miFinish.setAction(actFinishTask);
      miRemove.setAction(actRemoveTask);
    }
  } // inner class TimelimitTasksPopupMenu

  /**
   * inner class PopupMenuListener todo factor out (this is a reusable class) todo we have single
   * selection model in the task list
   */
  private class PopupMenuListener extends DefaultJPopupMenuListener {
    private final TimelimitTasksPopupMenu popupTimelimitTasks;
    private final JTable tblTasks;

    public PopupMenuListener(TimelimitTasksPopupMenu popupTasks, JTable tblTasks) {
      super(popupTasks);

      this.popupTimelimitTasks = popupTasks;
      this.tblTasks = tblTasks;
    }

    @Override
    protected void showPopupMenu(MouseEvent ev) {
      // first select/deselect the row:
      int iRow = tblTasks.rowAtPoint(ev.getPoint());

      // Nur, wenn nicht selektiert, selektieren:
      if (!tblTasks.isRowSelected(iRow)) {
        if ((ev.getModifiers() & MouseEvent.CTRL_MASK) != 0) {
          // Control gedr\u00fcckt:
          // Zeile zur Selektion hinzuf\u00fcgen:
          tblTasks.addRowSelectionInterval(iRow, iRow);
        } else {
          // Sonst nur diese Zeile selektieren:
          tblTasks.setRowSelectionInterval(iRow, iRow);
        }
      } // if

      // enable/disable menu items
      final int iSelectedRow = this.tblTasks.getSelectedRow();
      final TimelimitTaskTableModel model = timelimittaskview.getTimelimitTaskTableModel();
      model.getTimelimitTask(iSelectedRow);

      // todo: there should be a better place for that...
      final boolean bPerformEnabled =
          existsRelatedObjectsFor(getSelectedTimelimitTasks(timelimittaskview));
      actPerformTask.setEnabled(bPerformEnabled);
      // this.popupTimelimitTasks.miPerform.setEnabled(bPerformEnabled);

      final boolean bFinished = areTasksCompleted(getSelectedTimelimitTasks(timelimittaskview));
      this.popupTimelimitTasks.miFinish.setState(bFinished);

      super.showPopupMenu(ev);
    }
  } // inner class PopupMenuListener

  /** inner class DoubleClickListener */
  private class DoubleClickListener extends MouseAdapter {
    private final TimelimitTaskView taskview;

    public DoubleClickListener(TimelimitTaskView taskview) {
      this.taskview = taskview;
    }

    @Override
    public void mouseClicked(MouseEvent ev) {
      if (ev.getClickCount() == 2) {
        TimelimitTaskController.this.cmdPerformTimelimitTask(this.taskview);
      }
    }
  } // inner class DoubleClickListener

  /** inner class TransferHandler. Handles drag&drop, copy&paste for the Timelimit task list. */
  private class TransferHandler extends javax.swing.TransferHandler {

    private final Component parent;

    public TransferHandler(Component parent) {
      this.parent = parent;
    }

    @Override
    public int getSourceActions(JComponent comp) {
      return NONE;
    }

    @Override
    public boolean canImport(JComponent comp, DataFlavor[] aflavors) {
      // Unfortunately, this method is not called for each row, so we only can say yes or no
      // for the whole table here. We must say yes to enable drop at all.

      class IsGenericObjectFlavor implements Predicate<DataFlavor> {
        @Override
        public boolean evaluate(DataFlavor flavor) {
          return (flavor instanceof GenericObjectIdModuleProcess.DataFlavor);
        }
      }
      return CollectionUtils.exists(Arrays.asList(aflavors), new IsGenericObjectFlavor());
    }

    @Override
    public boolean importData(JComponent comp, Transferable transferable) {
      boolean result = false;

      if (comp instanceof JTable) {
        final JTable tbl = (JTable) comp;

        try {
          final int iSelectedRow = tbl.getSelectedRow();
          if (iSelectedRow != -1) {
            final TimelimitTaskTableModel tblmdl =
                TimelimitTaskController.this.timelimittaskview.getTimelimitTaskTableModel();
            final CollectableTimelimitTask clctTarget = tblmdl.getCollectable(iSelectedRow);
            final TimelimitTaskVO taskvoTarget = clctTarget.getTimelimitTaskVO();

            final GenericObjectIdModuleProcess goimp =
                (GenericObjectIdModuleProcess)
                    transferable.getTransferData(new GenericObjectIdModuleProcess.DataFlavor());

            if (taskvoTarget.getCompleted() != null) {
              final String sMessage =
                  getSpringLocaleDelegate()
                      .getMessage(
                          "TimelimitTaskController.5",
                          "Dieser Eintrag ist bereits abgeschlossen. Er kann nicht mehr ver\u00e4ndert werden.");
              throw new NuclosBusinessException(sMessage);
            }
            boolean bDoIt = (taskvoTarget.getGenericObjectId() == null);
            if (!bDoIt) {
              final String sQuestion =
                  getSpringLocaleDelegate()
                          .getMessage(
                              "TimelimitTaskController.13",
                              "Soll das Objekt \"{0}\" zugeordnet werden?",
                              goimp.getGenericObjectIdentifier())
                      + "\n"
                      + getSpringLocaleDelegate()
                          .getMessage(
                              "TimelimitTaskController.3",
                              "Die bestehende Zuordnung zu \"{0}\" wird dadurch aufgehoben.",
                              taskvoTarget.getIdentifier());
              final int iBtn =
                  JOptionPane.showConfirmDialog(
                      this.parent,
                      sQuestion,
                      getSpringLocaleDelegate()
                          .getMessage(
                              "TimelimitTaskController.17", "Zugeordnetes Objekt \u00e4ndern"),
                      JOptionPane.OK_CANCEL_OPTION);
              bDoIt = (iBtn == JOptionPane.OK_OPTION);
            }

            if (bDoIt) {
              taskvoTarget.setGenericObjectId(new Integer(goimp.getGenericObjectId()));
              final TimelimitTaskVO taskvoUpdated = tltaskDelegate.update(taskvoTarget);
              tblmdl.setCollectable(iSelectedRow, new CollectableTimelimitTask(taskvoUpdated));
              result = true;
            }
          }
        } catch (UnsupportedFlavorException ex) {
          JOptionPane.showMessageDialog(
              parent,
              getSpringLocaleDelegate()
                  .getMessage(
                      "TimelimitTaskController.4",
                      "Dieser Datentransfer wird von dem ausgew\u00e4hlten Objekt nicht unterst\u00fctzt."));
        } catch (IOException ex) {
          throw new NuclosFatalException(ex);
        } catch (CommonBusinessException ex) {
          Errors.getInstance().showExceptionDialog(parent, ex);
        }
      }

      return result;
    }
  }

  @Override
  public ScheduledRefreshable getSingleScheduledRefreshableView() {
    return this.timelimittaskview;
  }

  @Override
  public void refreshScheduled(ScheduledRefreshable isRefreshable) {
    refreshTimelimitTaskView();
  }

  /** @return */
  public MainFrameTab getTab() {
    return tab;
  }
} // class TimelimitTaskController