Search in sources :

Example 1 with AttributePlugin

use of com.ramussoft.gui.common.AttributePlugin in project ramus by Vitaliy-Yakovchuk.

the class RowTreeTableModel method getValueAt.

@Override
public Object getValueAt(Object node, int index) {
    TreeTableNode tableRow = (TreeTableNode) node;
    if (tableRow instanceof GroupNode) {
        if (index == 0) {
            GroupNode groupNode = (GroupNode) tableRow;
            if (table != null) {
                Attribute attribute = groupNode.getAttribute();
                if (attribute != null) {
                    AttributePlugin plugin = framework.findAttributePlugin(attribute);
                    TableCellRenderer renderer = plugin.getTableCellRenderer(rowSet.getEngine(), framework.getAccessRules(), attribute);
                    if (renderer != null) {
                        try {
                            Component c = renderer.getTableCellRendererComponent(table, groupNode.getValue(), false, false, -1, -1);
                            if (c instanceof JLabel)
                                return ((JLabel) c).getText();
                        } catch (Exception e) {
                        // e.printStackTrace();
                        }
                    }
                }
            }
            return groupNode.getValue();
        }
        return null;
    }
    return localizers[index].getValue(valueGetters[index].getValue(tableRow, index));
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) AttributePlugin(com.ramussoft.gui.common.AttributePlugin) Attribute(com.ramussoft.common.Attribute) JLabel(javax.swing.JLabel) Component(java.awt.Component)

Example 2 with AttributePlugin

use of com.ramussoft.gui.common.AttributePlugin in project ramus by Vitaliy-Yakovchuk.

the class AttributePreferenciesDialog method init.

private void init() {
    double[][] size = { { DIV_SPACE, TableLayout.MINIMUM, DIV_SPACE, TableLayout.FILL, DIV_SPACE }, { DIV_SPACE, TableLayout.FILL, DIV_SPACE, TableLayout.FILL, DIV_SPACE } };
    AttributeType[] attributeTypes = engine.getAttributeTypes();
    LocalizedType[] types = new LocalizedType[attributeTypes.length];
    for (int i = 0; i < types.length; i++) {
        AttributeType type = attributeTypes[i];
        AttributePlugin plugin = framework.findAttributePlugin(type);
        types[i] = new LocalizedType(plugin.getString("AttributeType." + type.toString()), type);
    }
    Arrays.sort(types);
    for (LocalizedType type : types) {
        if (type.toString().length() > 0)
            typeComboBox.addItem(type);
    }
    JPanel panel = new JPanel(new TableLayout(size));
    panel.add(new JLabel(getString("AttributeName")), "1, 1");
    panel.add(nameField, "3, 1");
    panel.add(new JLabel(getString("AttributeTypeName")), "1, 3");
    panel.add(typeComboBox, "3, 3");
    typeComboBox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                SwingUtilities.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        updateAdditionalOptions();
                    }
                });
            }
        }
    });
    mainPanel = new JPanel(new BorderLayout());
    contentPanel.add(panel, BorderLayout.NORTH);
    mainPanel.add(contentPanel, BorderLayout.CENTER);
    postInit();
    this.setMainPane(mainPanel);
    pack();
    setLocationRelativeTo(null);
    int x = Options.getInteger("AttributePreferenciesDialog.X", getLocation().x);
    int y = Options.getInteger("AttributePreferenciesDialog.Y", getLocation().y);
    setLocation(x, y);
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            updateAdditionalOptions();
        }
    });
}
Also used : JPanel(javax.swing.JPanel) ItemEvent(java.awt.event.ItemEvent) AttributePlugin(com.ramussoft.gui.common.AttributePlugin) JLabel(javax.swing.JLabel) BorderLayout(java.awt.BorderLayout) AttributeType(com.ramussoft.common.AttributeType) ItemListener(java.awt.event.ItemListener) TableLayout(info.clearthought.layout.TableLayout)

