Example usage for javax.swing JPopupMenu add

List of usage examples for javax.swing JPopupMenu add

Introduction

In this page you can find the example usage for javax.swing JPopupMenu add.

Prototype

public JMenuItem add(Action a) 

Source Link

Document

Appends a new menu item to the end of the menu which dispatches the specified Action object.

Usage

From source file:org.nuclos.client.relation.EntityRelationshipModelEditPanel.java

protected JPopupMenu createPopupMenu() {

    JPopupMenu pop = new JPopupMenu();

    JMenuItem i1 = new JMenuItem(
            getSpringLocaleDelegate().getMessage("nuclos.entityrelation.editor.16", "neue Entit\u00e4t"));
    i1.addActionListener(new ActionListener() {

        @Override/*from   w w  w.ja  v a 2s. co  m*/
        public void actionPerformed(ActionEvent e) {

            int x = xPos;
            int y = yPos;

            mxGeometry mxgeo = new mxGeometry(x, y, 100, 80);
            mxgeo.setSourcePoint(new mxPoint(100, 100));
            mxgeo.setTargetPoint(new mxPoint(150, 150));

            mxCell cell = new mxCell("", mxgeo, ENTITYSTYLE);
            cell.setVertex(true);
            mxCell cellRoot = (mxCell) graphComponent.getGraph().getModel().getRoot();
            mxCell cellContainer = (mxCell) cellRoot.getChildAt(0);
            int childcount = cellContainer.getChildCount();
            getGraphModel().add(cellContainer, cell, childcount);
            getGraphComponent().refresh();

        }
    });

    JMenuItem i3 = new JMenuItem(
            getSpringLocaleDelegate().getMessage("nuclos.entityrelation.editor.8", "zoom in"));
    i3.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            graphComponent.zoomIn();
        }
    });

    JMenuItem i4 = new JMenuItem(
            getSpringLocaleDelegate().getMessage("nuclos.entityrelation.editor.9", "zoom out"));
    i4.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            graphComponent.zoomOut();
        }
    });

    pop.add(i1);
    pop.addSeparator();
    pop.add(i3);
    pop.add(i4);

    return pop;
}

From source file:org.nuclos.client.relation.EntityRelationshipModelEditPanel.java

