List of usage examples for javax.swing JPopupMenu addSeparator
public void addSeparator()
From source file:org.nuclos.client.customcomp.resplan.ResPlanPanel.java
private void initJResPlan() { resPlan = new JResPlanComponent<Collectable, Date, Collectable, Collectable>(resPlanModel, timeModel); resPlan.getTimelineHeader().setCategoryModel(timeGranularityModel.getSelectedItem()); resPlan.addMouseListener(new AbstractJPopupMenuListener() { @Override/* w ww . j a va2 s . co m*/ protected JPopupMenu getJPopupMenu(MouseEvent evt) { JPopupMenu popupMenu = new JPopupMenu(); Point pt = evt.getPoint(); Area<Collectable, Date> blankSelection = resPlan.getSelectedBlankArea(); if (blankSelection != null) { popupMenu.add(new AddAction(blankSelection.getResource(), blankSelection.getInterval())); } else { popupMenu.add(new AddAction(resPlan.getResourceAt(pt), resPlan.getTimeIntervalAt(pt))); } List<Collectable> selectedEntries = selectEntriesForEvent(pt); List<Collectable> selectedRelations = selectRelationsForEvent(pt); if (resPlan.isEditable() && (!selectedEntries.isEmpty() || !selectedRelations.isEmpty())) { JMenuItem menuItem = popupMenu.add(removeAction); boolean enabled = true; for (Collectable clct : selectedEntries) { if (!resPlanModel.isRemoveEntryAllowed(clct)) { enabled = false; break; } } for (Collectable clct : selectedRelations) { if (!resPlanModel.isRemoveRelationAllowed(clct)) { enabled = false; break; } } // Note: just change the state of the menu item (and leave the action as is) menuItem.setEnabled(enabled); } if (!selectedEntries.isEmpty() || !selectedRelations.isEmpty()) { popupMenu.add(detailsAction); } if (selectedEntries.size() == 1 && resPlanModel.getRelationEntity() != null && resPlanModel.isCreateRelationAllowed()) { popupMenu.addSeparator(); if (resPlan.getRelateBegin() != null) { Collectable to = selectedEntries.get(0); if (to != resPlan.getRelateBegin()) { popupMenu.add(relateFinishAction); } } popupMenu.add(relateBeginAction); } return popupMenu; } private List<Collectable> selectEntriesForEvent(Point pt) { List<Collectable> selection = resPlan.getSelectedEntries(); Collectable entryAt = resPlan.getEntryAt(pt); if (entryAt != null && (selection.isEmpty() || !selection.contains(entryAt))) { selection = Collections.singletonList(entryAt); resPlan.setSelectedEntries(selection); } return selection; } private List<Collectable> selectRelationsForEvent(Point pt) { List<Collectable> selection = resPlan.getSelectedRelations(); Collectable relAt = resPlan.getRelationAt(pt); if (relAt != null && (selection.isEmpty() || !selection.contains(relAt))) { selection = Collections.singletonList(relAt); resPlan.setSelectedRelations(selection); } return selection; } @Override public void mouseClicked(MouseEvent evt) { if (evt.getClickCount() == 2) { Collectable clct = resPlan.getEntryAt(evt.getPoint()); if (clct == null) { clct = resPlan.getRelationAt(evt.getPoint()); if (clct != null) { runDetailsCollectable(resPlanModel.getRelationEntity().getEntityName(), clct); } } else { runDetailsCollectable(resPlanModel.getEntryEntity().getEntityName(), clct); } evt.consume(); } } }); resPlan.getResourceHeader().addMouseListener(new AbstractJPopupMenuListener() { @Override public void mouseClicked(MouseEvent evt) { if (evt.getClickCount() == 2) { Collectable clct = resPlan.getResourceHeader().getValueAt(evt.getPoint()); runDetailsCollectable(resPlanModel.getResourceEntity().getEntityName(), clct); evt.consume(); } } @Override protected JPopupMenu getJPopupMenu(MouseEvent evt) { final Collectable clct = resPlan.getResourceHeader().getValueAt(evt.getPoint()); if (clct != null) { JPopupMenu popupMenu = new JPopupMenu(); popupMenu.add(new AbstractAction( SpringLocaleDelegate.getInstance().getText("nuclos.resplan.action.showDetails")) { @Override public void actionPerformed(ActionEvent e) { runDetailsCollectable(resPlanModel.getResourceEntity().getEntityName(), clct); } }); return popupMenu; } return null; } }); Date start = DateUtils.addDays(DateUtils.getPureDate(new Date()), -5); Date end = DateUtils.addDays(start, 30); resPlan.setTimeHorizon(new Interval<Date>(start, end)); }
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 . jav a2s. c o 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 a2s . c o 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.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/*w w w. j a va 2s. c om*/ 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 w w . j av a 2 s .c o m*/ 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/*w w w . java2 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
/** * @param result/*from ww w . j a v a 2 s .c o m*/ * @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.omegat.gui.properties.SegmentPropertiesArea.java
@Override public void populatePaneMenu(JPopupMenu contextMenu) { JMenuItem tableModeItem = new JCheckBoxMenuItem(OStrings.getString("SEGPROP_CONTEXTMENU_TABLE_MODE")); tableModeItem.setSelected(viewImpl.getClass().equals(SegmentPropertiesTableView.class)); tableModeItem.addActionListener(new ActionListener() { @Override/*w ww . ja v a 2 s .c o m*/ public void actionPerformed(ActionEvent e) { toggleMode(SegmentPropertiesTableView.class); } }); JMenuItem listModeItem = new JCheckBoxMenuItem(OStrings.getString("SEGPROP_CONTEXTMENU_LIST_MODE")); listModeItem.setSelected(viewImpl.getClass().equals(SegmentPropertiesListView.class)); listModeItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { toggleMode(SegmentPropertiesListView.class); } }); ButtonGroup group = new ButtonGroup(); group.add(tableModeItem); group.add(listModeItem); contextMenu.add(tableModeItem); contextMenu.add(listModeItem); contextMenu.addSeparator(); final JMenuItem toggleKeyTranslationItem = new JCheckBoxMenuItem( OStrings.getString("SEGPROP_CONTEXTMENU_RAW_KEYS")); toggleKeyTranslationItem.setSelected(Preferences.isPreference(Preferences.SEGPROPS_SHOW_RAW_KEYS)); toggleKeyTranslationItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Preferences.setPreference(Preferences.SEGPROPS_SHOW_RAW_KEYS, toggleKeyTranslationItem.isSelected()); viewImpl.update(); } }); contextMenu.add(toggleKeyTranslationItem); }
From source file:org.openestate.tool.helloworld.HelloWorldObjectViewPanel.java
@Override protected void doShowActions(Component component, int x, int y) { JPopupMenu popup = new JPopupMenu(); popup.add(createDefaultCopyAction(currentObject != null && currentObject.id > 0 && HelloWorldPlugin.isUserAllowedTo(HelloWorldPermission.OBJECTS_EDIT))); popup.add(createDefaultRemoveAction(currentObject != null && currentObject.id > 0 && mayRemoveObject)); boolean addonItemAdded = false; for (ObjectViewExtension addon : addons) { JMenuItem[] items = addon.createActionMenuItems(currentObject); if (ArrayUtils.isEmpty(items)) continue; for (JMenuItem item : items) { if (!addonItemAdded) { addonItemAdded = true;// w w w . j a v a 2 s . com popup.addSeparator(); } popup.add(item); } } popup.show(component, x, y); }
From source file:org.orbisgis.core.ui.plugins.views.geocatalog.Catalog.java
public JPopupMenu getPopup() { JPopupMenu popup = new JPopupMenu(); JComponent[] menus = menuTree.getJMenus(); for (JComponent menu : menus) { popup.add(menu);/*from www . j av a 2 s . co m*/ } if (!tagSources.isEmpty() && lstSources.getSelectedIndices().length > 0) { JMenu menu = new JMenu(I18N.getString("orbisgis.org.orbisgis.core.ui.plugins.views.geocatalog.tag")); Iterator<String> tagsIterator = tagSources.keySet().iterator(); while (tagsIterator.hasNext()) { String tag = tagsIterator.next(); JCheckBoxMenuItem item; if (isSelectionTagged(tag)) { item = new JCheckBoxMenuItem(tag, true); RemoveTagActionListener removeTagAL = new RemoveTagActionListener(tag); item.addActionListener(removeTagAL); } else { item = new JCheckBoxMenuItem(tag, false); AddTagActionListener addTagAL = new AddTagActionListener(tag); item.addActionListener(addTagAL); } menu.add(item); } popup.addSeparator(); popup.add(menu); } return popup; }