예제 #1
0
 public void notifyTransactions(Iterable<TransactionDomainEvents> transactions) {
   // on usecase delete no update necessary
   if (matches(withUsecases("delete"), transactions)) {
     if (matches(withNames("removedAttachment"), transactions)) attachmentsModel.refresh();
     else return;
   } else if (matches(withNames("changedStatus", "addedAttachment"), transactions))
     attachmentsModel.refresh();
 }
예제 #2
0
  @Action
  public Task remove() {
    ConfirmationDialog dialog = module.objectBuilderFactory().newObject(ConfirmationDialog.class);
    dialog.setRemovalMessage(
        i18n.text(
            attachments.getSelectedRows().length > 1
                ? WorkspaceResources.attachments
                : WorkspaceResources.attachment));
    dialogs.showOkCancelHelpDialog(this, dialog, i18n.text(StreamflowResources.confirmation));

    if (dialog.isConfirmed()) {
      final List<AttachmentDTO> removedAttachments = new ArrayList<AttachmentDTO>();
      for (int i : attachments.getSelectedRows()) {
        removedAttachments.add(
            attachmentsModel.getEventList().get(attachments.convertRowIndexToModel(i)));
      }

      return new CommandTask() {
        @Override
        public void command() throws Exception {

          for (AttachmentDTO removedAttachment : removedAttachments) {
            attachmentsModel.removeAttachment(removedAttachment);
          }
        }
      };
    } else return null;
  }
예제 #3
0
  @Action(block = Task.BlockingScope.APPLICATION)
  public Task open() throws IOException {
    for (int i : attachments.getSelectedRows()) {
      AttachmentDTO attachment =
          attachmentsModel.getEventList().get(attachments.convertRowIndexToModel(i));

      return new OpenAttachmentTask(
          attachment.text().get(), attachment.href().get(), this, attachmentsModel, dialogs);
    }

    return null;
  }
예제 #4
0
  public AttachmentsView(@Service ApplicationContext context, @Uses AttachmentsModel model) {
    setLayout(new BorderLayout());

    final ActionMap am = context.getActionMap(this);

    this.attachmentsModel = model;
    TableFormat tableFormat = new AttachmentsTableFormatter();
    tableModel = new EventJXTableModel<AttachmentDTO>(attachmentsModel.getEventList(), tableFormat);

    attachments = new JXTable(tableModel);

    attachments.setFocusTraversalKeys(
        KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
        KeyboardFocusManager.getCurrentKeyboardFocusManager()
            .getDefaultFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
    attachments.setFocusTraversalKeys(
        KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
        KeyboardFocusManager.getCurrentKeyboardFocusManager()
            .getDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));

    attachments.getColumn(0).setPreferredWidth(20);
    attachments.getColumn(0).setMaxWidth(20);
    attachments.getColumn(0).setResizable(false);
    attachments.getColumn(2).setPreferredWidth(100);
    attachments.getColumn(2).setMaxWidth(100);
    attachments.getColumn(3).setPreferredWidth(100);
    attachments.getColumn(3).setMaxWidth(100);

    attachments.setAutoCreateColumnsFromModel(false);

    attachments.addHighlighter(HighlighterFactory.createAlternateStriping());

    attachments.setModel(tableModel);
    attachments.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    JPanel toolbar = new JPanel();
    StreamflowButton addButton = new StreamflowButton(am.get("add"));
    toolbar.add(addButton);
    StreamflowButton removeButton = new StreamflowButton(am.get("remove"));
    toolbar.add(removeButton);
    final StreamflowButton openButton = new StreamflowButton(am.get("open"));
    toolbar.add(openButton);
    attachments
        .getSelectionModel()
        .addListSelectionListener(new SelectionActionEnabler(am.get("open")));
    attachments
        .getSelectionModel()
        .addListSelectionListener(
            new SelectionActionEnabler(am.get("remove")) {

              @Override
              public boolean isSelectedValueValid(javax.swing.Action action) {
                return !attachments
                    .getValueAt(attachments.convertRowIndexToModel(attachments.getSelectedRow()), 0)
                    .equals(Icons.formSubmitted);
              }
            });

    attachmentsModel.addObserver(
        new RefreshComponents().visibleOn("createattachment", addButton, removeButton));

    attachments.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "open");
    attachments.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "remove");
    attachments.setActionMap(am);

    attachments.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent me) {
            int obj = attachments.getSelectedRow();
            if (obj == -1) return;
            if (me.getClickCount() == 2) {
              am.get("open")
                  .actionPerformed(
                      new ActionEvent(openButton, ActionEvent.ACTION_PERFORMED, "open"));
              me.consume();
            }
          }
        });

    attachments
        .getColumn(0)
        .setCellRenderer(
            new DefaultTableCellRenderer() {
              @Override
              public Component getTableCellRendererComponent(
                  JTable table,
                  Object value,
                  boolean isSelected,
                  boolean hasFocus,
                  int row,
                  int column) {

                JLabel iconLabel = new JLabel(" ");
                switch ((Icons) value) {
                  case attachments:
                    iconLabel = new JLabel(i18n.icon((Icons) value, 11));
                    break;

                  case conversations:
                    iconLabel = new JLabel(i18n.icon((Icons) value, 11));
                    break;

                  case formSubmitted:
                    iconLabel = new JLabel(i18n.icon((Icons) value, 11));
                    break;
                }

                iconLabel.setOpaque(true);

                if (isSelected) iconLabel.setBackground(attachments.getSelectionBackground());
                return iconLabel;
              }
            });

    JScrollPane attachmentsScrollPane = new JScrollPane(attachments);

    add(attachmentsScrollPane, BorderLayout.CENTER);
    add(toolbar, BorderLayout.SOUTH);

    new RefreshWhenShowing(this, attachmentsModel);
  }