protected JPopupMenu createRelationPopupMenu(final mxCell cell, boolean delete, boolean objectGeneration) {
    final SpringLocaleDelegate localeDelegate = getSpringLocaleDelegate();

    JPopupMenu pop = new JPopupMenu();
    JMenuItem i1 = new JMenuItem(
            localeDelegate.getMessage("nuclos.entityrelation.editor.10", "Bezug zu Stammdaten bearbeiten"));

    i1.addActionListener(new ActionListener() {

        @Override//w ww  .j a  v a 2 s  .co  m
        public void actionPerformed(ActionEvent e) {
            editMasterdataRelation(cell);
        }
    });

    JMenuItem i2 = new JMenuItem(
            localeDelegate.getMessage("nuclos.entityrelation.editor.11", "Unterfomularbezug bearbeiten"));
    i2.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            editSubformRelation(cell);
        }

    });

    JMenuItem i4 = new JMenuItem(
            localeDelegate.getMessage("nuclos.entityrelation.editor.12", "Verbindung l\u00f6sen"));
    i4.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            int opt = JOptionPane.showConfirmDialog(mainPanel, localeDelegate.getMessage(
                    "nuclos.entityrelation.editor.7", "M\u00f6chten Sie die Verbindung wirklich l\u00f6sen?"));
            if (opt != 0) {
                return;
            }
            mxCell cellSource = (mxCell) cell.getSource();
            if (cellSource != null && cellSource.getValue() instanceof EntityMetaDataVO) {
                EntityMetaDataVO metaSource = (EntityMetaDataVO) cellSource.getValue();
                if (cell.getValue() instanceof EntityFieldMetaDataVO) {
                    EntityFieldMetaDataVO voField = (EntityFieldMetaDataVO) cell.getValue();
                    voField.flagRemove();

                    List<EntityFieldMetaDataTO> toList = new ArrayList<EntityFieldMetaDataTO>();
                    EntityFieldMetaDataTO toField = new EntityFieldMetaDataTO();
                    toField.setEntityFieldMeta(voField);
                    toList.add(toField);

                    MetaDataDelegate.getInstance().modifyEntityMetaData(metaSource, toList);

                    if (mpRemoveRelation.containsKey(metaSource)) {
                        mpRemoveRelation.get(metaSource).add(voField);
                    } else {
                        Set<EntityFieldMetaDataVO> s = new HashSet<EntityFieldMetaDataVO>();
                        s.add(voField);
                        mpRemoveRelation.put(metaSource, s);
                    }
                } else if (cell.getValue() != null && cell.getValue() instanceof String) {

                }
            }

            mxGraphModel model = (mxGraphModel) graphComponent.getGraph().getModel();
            model.remove(cell);
            EntityRelationshipModelEditPanel.this.fireChangeListenEvent();
        }
    });

    JMenuItem i5 = new JMenuItem(
            localeDelegate.getMessage("nuclos.entityrelation.editor.13", "Arbeitsschritt bearbeiten"));
    i5.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {

                mxCell cellSource = (mxCell) cell.getSource();
                mxCell cellTarget = (mxCell) cell.getTarget();

                EntityMetaDataVO sourceModule = (EntityMetaDataVO) cellSource.getValue();
                EntityMetaDataVO targetModule = (EntityMetaDataVO) cellTarget.getValue();

                String sSourceModule = sourceModule.getEntity();
                String sTargetModule = targetModule.getEntity();

                boolean blnFound = false;

                for (MasterDataVO voGeneration : MasterDataCache.getInstance()
                        .get(NuclosEntity.GENERATION.getEntityName())) {
                    String sSource = (String) voGeneration.getField("sourceModule");
                    String sTarget = (String) voGeneration.getField("targetModule");

                    if (org.apache.commons.lang.StringUtils.equals(sSource, sSourceModule)
                            && org.apache.commons.lang.StringUtils.equals(sTarget, sTargetModule)) {
                        GenerationCollectController gcc = (GenerationCollectController) NuclosCollectControllerFactory
                                .getInstance().newMasterDataCollectController(
                                        NuclosEntity.GENERATION.getEntityName(), null, null);
                        gcc.runViewSingleCollectableWithId(voGeneration.getId());
                        blnFound = true;
                        break;
                    }

                }
                if (!blnFound) {
                    GenerationCollectController gcc = (GenerationCollectController) NuclosCollectControllerFactory
                            .getInstance().newMasterDataCollectController(
                                    NuclosEntity.GENERATION.getEntityName(), null, null);
                    Map<String, Object> mp = new HashMap<String, Object>();
                    mp.put("sourceModule", sSourceModule);
                    mp.put("sourceModuleId", new Integer(
                            MetaDataClientProvider.getInstance().getEntity(sSourceModule).getId().intValue()));
                    mp.put("targetModule", sTargetModule);
                    mp.put("targetModuleId", new Integer(
                            MetaDataClientProvider.getInstance().getEntity(sTargetModule).getId().intValue()));
                    MasterDataVO vo = new MasterDataVO(NuclosEntity.GENERATION.getEntityName(), null, null,
                            null, null, null, null, mp);
                    gcc.runWithNewCollectableWithSomeFields(vo);
                }
            } catch (NuclosBusinessException e1) {
                LOG.warn("actionPerformed failed: " + e1, e1);
            } catch (CommonPermissionException e1) {
                LOG.warn("actionPerformed failed: " + e1, e1);
            } catch (CommonFatalException e1) {
                LOG.warn("actionPerformed failed: " + e1, e1);
            } catch (CommonBusinessException e1) {
                LOG.warn("actionPerformed failed: " + e1, e1);
            }
        }
    });

    if (cell.getStyle() != null && cell.getStyle().indexOf(OPENARROW) >= 0) {
        i1.setSelected(true);
        pop.add(i1);
    } else if (cell.getStyle() != null && cell.getStyle().indexOf(DIAMONDARROW) >= 0) {
        i2.setSelected(true);
        pop.add(i2);
    }

    if (objectGeneration) {
        //pop.addSeparator();
        pop.add(i5);
    }

    if (delete) {
        pop.addSeparator();
        pop.add(i4);
    }
    return pop;
}

From source file:org.nuclos.client.relation.EntityRelationshipModelEditPanel.java

