Ejemplo n.º 1
0
  /** Die Methode speichert den Inhalt des Text Felder in die Datenbank */
  private boolean addToDB() {
    myFrame.setCursorWait();
    Vector<ContainerAttribute> myAtt = new Vector<ContainerAttribute>();
    String objKey = ReqField.get(0).getText();

    if (objKey.isEmpty() == false) {
      for (int i = 1; i < ReqField.size(); i++) {
        if (ReqField.get(i).getAtt().size() != 0 && ReqField.get(i).getText().isEmpty() == false) {
          myAtt.addAll(ReqField.get(i).getAtt());
        }
      }
      for (int i = 0; i < OptField.size(); i++) {
        if (OptField.get(i).getAtt().size() != 0 && OptField.get(i).getText().isEmpty() == false) {
          myAtt.addAll(OptField.get(i).getAtt());
        }
      }
      int ret = -1;

      // New Entry
      if (isNewEntry == true) {
        if (theDb.getObject(objKey) == null) {
          ret =
              theDb.setObject(
                  new ContainerObject(
                      -1, theDb.convTypeNameToTypeId(this.entryTypeString), objKey, myAtt));
        } else {
          JOptionPane.showMessageDialog(
              null,
              Main.myLang.getString(Main.myLang.getString("textFildTab.existingkey.message")),
              Main.myLang.getString(Main.myLang.getString("textFildTab.existingkey.title")),
              JOptionPane.ERROR_MESSAGE);
        }
      }
      // Edit Entry
      else {
        if (theDb.getObject(objKey) != null) {
        } else {
          JOptionPane.showMessageDialog(
              null,
              Main.myLang.getString(Main.myLang.getString("textFildTab.changedkey.message")),
              Main.myLang.getString(Main.myLang.getString("textFildTab.changedkey.title")),
              JOptionPane.WARNING_MESSAGE);
        }
        ret =
            theDb.setObject(
                new ContainerObject(
                    obj.getId(), theDb.convTypeNameToTypeId(this.entryTypeString), objKey, myAtt));
      }

      // file into DB
      if (ret != -1) {
        try {
          theDb.setAllFiles(this.fileModel.getData(), ret);
          obj = theDb.getObject(ret);
          myFrame.setCursorNormal();
          return true;
        } catch (PacketTooBigException e) {
          JOptionPane.showMessageDialog(
              null,
              Main.myLang.getString(Main.myLang.getString("textFildTab.FileSizeToSmall.message")),
              Main.myLang.getString(Main.myLang.getString("textFildTab.FileSizeToSmall.title")),
              JOptionPane.ERROR_MESSAGE);
          myFrame.setCursorNormal();
        }
      }
      myFrame.setCursorNormal();
      return false;
    } else {
      JOptionPane.showMessageDialog(
          null,
          Main.myLang.getString(Main.myLang.getString("textFildTab.missingKey.message")),
          Main.myLang.getString(Main.myLang.getString("textFildTab.missingKey.title")),
          JOptionPane.ERROR_MESSAGE);
      myFrame.setCursorNormal();
      return false;
    }
  }