Example 3 with AttributePlugin

use of com.ramussoft.gui.common.AttributePlugin in project ramus by Vitaliy-Yakovchuk.

the class AttributeEditorDialog method init.

protected void init(Engine engine, Attribute attribute, Element element, GUIFramework framework, AccessRules rules, Object value) {
    String t = GlobalResourcesManager.getString("AttributeEditorDialog.Title") + " - ";
    String name = framework.getSystemAttributeName(attribute);
    if (name == null)
        name = attribute.getName();
    setTitle(t + element.getName() + " | " + name);
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    panel = new AttributeEditorPanel() {

        /**
         */
        private static final long serialVersionUID = 1L;

        @Override
        protected void close() {
            super.close();
            AttributeEditorDialog.this.setVisible(false);
            AttributeEditorDialog.this.closed();
        }

        @Override
        protected String getSavePrefix() {
            return "1";
        }

        @Override
        public boolean apply() {
            boolean apply = super.apply();
            if (apply)
                onApply(this.value);
            return apply;
        }
    };
    AttributePlugin p = framework.findAttributePlugin(attribute);
    attributeEditor = p.getAttributeEditor(engine, rules, element, attribute, "attributeEditorDialog", null);
    panel.setAttributeEditor(attributeEditor, engine, attribute, element, rules.canUpdateElement(element.getId(), attribute.getId()), value);
    JPanel panel = new JPanel(new BorderLayout()) {

        /**
         */
        private static final long serialVersionUID = -8409626746568642304L;

        @Override
        protected boolean processKeyBinding(final KeyStroke ks, final KeyEvent e, final int condition, final boolean pressed) {
            if (!ks.isOnKeyRelease() && ks.getKeyCode() == KeyEvent.VK_ENTER && e.isControlDown()) {
                AttributeEditorDialog.this.panel.ok();
                return false;
            }
            if (!ks.isOnKeyRelease() && ks.getKeyCode() == KeyEvent.VK_ESCAPE) {
                AttributeEditorDialog.this.panel.cancel();
                return false;
            }
            return super.processKeyBinding(ks, e, condition, pressed);
        }
    };
    panel.add(this.panel, BorderLayout.CENTER);
    Action[] actions = attributeEditor.getActions();
    if (actions.length > 0) {
        JToolBar bar = new JToolBar();
        for (Action action : actions) if (action != null) {
            String command = (String) action.getValue(Action.ACTION_COMMAND_KEY);
            JButton button = bar.add(action);
            button.setFocusable(false);
            if (action.getValue(Action.SHORT_DESCRIPTION) == null) {
                String text = null;
                text = p.getString(command);
                if (text == null) {
                    StringGetter getter = (StringGetter) action.getValue(StringGetter.ACTION_STRING_GETTER);
                    if (getter != null)
                        text = getter.getString(command);
                    else
                        text = GlobalResourcesManager.getString(command);
                }
                if (text != null)
                    button.setToolTipText(text);
            }
        } else
            bar.addSeparator();
        panel.add(bar, BorderLayout.NORTH);
    }
    this.setContentPane(panel);
    setEditsAction(panel);
    pack();
    setLocationRelativeTo(null);
    Options.loadOptions(this);
    this.panel.loadPreferences();
    this.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosed(WindowEvent e) {
            AttributeEditorDialog.this.panel.cancel();
            Options.saveOptions(AttributeEditorDialog.this);
        }
    });
}
Also used : JPanel(javax.swing.JPanel) Action(javax.swing.Action) AttributePlugin(com.ramussoft.gui.common.AttributePlugin) JButton(javax.swing.JButton) WindowAdapter(java.awt.event.WindowAdapter) JToolBar(javax.swing.JToolBar) StringGetter(com.ramussoft.gui.common.StringGetter) KeyEvent(java.awt.event.KeyEvent) BorderLayout(java.awt.BorderLayout) WindowEvent(java.awt.event.WindowEvent) KeyStroke(javax.swing.KeyStroke)