protected JPopupMenu createPopupMenuEntity(final mxCell cell, boolean newCell) {
    final SpringLocaleDelegate localeDelegate = getSpringLocaleDelegate();

    JPopupMenu pop = new JPopupMenu();
    JMenuItem i1 = new JMenuItem(
            localeDelegate.getMessage("nuclos.entityrelation.editor.14", "Symbol l\u00f6schen"));
    i1.addActionListener(new ActionListener() {

        @Override/*from   www . ja  v  a  2 s .c  o  m*/
        public void actionPerformed(ActionEvent e) {
            mxGraphModel model = (mxGraphModel) graphComponent.getGraph().getModel();
            int iEdge = cell.getEdgeCount();
            for (int i = 0; i < iEdge; i++) {
                mxCell cellRelation = (mxCell) cell.getEdgeAt(0);
                model.remove(cellRelation);
            }
            model.remove(cell);
            fireChangeListenEvent();
        }
    });

    if (!newCell)
        pop.add(i1);

    if (cell.getStyle() == null || !(cell.getStyle().indexOf(ENTITYSTYLE) >= 0)) {
        return pop;
    }

    JMenuItem iWizard = new JMenuItem(
            localeDelegate.getMessage("nuclos.entityrelation.editor.15", "Wizard \u00f6ffnen"));
    iWizard.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (cell.getValue() != null && cell.getValue() instanceof EntityMetaDataVO) {
                String sValue = ((EntityMetaDataVO) cell.getValue()).getEntity();
                if (sValue.length() > 0) {
                    try {
                        final EntityMetaDataVO vo = MetaDataClientProvider.getInstance().getEntity(sValue);
                        new ShowNuclosWizard.NuclosWizardEditRunnable(false, mf.getHomePane(), vo).run();
                    } catch (Exception e1) {
                        // neue Entity
                        LOG.info("actionPerformed: " + e1 + " (new entity?)");
                    }
                }
            }
        }
    });

    if (!newCell) {
        //pop.addSeparator();
        pop.add(iWizard);
    } else {
        JMenuItem iNew = new JMenuItem(
                localeDelegate.getMessage("nuclos.entityrelation.editor.16", "neue Entit\u00e4t"));
        iNew.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (cell.getValue() != null && cell.getValue() instanceof EntityMetaDataVO) {
                    final EntityMetaDataVO voTMP = (EntityMetaDataVO) cell.getValue();
                    final EntityMetaDataVO vo = MetaDataClientProvider.getInstance()
                            .getEntity(voTMP.getEntity());
                    new ShowNuclosWizard.NuclosWizardEditRunnable(false, mf.getHomePane(), vo).run();
                } else {
                    cell.setValue(
                            localeDelegate.getMessage("nuclos.entityrelation.editor.16", "neue Entit\u00e4t"));
                    mxGraph graph = graphComponent.getGraph();
                    graph.refresh();
                }
            }
        });
        pop.add(iNew);
    }
    //pop.addSeparator();

    Collection<EntityMetaDataVO> colMetaVO = MetaDataClientProvider.getInstance().getAllEntities();

    List<EntityMetaDataVO> lst = new ArrayList<EntityMetaDataVO>(colMetaVO);

    Collections.sort(lst, new Comparator<EntityMetaDataVO>() {

        @Override
        public int compare(EntityMetaDataVO o1, EntityMetaDataVO o2) {
            return o1.getEntity().toLowerCase().compareTo(o2.getEntity().toLowerCase());
        }

    });

    for (final EntityMetaDataVO vo : lst) {
        if (vo.getEntity().startsWith("nuclos_"))
            continue;

        JCheckBoxMenuItem menu = new JCheckBoxMenuItem(vo.getEntity());
        menu.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                final JMenuItem item = (JMenuItem) e.getSource();
                SwingUtilities.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        cell.setValue(vo);
                        graphComponent.repaint();
                        fireChangeListenEvent();
                    }
                });

            }
        });
        if (cell.getValue() != null && cell.getValue() instanceof EntityMetaDataVO) {
            EntityMetaDataVO sValue = (EntityMetaDataVO) cell.getValue();
            if (vo.getEntity().equals(sValue.getEntity())) {
                menu.setSelected(true);
            }
        }
        //pop.add(menu);
    }

    return pop;

}

From source file:org.nuclos.client.relation.MyGraphModel.java