Ejemplo n.º 2
0
  private JPanel getFilePanel(String typeName, Undomanager manager) {
    // PopupMenu init
    tablePopupMenu = new JPopupMenu();
    JMenuItem tableOpenItem = new JMenuItem("Open");

    tableOpenItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            openFile(rightClickedElement);
          }
        });
    tablePopupMenu.add(tableOpenItem);

    // Main Panel init
    JPanel textFieldPanel = new JPanel();
    JLabel typeLabel = new JLabel(typeName, JLabel.CENTER);
    typeLabel.setPreferredSize(new Dimension(150, 35));

    // Tabel Init
    if (isNewEntry == false) {
      fileTable = new JTable(new FileTableModel(theDb.getAllFiles(obj.getId())));
    } else {
      fileTable = new JTable(new FileTableModel(new Vector<ContainerFile>()));
    }
    fileModel = (FileTableModel) fileTable.getModel();
    fileTable.getTableHeader().setReorderingAllowed(false);
    TableColumn col = fileTable.getColumnModel().getColumn(0);
    col.setMinWidth(25);
    col.setMaxWidth(50);
    col.setPreferredWidth(25);
    col = fileTable.getColumnModel().getColumn(3);
    col.setMinWidth(35);
    col.setMaxWidth(50);
    col.setPreferredWidth(35);

    // Listener f�r clicks on file Table
    // Double-Click => Open Edit Fild
    // Right-Click => Context Menu => Open
    fileTable.addMouseListener(
        new MouseAdapter() {
          public void mousePressed(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON3 && fileTable.rowAtPoint(e.getPoint()) != -1) {
              rightClickedElement =
                  (ContainerFile) fileModel.getDataAt(fileTable.rowAtPoint(e.getPoint()));
              tablePopupMenu.show(e.getComponent(), e.getX(), e.getY());
            } else if (e.getButton() == MouseEvent.BUTTON1
                && e.getClickCount() == 2
                && fileTable.rowAtPoint(e.getPoint()) != -1) {
              new FileDialog(
                  fileModel,
                  (ContainerFile) fileModel.getDataAt(fileTable.rowAtPoint(e.getPoint())),
                  fileTable.rowAtPoint(e.getPoint()),
                  myFrame);
            }
          }
        });

    // Scrollpane init
    JScrollPane scrollPane = new javax.swing.JScrollPane();
    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setViewportView(fileTable);
    scrollPane.setPreferredSize(new Dimension(0, 100));

    // Button init
    JButton add =
        new JButton(new ImageIcon(getClass().getClassLoader().getResource("images/add.png")));
    add.setToolTipText(Main.myLang.getString("button.add"));
    add.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            new FileDialog(fileModel, ((Component) myFrame));
          }
        });
    JButton del = new JButton(new ImageIcon("images/delete.png"));
    del.setToolTipText(Main.myLang.getString("button.delete"));
    del.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            int selectedRow = fileTable.getSelectedRow();
            if (selectedRow != -1) {
              fileModel.removeData(selectedRow);
              // TODO:
            }
            fileModel.fireTableDataChanged();
            fileTable.repaint();
          }
        });
    JButton open =
        new JButton(new ImageIcon(getClass().getClassLoader().getResource("images/folder.png")));
    open.setToolTipText(Main.myLang.getString("button.open"));
    open.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (fileTable.getSelectedRow() != -1) {
              openFile(((ContainerFile) fileModel.getDataAt(fileTable.getSelectedRow())));
            }
          }
        });

    // Toolbar init
    JToolBar buttonBar = new JToolBar();
    buttonBar.setOrientation(VERTICAL);
    buttonBar.setFloatable(false);
    buttonBar.add(add);
    buttonBar.add(del);
    buttonBar.add(open);

    // Zusammenf�gen
    textFieldPanel.setLayout(new BoxLayout(textFieldPanel, BoxLayout.LINE_AXIS));
    textFieldPanel.setBorder(BorderFactory.createRaisedBevelBorder());
    textFieldPanel.add(typeLabel);
    textFieldPanel.add(scrollPane);
    textFieldPanel.add(buttonBar);
    textFieldPanel.validate();
    return textFieldPanel;
  }