Example 4 with AttributePlugin

use of com.ramussoft.gui.common.AttributePlugin in project ramus by Vitaliy-Yakovchuk.

the class ModelsPanel method init.

private void init() {
    tree = new RowTreeTableComponent(engine, IDEF0Plugin.getModelTree(engine), framework.getAccessRules(), new ModelRowCreator(), new Attribute[] { StandardAttributesPlugin.getAttributeNameAttribute(engine) }, framework) {

        @Override
        protected RowTreeTableModel createRowTreeTableModel(final Engine engine, Qualifier qualifier, AccessRules accessRules, RootCreater rootCreater, Attribute[] attributes, GUIFramework framework) {
            RowTreeTableModel rowTreeTableModel = new RowTreeTableModel(engine, qualifier, attributes, accessRules, rootCreater, framework) {

                @Override
                protected RowNode newRowNode(Row row) {
                    Long id = (Long) row.getAttribute(StandardAttributesPlugin.getAttributeQualifierId(engine));
                    if (id != null) {
                        Qualifier qualifier = engine.getQualifier(id);
                        if (qualifier != null) {
                            ModelsNode node = newModelsNode(row, qualifier);
                            node.getTreeTableModel().setTable(tree.getTable());
                            node.getTreeTableModel().setModelSupport(tree.getModel().getModelSupport());
                            return node;
                        }
                    }
                    return super.newRowNode(row);
                }

                @Override
                public boolean isCellEditable(Object node, int column) {
                    if (super.isCellEditable(node, column)) {
                        if (node instanceof ModelsNode)
                            return true;
                    }
                    return false;
                }
            };
            return rowTreeTableModel;
        }

        @Override
        protected RowTreeTable createTable(AccessRules accessRules, GUIFramework framework, AttributePlugin[] plugins) {
            return new RowTreeTable(accessRules, model.getRowSet(), plugins, framework, model) {

                long treeModelsId = IDEF0Plugin.getModelTree(engine).getId();

                @Override
                public Transferable createTransferable() {
                    final int[] is = getSelectedRows();
                    final ArrayList<Integer> al = new ArrayList<Integer>();
                    long id = IDEF0Plugin.getModelTree(engine).getId();
                    Rows rows = new Rows();
                    for (final int i : is) {
                        al.add(i);
                        TreeTableNode node = (TreeTableNode) getPathForRow(i).getLastPathComponent();
                        if ((node != null) && (node.getRow() != null)) {
                            Row row = node.getRow();
                            rows.add(row);
                            if (row.getElement().getQualifierId() != id)
                                return null;
                        }
                    }
                    exporting = true;
                    return new ArrayTransferable(al, rows);
                }

                @Override
                public boolean importData(Transferable t, boolean on, int aIndex) {
                    int index = aIndex;
                    long id = IDEF0Plugin.getModelTree(engine).getId();
                    if (index >= getRowCount())
                        index--;
                    if (index < 0)
                        return false;
                    TreeTableNode node = (TreeTableNode) getPathForRow(index).getLastPathComponent();
                    if (node.getRow() != null)
                        if (node.getRow().getElement().getQualifierId() != id)
                            return false;
                    return super.importData(t, on, aIndex);
                }

                @Override
                protected Icon getDefaultIcon(Row row) {
                    if (row.getElement().getQualifierId() != treeModelsId) {
                        if (row.getChildCount() == 0)
                            return note;
                        else
                            return function;
                    }
                    if (row.getAttribute(StandardAttributesPlugin.getAttributeQualifierId(engine)) == null)
                        return null;
                    return ModelsPanel.this.model;
                }
            };
        }
    };
    fixTable((TreeTableNode) tree.getModel().getRoot());
    tree.getTable().addMouseListener(new MouseAdapter() {

        private int[] lastSelectedRows;

        private long lastClickTime;

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON1) {
                if ((e.getClickCount() % 2 == 0) && (e.getClickCount() > 0)) {
                    openDiagram();
                } else {
                    if ((e.getClickCount() == 1) && (System.currentTimeMillis() - lastClickTime < QualifierView.EDIT_NAME_CLICK_DELAY) && (Arrays.equals(lastSelectedRows, tree.getTable().getSelectedRows()))) {
                        if (!tree.getTable().isEditing()) {
                            editTableField();
                        }
                    } else {
                        lastClickTime = System.currentTimeMillis();
                        lastSelectedRows = tree.getTable().getSelectedRows();
                    }
                }
            }
        }
    });
    tree.getTable().setEditIfNullEvent(false);
    tree.getTable().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0), "EditCell");
    tree.getTable().getActionMap().put("EditCell", new AbstractAction() {

        /**
         */
        private static final long serialVersionUID = 3229634866196074563L;

        @Override
        public void actionPerformed(ActionEvent e) {
            if ((tree.getTable().getSelectedRow() >= 0) && (tree.getTable().getSelectedColumn() >= 0))
                editTableField();
        }
    });
    JScrollPane pane = new JScrollPane();
    pane.setViewportView(tree);
    this.add(pane, BorderLayout.CENTER);
}
Also used : RootCreater(com.ramussoft.gui.qualifier.table.RootCreater) RowRootCreater(com.ramussoft.gui.qualifier.table.RowRootCreater) Attribute(com.ramussoft.common.Attribute) RowTreeTableComponent(com.ramussoft.gui.qualifier.table.RowTreeTableComponent) GUIFramework(com.ramussoft.gui.common.GUIFramework) RowNode(com.ramussoft.gui.qualifier.table.RowNode) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) Qualifier(com.ramussoft.common.Qualifier) RowTreeTable(com.ramussoft.gui.qualifier.table.RowTreeTable) AbstractAction(javax.swing.AbstractAction) Engine(com.ramussoft.common.Engine) Rows(com.ramussoft.gui.qualifier.table.Rows) JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) AttributePlugin(com.ramussoft.gui.common.AttributePlugin) TreeTableNode(com.ramussoft.gui.qualifier.table.TreeTableNode) Transferable(java.awt.datatransfer.Transferable) MouseAdapter(java.awt.event.MouseAdapter) RowTreeTableModel(com.ramussoft.gui.qualifier.table.RowTreeTableModel) AccessRules(com.ramussoft.common.AccessRules) IDEF0Object(com.ramussoft.pb.idef.visual.IDEF0Object) Row(com.ramussoft.database.common.Row) RootRow(com.ramussoft.database.common.RowSet.RootRow) ImageIcon(javax.swing.ImageIcon) Icon(javax.swing.Icon)