public JPopupMenu createRelationPopupMenu(final mxCell cell, boolean delete) {

    final JPopupMenu pop = new JPopupMenu();
    JMenuItem i1 = new JMenuItem(
            getSpringLocaleDelegate().getMessage("nuclos.entityrelation.editor.1", "Bezug zu Stammdaten"));
    i1.addActionListener(new ActionListener() {

        @Override//from   w w w .ja v  a  2  s  .  com
        public void actionPerformed(ActionEvent e) {
            editPanel.setIsPopupShown(false);
            if (cell.getTarget() == null || cell.getSource() == null) {
                remove(cell);
                return;
            }
            Object cells[] = { cell };
            mxUtils.setCellStyles(graphComponent.getGraph().getModel(), cells, mxConstants.STYLE_ENDARROW,
                    mxConstants.ARROW_OPEN);
            mxUtils.setCellStyles(graphComponent.getGraph().getModel(), cells, mxConstants.STYLE_ENDSIZE, "12");
            mxUtils.setCellStyles(graphComponent.getGraph().getModel(), cells, mxConstants.STYLE_ELBOW,
                    mxConstants.ELBOW_VERTICAL);
            mxUtils.setCellStyles(graphComponent.getGraph().getModel(), cells, EDGESTYLE, ELBOWCONNECTOR);
            RelationAttributePanel panel = new RelationAttributePanel(RelationAttributePanel.TYPE_ENTITY);
            mxCell target = (mxCell) cell.getTarget();
            mxCell source = (mxCell) cell.getSource();
            panel.setEntity((EntityMetaDataVO) target.getValue());
            panel.setEntitySource((EntityMetaDataVO) source.getValue());
            EntityMetaDataVO voSource = (EntityMetaDataVO) source.getValue();
            EntityMetaDataVO voTarget = (EntityMetaDataVO) target.getValue();
            panel.setEntityFields(
                    MetaDataDelegate.getInstance().getAllEntityFieldsByEntity(voSource.getEntity()).values());
            double cellsDialog[][] = { { 5, TableLayout.PREFERRED, 5 }, { 5, TableLayout.PREFERRED, 5 } };
            JDialog dia = new JDialog(mf);
            dia.setLayout(new TableLayout(cellsDialog));
            dia.setTitle(getSpringLocaleDelegate().getMessage("nuclos.entityrelation.editor.10",
                    "Bezug zu Stammdaten bearbeiten"));
            dia.setLocationRelativeTo(editPanel);
            dia.add(panel, "1,1");
            dia.setModal(true);
            panel.setDialog(dia);
            dia.pack();
            dia.setVisible(true);

            if (panel.getState() == 1) {
                EntityFieldMetaDataVO vo = panel.getField();
                cell.setValue(vo);
                mpTransation.put(vo, panel.getTranslation().getRows());

                List<EntityFieldMetaDataTO> toList = new ArrayList<EntityFieldMetaDataTO>();

                EntityFieldMetaDataTO toField = new EntityFieldMetaDataTO();
                toField.setEntityFieldMeta(vo);
                toField.setTranslation(panel.getTranslation().getRows());
                toList.add(toField);

                MetaDataDelegate.getInstance().modifyEntityMetaData(voSource, toList);
                editPanel.loadReferenz();

            } else {
                remove(cell);
            }

        }
    });

    final JMenuItem i2 = new JMenuItem(getSpringLocaleDelegate().getMessage("nuclos.entityrelation.editor.3",
            "Bezug zu Vorg\u00e4ngen (Unterformularbezug)"));
    i2.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            editPanel.setIsPopupShown(false);
            if (cell.getTarget() == null || cell.getSource() == null) {
                remove(cell);
                return;
            }
            Object cells[] = { cell };
            mxUtils.setCellStyles(graphComponent.getGraph().getModel(), cells, mxConstants.STYLE_ENDARROW,
                    mxConstants.ARROW_DIAMOND);
            mxUtils.setCellStyles(graphComponent.getGraph().getModel(), cells, mxConstants.STYLE_ENDSIZE, "12");
            mxUtils.setCellStyles(graphComponent.getGraph().getModel(), cells, mxConstants.STYLE_ELBOW,
                    mxConstants.ELBOW_VERTICAL);
            mxUtils.setCellStyles(graphComponent.getGraph().getModel(), cells, EDGESTYLE, ELBOWCONNECTOR);
            mxCell target = (mxCell) cell.getTarget();
            mxCell source = (mxCell) cell.getSource();
            EntityMetaDataVO voSource = (EntityMetaDataVO) source.getValue();
            EntityMetaDataVO voTarget = (EntityMetaDataVO) target.getValue();
            String sFieldName = null;
            boolean blnNotSet = true;
            while (blnNotSet) {
                sFieldName = JOptionPane.showInputDialog(editPanel, getSpringLocaleDelegate().getMessage(
                        "nuclos.entityrelation.editor.1", "Bitte geben Sie den Namen des Feldes an!"));
                if (sFieldName == null || sFieldName.length() < 1) {
                    MyGraphModel.this.remove(cell);
                    return;
                } else if (sFieldName != null) {
                    blnNotSet = false;
                }
            }
            EntityFieldMetaDataVO vo = new EntityFieldMetaDataVO();
            vo.setModifiable(true);
            vo.setLogBookTracking(false);
            vo.setReadonly(false);
            vo.setShowMnemonic(true);
            vo.setInsertable(true);
            vo.setSearchable(true);
            vo.setNullable(false);
            vo.setUnique(true);
            vo.setDataType("java.lang.String");

            List<TranslationVO> lstTranslation = new ArrayList<TranslationVO>();
            for (LocaleInfo voLocale : LocaleDelegate.getInstance().getAllLocales(false)) {
                String sLocaleLabel = voLocale.language;
                Integer iLocaleID = voLocale.localeId;
                String sCountry = voLocale.title;
                Map<String, String> map = new HashMap<String, String>();

                TranslationVO translation = new TranslationVO(iLocaleID, sCountry, sLocaleLabel, map);
                for (String sLabel : labels) {
                    translation.getLabels().put(sLabel, sFieldName);
                }
                lstTranslation.add(translation);
            }

            vo.setForeignEntity(voTarget.getEntity());
            vo.setField(sFieldName);
            vo.setDbColumn("INTID_" + sFieldName);

            cell.setValue(vo);

            List<EntityFieldMetaDataTO> toList = new ArrayList<EntityFieldMetaDataTO>();

            EntityFieldMetaDataTO toField = new EntityFieldMetaDataTO();
            toField.setEntityFieldMeta(vo);
            toField.setTranslation(lstTranslation);
            toList.add(toField);

            MetaDataDelegate.getInstance().modifyEntityMetaData(voSource, toList);
            editPanel.loadReferenz();
        }
    });

    final JMenuItem i4 = new JMenuItem(
            getSpringLocaleDelegate().getMessage("nuclos.entityrelation.editor.5", "Arbeitsschritt"));
    i4.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            editPanel.setIsPopupShown(false);
            if (cell.getTarget() == null || cell.getSource() == null) {
                remove(cell);
                return;
            }
            Object cells[] = { cell };
            mxUtils.setCellStyles(graphComponent.getGraph().getModel(), cells, mxConstants.STYLE_ENDARROW,
                    mxConstants.ARROW_OVAL);
            mxUtils.setCellStyles(graphComponent.getGraph().getModel(), cells, mxConstants.STYLE_ENDSIZE, "12");
            mxUtils.setCellStyles(graphComponent.getGraph().getModel(), cells, mxConstants.STYLE_ELBOW,
                    mxConstants.ELBOW_VERTICAL);
            mxUtils.setCellStyles(graphComponent.getGraph().getModel(), cells, EDGESTYLE, ELBOWCONNECTOR);

            try {

                mxCell cellSource = (mxCell) cell.getSource();
                mxCell cellTarget = (mxCell) cell.getTarget();

                EntityMetaDataVO sourceModule = (EntityMetaDataVO) cellSource.getValue();
                EntityMetaDataVO targetModule = (EntityMetaDataVO) cellTarget.getValue();

                String sSourceModule = sourceModule.getEntity();
                String sTargetModule = targetModule.getEntity();

                boolean blnFound = false;

                for (MasterDataVO voGeneration : MasterDataCache.getInstance()
                        .get(NuclosEntity.GENERATION.getEntityName())) {
                    String sSource = (String) voGeneration.getField("sourceModule");
                    String sTarget = (String) voGeneration.getField("targetModule");

                    if (org.apache.commons.lang.StringUtils.equals(sSource, sSourceModule)
                            && org.apache.commons.lang.StringUtils.equals(sTarget, sTargetModule)) {
                        GenerationCollectController gcc = (GenerationCollectController) NuclosCollectControllerFactory
                                .getInstance().newMasterDataCollectController(
                                        NuclosEntity.GENERATION.getEntityName(), null, null);
                        gcc.runViewSingleCollectableWithId(voGeneration.getId());
                        blnFound = true;
                        break;
                    }

                }
                if (!blnFound) {
                    GenerationCollectController gcc = (GenerationCollectController) NuclosCollectControllerFactory
                            .getInstance().newMasterDataCollectController(
                                    NuclosEntity.GENERATION.getEntityName(), null, null);
                    Map<String, Object> mp = new HashMap<String, Object>();
                    mp.put("sourceModule", sSourceModule);
                    mp.put("sourceModuleId", new Integer(
                            MetaDataClientProvider.getInstance().getEntity(sSourceModule).getId().intValue()));
                    mp.put("targetModule", sTargetModule);
                    mp.put("targetModuleId", new Integer(
                            MetaDataClientProvider.getInstance().getEntity(sTargetModule).getId().intValue()));
                    MasterDataVO vo = new MasterDataVO(NuclosEntity.GENERATION.getEntityName(), null, null,
                            null, null, null, null, mp);
                    gcc.runWithNewCollectableWithSomeFields(vo);
                }
            } catch (NuclosBusinessException e1) {
                LOG.warn("actionPerformed: " + e1);
            } catch (CommonPermissionException e1) {
                LOG.warn("actionPerformed: " + e1);
            } catch (CommonFatalException e1) {
                LOG.warn("actionPerformed: " + e1);
            } catch (CommonBusinessException e1) {
                LOG.warn("actionPerformed: " + e1);
            }
        }
    });

    JMenuItem i5 = new JMenuItem(
            getSpringLocaleDelegate().getMessage("nuclos.entityrelation.editor.12", "Verbindung l\u00f6sen"));
    i5.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            mxGraphModel model = (mxGraphModel) graphComponent.getGraph().getModel();
            model.remove(cell);
        }
    });

    pop.add(i1);
    pop.add(i2);
    //pop.add(i3);
    pop.add(i4);
    if (delete) {
        pop.addSeparator();
        pop.add(i5);
    }

    return pop;

}