Ejemplo n.º 3
0
  /**
   * Die Methode initialisiert Text Areas
   *
   * @return gui.CTex_TextArea
   */
  private TextArea getTextArea(
      boolean isRequired,
      final String typeName,
      Undomanager manager,
      final JButton addObject,
      final JButton addCondition) {

    final TextArea TextArea;
    ContainerAttribute e = null;
    Vector<ContainerAttribute> attV = new Vector<ContainerAttribute>();
    if (obj != null) {
      // wenn ein aus Objekt
      if (entryTypeKeyVar == typeName) {
        attV.add(
            new ContainerAttribute(-1, -1, obj.getKey(), false, new Vector<ContainerAttribute>()));
        TextArea = new TextArea(theDb, entryTypeKeyVar, attV, this);

      } else {
        Vector<ContainerAttribute> v = obj.getAttributes();
        Iterator<ContainerAttribute> i = v.iterator();
        // load Attribute
        attV.clear();
        while (i.hasNext()) {
          e = i.next();
          if (theDb.convTypeIdToTypeName(e.getObjectTypeId()).equals(typeName)) {
            attV.add(e);
          }
        }
        // if has Value or not
        if (attV.size() != 0) {
          TextArea =
              new TextArea(
                  theDb, theDb.convTypeIdToTypeName(attV.get(0).getObjectTypeId()), attV, this);
        } else {
          attV.add(
              new ContainerAttribute(
                  -1,
                  theDb.convTypeNameToTypeId(typeName),
                  "",
                  false,
                  new Vector<ContainerAttribute>()));
          TextArea = new TextArea(theDb, typeName, attV, this);
        }
      }
    } else {
      TextArea = new TextArea(theDb, typeName, attV, this);
    }

    // action of addObject "Objecte werden Gelb markiert und Links Weis"
    addObject.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent obj) {
            TextArea.setObject();
          }
        });

    // action of addCondition "Condition werden Grun markiert"
    addCondition.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent con) {
            TextArea.addCondition();
          }
        });

    if (!isRequired) {
      OptField.add(TextArea);
      addTextFieldOpt(OptField.get(OptField.size() - 1), manager);
      this.OptAreaId++;
    } else {
      ReqField.add(TextArea);
      addTextFieldReq(ReqField.get(ReqField.size() - 1), manager);
      this.ReqAreaId++;
    }

    // Save TextAreas for AutoGeneration Key
    if (typeName.equals("author")) {
      this.autor = TextArea;
    } else if (typeName.equals("year")) {
      this.year = TextArea;
    }

    return TextArea;
  }
Ejemplo n.º 4
0
  /**
   * Construktor: Initialisiert CTex_TextFieldTab mit dem uebergebnen Objekt aus dem Datenbank
   *
   * @return gui.CTex_TextFieldTab
   */
  EntryPanel(
      Db theDb, TabPanel inTab, final Undomanager manager, ContainerObject obj, Frame frame) {

    tableTab = inTab;
    isNewEntry = false;
    this.obj = obj;
    this.theDb = theDb;
    this.myTabPane = this;
    this.myFrame = frame;
    this.entryTypeString = theDb.convTypeIdToTypeName(obj.getTypeId());
    this.entryType = theDb.getType(entryTypeString);

    // Close dialog when pressing ESC
    tableTab.registerKeyboardAction(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            tableTab.showPreviewPane();
          }
        },
        KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
        JComponent.WHEN_IN_FOCUSED_WINDOW);

    // Auf Tab Mous Listner Legen.
    addMouseListener(
        new MouseAdapter() {
          public void mousePressed(MouseEvent e) {

            // Tab Nummer holen
            int tabNumber = getUI().tabForCoordinate(EntryPanel.this, e.getX(), e.getY());

            // Wenn Tab 0 dann Requiedfield sonst OptionsField
            if (tabNumber == 0) {
              // Manager auf ReqField den feld setzen
              ReqOROpt = true;
              ReqAreaId = 0;
              manager.setActivManager(
                  myReqField,
                  myOptField,
                  null,
                  myReqCompound,
                  myOptCompound,
                  null,
                  ReqOROpt,
                  false);
              // Area Tab Einstellungen
              ReqField.get(ReqAreaId).setCaretPosition(0);
              ReqField.get(ReqAreaId).requestFocus(true);
              /* set Color of new Area */
              // ReqField.get(ReqAreaId).setFocusBackground();

            } else if (tabNumber == 1) {
              ReqOROpt = false;
              OptAreaId = 1;
              // Manager auf OptField setzen
              manager.setActivManager(
                  myReqField,
                  myOptField,
                  null,
                  myReqCompound,
                  myOptCompound,
                  null,
                  ReqOROpt,
                  false);
              // Area Tab Einstellungen
              OptField.get(OptAreaId).setCaretPosition(0);
              OptField.get(OptAreaId).requestFocus(true);
              /* set Color of new Area */
              // OptField.get(OptAreaId).setFocusBackground();
            }
          }
        });
    // Manager auf selekted Tab setzen
    manager.setActivManager(
        myReqField, myOptField, null, myReqCompound, null, myOptCompound, ReqOROpt, false);

    // "Requeds Field" u. "Optional Fields" Tabs einfuegen
    this.addTab("Required fields", getReqTextField(manager));
    this.addTab("Optional fields", getOptTextField(manager));

    this.ReqAreaId = 0;
    this.OptAreaId = 0;
    this.ReqOROpt = true;
  }