Example 5 with AttributePlugin

use of com.ramussoft.gui.common.AttributePlugin in project ramus by Vitaliy-Yakovchuk.

the class IDEF0Object method createEditFrame.

@Override
protected void createEditFrame() {
    final GUIFramework framework = movingArea.getPanel().getFramework();
    final Engine engine = framework.getEngine();
    long id = getFunction().getLink();
    Element element2 = null;
    if (id >= 0)
        element2 = engine.getElement(id);
    if (element2 == null)
        element2 = getFunction().getElement();
    final Element element = element2;
    Qualifier qualifier = engine.getQualifier(element.getQualifierId());
    Attribute name = null;
    if (qualifier.getAttributeForName() >= 0)
        name = engine.getAttribute(qualifier.getAttributeForName());
    if (name == null) {
        JOptionPane.showMessageDialog(framework.getMainFrame(), ResourceLoader.getString("NameAttributeNotSet"));
        return;
    }
    final Attribute nameAttribute = name;
    AttributePlugin plugin = framework.findAttributePlugin(name);
    final AttributeEditor editor = plugin.getAttributeEditor(engine, framework.getAccessRules(), element, name, "activity_name", null);
    setTextComponent(new JScrollPane(editor.getLastComponent()));
    final Object value = engine.getAttribute(element, name);
    editor.setValue(value);
    final Rectangle r = movingArea.getIBounds(getBounds());
    final JTextArea textArea = (JTextArea) editor.getLastComponent();
    processTextArea(textArea);
    // textArea.setBackground(getFunction().getBackground());
    // textArea.setForeground(getFunction().getForeground());
    // textArea.setFont(movingArea.getFont(getFont()));
    // textArea.setCaretColor(getFunction().getForeground());
    final JPopupMenu menu = textArea.getComponentPopupMenu();
    textArea.setComponentPopupMenu(null);
    movingArea.getPanel().setActionDisable(true);
    textArea.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER && e.isControlDown()) {
                stopEdit(element, engine, nameAttribute, editor, value, textArea, menu);
            } else if (e.getKeyCode() == KeyEvent.VK_ESCAPE)
                cancelEdit(editor, textArea, menu);
        }
    });
    textArea.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
            stopEdit(element, engine, nameAttribute, editor, value, textArea, menu);
        }

        @Override
        public void focusGained(FocusEvent e) {
        }
    });
    movingArea.add(getTextComponent());
    movingArea.setbImage(null);
    getTextComponent().setBounds(r);
    movingArea.revalidate();
    movingArea.repaint();
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            textArea.requestFocus();
        }
    });
}
Also used : JScrollPane(javax.swing.JScrollPane) JTextArea(javax.swing.JTextArea) AttributePlugin(com.ramussoft.gui.common.AttributePlugin) Attribute(com.ramussoft.common.Attribute) GUIFramework(com.ramussoft.gui.common.GUIFramework) Element(com.ramussoft.common.Element) KeyAdapter(java.awt.event.KeyAdapter) Rectangle(java.awt.Rectangle) FRectangle(com.dsoft.pb.types.FRectangle) FocusEvent(java.awt.event.FocusEvent) JPopupMenu(javax.swing.JPopupMenu) KeyEvent(java.awt.event.KeyEvent) AttributeEditor(com.ramussoft.gui.common.AttributeEditor) Qualifier(com.ramussoft.common.Qualifier) FocusListener(java.awt.event.FocusListener) Engine(com.ramussoft.common.Engine)