From source file:org.nuclos.client.relation.MyGraphModel.java

protected JPopupMenu createPopupMenuEntity(final mxCell cell, boolean newCell) {

    JPopupMenu pop = new JPopupMenu();
    JMenuItem i1 = new JMenuItem(
            getSpringLocaleDelegate().getMessage("nuclos.entityrelation.editor.14", "Symbol l\u00f6schen"));
    i1.addActionListener(new ActionListener() {

        @Override/*from w  ww  . j a v a2  s  .c om*/
        public void actionPerformed(ActionEvent e) {
            mxGraphModel model = (mxGraphModel) graphComponent.getGraph().getModel();
            model.remove(cell);
        }
    });

    if (!newCell)
        pop.add(i1);

    if (cell.getStyle() == null || !(cell.getStyle().indexOf(ENTITYSTYLE) >= 0)) {
        return pop;
    }

    JMenuItem iWizard = new JMenuItem(
            getSpringLocaleDelegate().getMessage("nuclos.entityrelation.editor.15", "Wizard \u00f6ffnen"));
    iWizard.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (cell.getValue() != null && cell.getValue() instanceof EntityMetaDataVO) {
                String sValue = ((EntityMetaDataVO) cell.getValue()).getEntity();
                if (sValue.length() > 0) {
                    final EntityMetaDataVO vo = MetaDataClientProvider.getInstance().getEntity(sValue);
                    new ShowNuclosWizard.NuclosWizardEditRunnable(false, mf.getHomePane(), vo).run();
                }
            }
        }
    });

    if (!newCell) {
        pop.addSeparator();
        pop.add(iWizard);
    } else {
        JMenuItem iNew = new JMenuItem(
                getSpringLocaleDelegate().getMessage("nuclos.entityrelation.editor.16", "neue Entit\u00e4t"));
        iNew.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (cell.getValue() != null && cell.getValue() instanceof EntityMetaDataVO) {
                    String sValue = ((EntityMetaDataVO) cell.getValue()).getEntity();
                    if (sValue.length() > 0) {
                        try {
                            final EntityMetaDataVO vo = MetaDataClientProvider.getInstance().getEntity(sValue);
                            new ShowNuclosWizard.NuclosWizardEditRunnable(false, mf.getHomePane(), vo).run();
                        } catch (CommonFatalException e1) {
                            // do noting here Entity does not exist
                            LOG.warn("actionPerformed: " + e1 + "(entity does not exist?)");
                        }
                    }
                } else {
                    cell.setValue(getSpringLocaleDelegate().getMessage("nuclos.entityrelation.editor.16",
                            "neue Entit\u00e4t"));
                    mxGraph graph = graphComponent.getGraph();
                    graph.refresh();
                }
            }
        });
        pop.add(iNew);
    }

    return pop;
}

From source file:org.nuclos.client.ui.collect.component.AbstractCollectableComponent.java

/**
 * Subclasses may add menu items to the default popup menu or provide their own completely.
 * @return a new popup menu for this component.
 * @see JPopupMenuFactory/* www.java 2 s.co  m*/
 */
@Override
public JPopupMenu newJPopupMenu() {
    JPopupMenu result;

    if (isSearchComponent() && hasComparisonOperator()) {
        result = newComparisonOperatorPopupMenu();
    } else {
        // regular popup menu:
        result = new JPopupMenu();

        if (isMultiEditable()) {
            result.add(newNoChangeEntry());
            result.add(newClearEntry());
        }

        if (getEntityField().isReferencing()) {
            if (result.getComponentCount() > 0) {
                result.addSeparator();
            }
            result.add(newShowDetailsEntry());
            result.add(newInsertEntry());
        }

        if (result.getComponentCount() == 0) {
            result = null;
        }
    }
    return result;
}

From source file:org.nuclos.client.ui.collect.component.AbstractCollectableComponent.java

/**
 * @return//from   w w w .  ja  v a 2 s . com
 * @precondition hasComparisonOperator()
 */
public JPopupMenu newComparisonOperatorPopupMenu() {
    if (!hasComparisonOperator()) {
        throw new IllegalStateException();
    }
    final JPopupMenu result = new JPopupMenu(
            getSpringLocaleDelegate().getMessage("AbstractCollectableComponent.16", "Vergleichsoperator"));

    // 1. comparison operators:
    final ButtonGroup btngrpComparisonOperators = new ButtonGroup();

    final ItemListener itemlistener = new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent ev) {
            if (ev.getStateChange() == ItemEvent.SELECTED) {
                final String sOperatorName = ((AbstractButton) ev.getItem()).getActionCommand();
                setComparisonOperator(ComparisonOperator.getInstance(sOperatorName));
                runLocked(new Runnable() {
                    @Override
                    public void run() {
                        updateSearchConditionInModel();
                    }
                });
            }
        }
    };

    ComparisonOperator[] supportedComparisonOperators = getSupportedComparisonOperators();
    if (supportedComparisonOperators == null)
        return null;

    for (ComparisonOperator compop : supportedComparisonOperators) {
        JMenuItem mi = new JRadioButtonMenuItem(
                getSpringLocaleDelegate().getMessage(compop.getResourceIdForLabel(), null));
        mi.setActionCommand(compop.name());
        mi.setToolTipText(getSpringLocaleDelegate().getMessage(compop.getResourceIdForDescription(), null));
        result.add(mi);
        btngrpComparisonOperators.add(mi);
        mi.addItemListener(itemlistener);
    }

    result.addPopupMenuListener(new PopupMenuListener() {
        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent ev) {
            for (int i = 0, n = result.getComponentCount(); i < n; i++) {
                Component c = result.getComponent(i);
                if (c instanceof JMenuItem && StringUtils.emptyIfNull(((JMenuItem) c).getActionCommand())
                        .equals(getComparisonOperator().name()))
                    ((JMenuItem) c).setSelected(true);
            }
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent ev) {
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent ev) {
        }
    });

    // 2. right operand (value or other field):
    if (canDisplayComparisonWithOtherField()) {
        addRightOperandToPopupMenu(result, this);
    }

    return result;
}