Aggregations

AttributePlugin (com.ramussoft.gui.common.AttributePlugin)15 Attribute (com.ramussoft.common.Attribute)10 Engine (com.ramussoft.common.Engine)5 AttributeType (com.ramussoft.common.AttributeType)4 Qualifier (com.ramussoft.common.Qualifier)4 BorderLayout (java.awt.BorderLayout)4 JPanel (javax.swing.JPanel)4 AccessRules (com.ramussoft.common.AccessRules)3 Element (com.ramussoft.common.Element)3 JLabel (javax.swing.JLabel)3 AttributeEditor (com.ramussoft.gui.common.AttributeEditor)2 GUIFramework (com.ramussoft.gui.common.GUIFramework)2 DialogedTableCellEditor (com.ramussoft.gui.qualifier.table.DialogedTableCellEditor)2 RowRootCreater (com.ramussoft.gui.qualifier.table.RowRootCreater)2 RowTreeTableComponent (com.ramussoft.gui.qualifier.table.RowTreeTableComponent)2 RowTreeTableModel (com.ramussoft.gui.qualifier.table.RowTreeTableModel)2 TabledAttributePlugin (com.ramussoft.gui.qualifier.table.TabledAttributePlugin)2 IDEF0Object (com.ramussoft.pb.idef.visual.IDEF0Object)2 TableLayout (info.clearthought.layout.TableLayout)2 KeyEvent (java.awt.event.KeyEvent)2