From source file:org.nuclos.client.ui.collect.component.AbstractCollectableComponent.java

/**
 * @param result/*from w w  w. j  a v a2  s  .com*/
 * @param clctcomp
 */
private static void addRightOperandToPopupMenu(JPopupMenu result, final AbstractCollectableComponent clctcomp) {
    result.addSeparator();
    final ButtonGroup btngrpCompareWith = new ButtonGroup();
    final SpringLocaleDelegate localeDelegate = SpringLocaleDelegate.getInstance();

    final JRadioButtonMenuItem miValue = new JRadioButtonMenuItem(
            localeDelegate.getMessage("AbstractCollectableComponent.17", "Wertvergleich"));
    miValue.setToolTipText(localeDelegate.getMessage("AbstractCollectableComponent.10",
            "Dieses Feld mit einem festen Wert vergleichen"));
    result.add(miValue);
    btngrpCompareWith.add(miValue);
    miValue.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ev) {
            clctcomp.resetWithComparison();
            clctcomp.runLocked(new Runnable() {
                @Override
                public void run() {
                    clctcomp.updateSearchConditionInModel();
                }
            });
        }
    });

    final JRadioButtonMenuItem miOtherField = new JRadioButtonMenuItem(
            localeDelegate.getMessage("AbstractCollectableComponent.12", "Feldvergleich..."));
    miOtherField.setToolTipText(localeDelegate.getMessage("AbstractCollectableComponent.9",
            "Dieses Feld mit dem Inhalt eines anderen Felds vergleichen"));
    result.add(miOtherField);
    btngrpCompareWith.add(miOtherField);
    miOtherField.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ev) {
            assert clctcomp.clcte != null;

            // select entity field with the same data type:
            final List<CollectableEntityField> lstclctefFiltered = CollectionUtils.select(
                    CollectableUtils.getCollectableEntityFields(clctcomp.clcte),
                    new Predicate<CollectableEntityField>() {
                        @Override
                        public boolean evaluate(CollectableEntityField clctef) {
                            return clctef.getJavaClass() == clctcomp.clctef.getJavaClass();
                        }
                    });
            // and sort by label:
            final List<CollectableEntityField> lstclctefSorted = CollectionUtils.sorted(lstclctefFiltered,
                    new CollectableEntityField.LabelComparator());

            final JComboBox cmbbx = new JComboBox(lstclctefSorted.toArray());
            cmbbx.setSelectedItem(clctcomp.getComparisonOtherField());

            final int iBtn = JOptionPane
                    .showConfirmDialog(clctcomp.getJComponent(),
                            new Object[] { localeDelegate.getMessage("AbstractCollectableComponent.6",
                                    "Anderes Feld: "), cmbbx },
                            localeDelegate.getMessage("AbstractCollectableComponent.15",
                                    "Vergleich mit anderem Feld"),
                            JOptionPane.OK_CANCEL_OPTION);

            if (iBtn == JOptionPane.OK_OPTION) {
                clctcomp.setWithComparison((CollectableEntityField) cmbbx.getSelectedItem());
                if (clctcomp.getComparisonOtherField() != null) {
                    // clear the view:
                    clctcomp.updateView(CollectableUtils.getNullField(clctcomp.getEntityField()));

                    if (clctcomp.compop.getOperandCount() < 2) {
                        // If the user selects "other field" and forgot to set the operator, we assume "EQUAL":
                        clctcomp.compop = ComparisonOperator.EQUAL;
                    }
                }
                clctcomp.runLocked(new Runnable() {
                    @Override
                    public void run() {
                        clctcomp.updateSearchConditionInModel();
                    }
                });
            }
        }
    });

    final List<ComparisonParameter> compatibleParameters = ComparisonParameter
            .getCompatibleParameters(clctcomp.getEntityField());
    final JRadioButtonMenuItem miParameterField = new JRadioButtonMenuItem(
            localeDelegate.getMessage("AbstractCollectableComponent.18", null));
    miParameterField.setToolTipText(localeDelegate.getMessage("AbstractCollectableComponent.19", null));
    btngrpCompareWith.add(miParameterField);
    if (compatibleParameters.size() > 0) {
        result.add(miParameterField);
        miParameterField.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ev) {
                ResourceIdMapper<ComparisonParameter> mapper = new ResourceIdMapper<ComparisonParameter>(
                        compatibleParameters);
                JComboBox cmbbx = new JComboBox(CollectionUtils.sorted(compatibleParameters, mapper).toArray());
                cmbbx.setRenderer(new DefaultListRenderer(mapper));
                cmbbx.setSelectedItem(clctcomp.getComparisonParameter());

                final int opt = JOptionPane.showConfirmDialog(clctcomp.getJComponent(),
                        new Object[] { localeDelegate.getMessage("AbstractCollectableComponent.20", null),
                                cmbbx },
                        localeDelegate.getMessage("AbstractCollectableComponent.19", null),
                        JOptionPane.OK_CANCEL_OPTION);

                if (opt == JOptionPane.OK_OPTION) {
                    clctcomp.setWithComparison((ComparisonParameter) cmbbx.getSelectedItem());
                    if (clctcomp.getComparisonParameter() != null) {
                        clctcomp.updateView(CollectableUtils.getNullField(clctcomp.getEntityField()));
                        if (clctcomp.compop.getOperandCount() < 2) {
                            clctcomp.compop = ComparisonOperator.EQUAL;
                        }
                    }
                    clctcomp.runLocked(new Runnable() {
                        @Override
                        public void run() {
                            clctcomp.updateSearchConditionInModel();
                        }
                    });
                }
            }
        });
    }

    result.addPopupMenuListener(new PopupMenuListener() {
        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent ev) {
            if (clctcomp.getComparisonParameter() != null) {
                miParameterField.setSelected(true);
            } else if (clctcomp.getComparisonOtherField() == null
                    || clctcomp.getComparisonOperator().getOperandCount() < 2) {
                miValue.setSelected(true);
            } else {
                miOtherField.setSelected(true);
            }
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent ev) {
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent ev) {
        }
    });
}

From source file:org.nuclos.client.ui.collect.component.CollectableComboBox.java

/**
 * adds a "Refresh" entry to the popup menu, for a non-searchable component.
 *//*  w  w w . j av  a  2  s  . co m*/
@Override
public JPopupMenu newJPopupMenu() {
    final JPopupMenu result = super.newJPopupMenu();
    if (!this.isSearchComponent() && getEntityField().isReferencing()) {
        result.add(newRefreshEntry());
    }
    return result;
}

From source file:org.nuclos.client.ui.collect.component.CollectableListOfValues.java

/**
 * adds a "Clear" entry to the popup menu, for a non-searchable component.
 *//*  ww  w  . ja  v  a 2  s . c o  m*/
@Override
public JPopupMenu newJPopupMenu() {
    final JPopupMenu result = super.newJPopupMenu();
    if (!this.isSearchComponent()) {
        final JMenuItem miClear = new JMenuItem(SpringLocaleDelegate.getInstance()
                .getMessage("CollectableFileNameChooserBase.1", "Zur\u00fccksetzen"));
        boolean bClearEnabled;
        try {
            bClearEnabled = this.getBrowseButton().isEnabled() && (this.getField().getValueId() != null);
        } catch (CollectableFieldFormatException ex) {
            bClearEnabled = false;
        }
        miClear.setEnabled(bClearEnabled);

        miClear.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ev) {
                CollectableListOfValues.this.clearListOfValues();
            }
        });
        result.add(miClear);
    }
    return result;
}