List of usage examples for javax.swing JPopupMenu getComponentCount
public int getComponentCount()
From source file:nz.govt.natlib.ndha.manualdeposit.jobmanagement.JobQueueManagement.java
public JPopupMenu getJobQueueMenu(final JTable table) { theTableSelected = table;/* w w w . j a v a 2 s. c o m*/ final JPopupMenu menu = new JPopupMenu(); boolean sortAscending = false; if (table.equals(theJobQueueRunningTable)) { sortAscending = personalSettings.isSortRunningAscending(); } else if (table.equals(theJobQueuePendingTable)) { sortAscending = personalSettings.isSortPendingAscending(); } else if (table.equals(theJobQueueFailedTable)) { sortAscending = personalSettings.isSortFailedAscending(); } else if (table.equals(theJobQueueDepositedTable)) { sortAscending = personalSettings.isSortDepositedAscending(); } else if (table.equals(theJobQueueInPermanentTable)) { sortAscending = personalSettings.isSortCompleteAscending(); } JMenuItem item; if (sortAscending) { item = new JMenuItem("Sort by date in descending order"); } else { item = new JMenuItem("Sort by date in ascending order"); } item.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(final java.awt.event.ActionEvent evt) { resortTable(evt); } }); menu.add(item); if ((table.equals(theJobQueueRunningTable)) || (table.equals(theJobQueuePendingTable)) || (table.equals(theJobQueueFailedTable))) { StringBuffer text = new StringBuffer(); text.append("Cancel job"); if (table.getSelectedRowCount() > 1) { text.append('s'); } item = new JMenuItem(text.toString()); item.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(final java.awt.event.ActionEvent evt) { try { cancelJobs(evt); } catch (JobQueueException ex) { String message = "Error cancelling jobs"; LOG.error(message, ex); mainFrame.showError("An error occurred", message, ex); } } }); menu.add(item); if (table.equals(theJobQueueFailedTable)) { text = new StringBuffer(); text.append("Resubmit job"); if (table.getSelectedRowCount() > 1) { text.append('s'); } item = new JMenuItem(text.toString()); item.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(final java.awt.event.ActionEvent evt) { resubmitJob(evt); } }); menu.add(item); } } if (table.equals(theJobQueueInPermanentTable)) { item = new JMenuItem("Clear completed jobs"); item.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(final java.awt.event.ActionEvent evt) { clearFinishedJobs(evt); } }); menu.add(item); } if (menu == null || menu.getComponentCount() == 0) { return null; } else { return menu; } }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java
public JPopupMenu getFileSystemMenu(final DefaultMutableTreeNode node) { JPopupMenu menu = null; fsoRootFileTemp = null;//from w ww.j a v a2s.c om if (node.getUserObject() instanceof FileSystemObject) { boolean allowBulkUpload = false; final FileSystemObject fso = (FileSystemObject) node.getUserObject(); menu = new JPopupMenu(); if ((fso != null) && (fso.getFile() != null) && (fso.getFile().exists())) { if (!entityRootSet) { stopEditingMetaData(); allowBulkUpload = applicationProperties.getUserData() .getUser(applicationProperties.getLoggedOnUser()).isAllowBulkLoad(); String addRootText; boolean canAddMultiRoot = false; setCustomizeMetaData(false); if (fso.getIsFile()) { addRootText = "Use file to describe IE root"; final DefaultMutableTreeNode nodeParent = (DefaultMutableTreeNode) node.getParent(); if (nodeParent.getUserObject() instanceof FileSystemObject) { fsoRootTemp = (FileSystemObject) nodeParent.getUserObject(); fsoRootFileTemp = fso; } else { fsoRootTemp = fso; } } else { addRootText = "Set as root of Intellectual Entity"; canAddMultiRoot = (userGroupData != null && userGroupData.isIncludeMultiEntityMenuItem()); fsoRootTemp = fso; } JMenuItem item = new JMenuItem(addRootText); item.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(final java.awt.event.ActionEvent evt) { manualDepositFrame.setWaitCursor(true); itmSetRootActionPerformed(evt); manualDepositFrame.setWaitCursor(false); } }); menu.add(item); if (canAddMultiRoot) { item = new JMenuItem("Set each file as an Intellectual Entity"); item.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(final java.awt.event.ActionEvent evt) { itmSetMultipleRootActionPerformed(evt); } }); menu.add(item); // Added 5/09/2013 by Ben // New menu option for creating multiple complex IEs item = new JMenuItem("Set each folder as an Intellectual Entity"); item.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(final java.awt.event.ActionEvent evt) { itmSetMultipleRootFolderActionPerformed(evt); } }); menu.add(item); } } if (fso.getIsFile()) { if (menu.getComponentCount() > 0) { menu.addSeparator(); } if (isWindows()) { JMenuItem item = new JMenuItem("Open File"); item.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(final java.awt.event.ActionEvent evt) { itmOpenFile(evt); } }); menu.add(item); item = new JMenuItem("Open File Location"); item.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(final java.awt.event.ActionEvent evt) { itmOpenFileLocation(evt); } }); menu.add(item); } } else { if (menu.getComponentCount() > 0) { menu.addSeparator(); } JMenuItem item = new JMenuItem("Store this directory as a favourite"); item.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(final java.awt.event.ActionEvent evt) { itmStoreAsFavourite(evt); } }); menu.add(item); item = new JMenuItem("Refresh directory file list"); item.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(final java.awt.event.ActionEvent evt) { itmRefreshDirectory(evt); } }); menu.add(item); if (allowBulkUpload) { item = new JMenuItem("Bulk load this directory"); item.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(final java.awt.event.ActionEvent evt) { bulkLoadDirectory(evt); } }); if (!metaDataOkay(false)) { item.setEnabled(false); item.setToolTipText("Meta data incomplete"); } menu.add(item); item = new JMenuItem("Bulk load each file as an Intellectual Entity"); item.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(final java.awt.event.ActionEvent evt) { bulkLoadDirectoryAsIEs(evt); } }); if (!metaDataOkay(false)) { item.setEnabled(false); item.setToolTipText("Meta data incomplete"); } menu.add(item); } } } } if (menu == null || menu.getComponentCount() == 0) { return null; } else { return menu; } }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java
private JPopupMenu getEntityMenu(FileSystemObject fso) { final JPopupMenu menu = new JPopupMenu(); if (fso.getIsFile()) { JMenuItem item;/*from ww w . j a va 2 s . c o m*/ ArrayList<FileGroupCollection> entities = getEntities(); if (entities.size() == 1) { item = new JMenuItem("Delete File"); item.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { itmDeleteEntityItem(evt); } }); menu.add(item); } item = new JMenuItem("Rename File"); item.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { itmRenameEntity(evt); } }); menu.add(item); if (menu.getComponentCount() > 0) { menu.addSeparator(); } item = new JMenuItem("Open File"); item.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { itmOpenFile(evt); } }); menu.add(item); } else { JMenuItem item = new JMenuItem("Delete Directory (and children)"); item.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { itmDeleteEntityItem(evt); } }); menu.add(item); item = new JMenuItem("Rename Directory"); item.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { itmRenameEntity(evt); } }); menu.add(item); } return menu; }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenterTest.java
@Test public final void testGetFileSystemMenu() { // Includes a test for setting the root entity DefaultMutableTreeNode node = new DefaultMutableTreeNode("Nothing"); JPopupMenu menu = depositPresenter.getFileSystemMenu(node); // menu should be null if the user object isn't a FileSystemObject assertTrue(menu == null);//from w w w . j ava 2s .c o m File theFile = new File(RESOURCES_INPUT_SOUND); String description = "ManualDeposit"; FileSystemObject root = new FileSystemObject(description, theFile, null); node = new DefaultMutableTreeNode(root); AppProperties props = depositPresenter.getAppProperties(); UserGroupData userGroupData = null; try { userGroupData = props.getUserData().getUser(props.getLoggedOnUser()).getUserGroupData(); } catch (Exception ex) { fail(); } userGroupData.setIncludeMultiEntityMenuItem(false); menu = depositPresenter.getFileSystemMenu(node); assertTrue(menu != null); int menuCount = menu.getComponentCount(); assertTrue(menuCount >= 1); try { depositPresenter.setupScreen(); } catch (Exception ex) { fail(); } userGroupData.setIncludeMultiEntityMenuItem(true); menu = depositPresenter.getFileSystemMenu(node); assertTrue(menu != null && menu.getComponentCount() == menuCount + 2); try { depositPresenter.setupScreen(); } catch (Exception ex) { fail(); } theFile = new File(RESOURCES_INPUT_SOUND + "/Preservation Copy/OHC-0000_s_1.wav"); description = "OHC-0000_s_1.wav"; FileSystemObject newRoot = new FileSystemObject(description, theFile, null); DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(newRoot); node.add(childNode); userGroupData.setIncludeMultiEntityMenuItem(false); menu = depositPresenter.getFileSystemMenu(childNode); assertTrue(menu != null); menuCount = menu.getComponentCount(); assertTrue(menuCount >= 1); try { depositPresenter.setupScreen(); } catch (Exception ex) { fail(); } userGroupData.setIncludeMultiEntityMenuItem(true); menu = depositPresenter.getFileSystemMenu(childNode); assertTrue(menu != null && menu.getComponentCount() == menuCount); root = setRoot(); // assertTrue(_presenter _theFrame._rootNode.equals(root)); assertFalse(theFrame.cursorIsWaiting); // node = new DefaultMutableTreeNode(root); // menu = _presenter.getFileSystemMenu(node); // menu should have at least one item // When the menu is fixed, implement this check // assertTrue(menu != null && menu.getComponentCount() >= 1); assertFalse(theFrame.cursorIsWaiting); }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenterTest.java
@Test public final void testGetEntityMenu() { String entityName = "Nothing"; DefaultMutableTreeNode node = new DefaultMutableTreeNode(entityName); JPopupMenu menu = depositPresenter.getEntityMenu(node); // menu should be null if the entity root hasn't been set assertTrue(menu == null);// www .jav a2 s . c o m FileSystemObject root = setRoot(); FileGroupCollection groups = new FileGroupCollection(entityName, root.getFullPath()); FileGroup group = FileGroup.create(entityName, "", RepresentationTypes.DigitalOriginal, root.getChildren()); // FileGroup group = new FileGroup(entityName, // RepresentationTypes.DigitalOriginal, root.getChildren()); try { groups.add(group); } catch (Exception ex) { fail(); } try { Thread.sleep(500); } catch (InterruptedException e) { } node = new DefaultMutableTreeNode(groups); menu = depositPresenter.getEntityMenu(node); // Should have at least two items - "Rename Intellectual Entity" & // "Add Entity" // Text may change so only check that they're there assertTrue(menu != null && menu.getComponentCount() > 1); FileGroup entity = FileGroup.create("Test Entity", "", RepresentationTypes.DigitalOriginal, root.getChildren()); // FileGroup entity = new FileGroup("Test Entity", // RepresentationTypes.DigitalOriginal, root.getChildren()); try { depositPresenter.getEntities().get(0).add(entity); } catch (Exception ex) { fail(); } node = new DefaultMutableTreeNode(entity); menu = depositPresenter.getEntityMenu(node); // Should have at one item - "Delete Entity" // "Rename Entity" has been deleted // Text may change so only check that they're there // assertTrue(menu != null && menu.getComponentCount() > 1); assertTrue(menu != null && menu.getComponentCount() == 1); FileSystemObject fso = root.getChildren().get(0); node = new DefaultMutableTreeNode(fso); menu = depositPresenter.getEntityMenu(node); try { Thread.sleep(500); } catch (InterruptedException e) { } // Should have at least two items - "Delete" & "Rename" // Applies to both file & directory, though the text is different for // each assertTrue(menu != null && menu.getComponentCount() > 1); assertFalse(theFrame.cursorIsWaiting); }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenterTest.java
@Test public final void testGetStructMapMenu() { DefaultMutableTreeNode node = new DefaultMutableTreeNode("Nothing"); JPopupMenu menu = depositPresenter.getStructMapMenu(node); // menu should be null if the entity root hasn't been set assertTrue(menu == null);//from ww w. j av a2 s .co m FileSystemObject root = setRoot(); try { Thread.sleep(500); } catch (InterruptedException e) { } menu = depositPresenter.getStructMapMenu(node); // Should have at one item - "Add Structure Item" // Text may change so only check that it's there assertTrue(menu != null && menu.getComponentCount() == 1); StructMap map = new StructMap("Test Entity", null, root.getChildren(), 0); // _theFrame.getStructures().add(map); node = new DefaultMutableTreeNode(map); menu = depositPresenter.getStructMapMenu(node); // Should have at least 3 items - "Delete" & "Rename" & "Add" // Text may change so only check that they're there assertTrue(menu != null && menu.getComponentCount() > 2); FileSystemObject fso = root.getChildren().get(0); node = new DefaultMutableTreeNode(fso); menu = depositPresenter.getStructMapMenu(node); try { Thread.sleep(500); } catch (InterruptedException e) { } // Should have one item - "Delete" // Text may change so only check that it's there assertTrue(menu != null && menu.getComponentCount() == 1); assertFalse(theFrame.cursorIsWaiting); }
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//from w w w . j a va2 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//ww w .jav a 2 s .c o m * @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.orbisgis.sif.components.fstree.TreeNodeFolder.java
@Override public void feedPopupMenu(JPopupMenu menu) { if (menu.getComponentCount() > 0) { menu.addSeparator();/*from www .j a va 2 s . com*/ } // Open the folder JMenuItem copyPathMenu = new JMenuItem(I18N.tr("Copy the path")); copyPathMenu.setToolTipText(I18N.tr("Copy the folder path in the clipboard")); copyPathMenu.setActionCommand("TreeNodeFolder:CopyPath"); copyPathMenu.addActionListener(EventHandler.create(ActionListener.class, this, "onCopyPath")); MenuCommonFunctions.updateOrInsertMenuItem(menu, copyPathMenu); // Read the file system to update the tree JMenuItem updateMenu = new JMenuItem(I18N.tr("Update"), SifIcon.getIcon("refresh")); updateMenu.setToolTipText(I18N.tr("Update the content of this folder from the file system")); updateMenu.setActionCommand("Update"); updateMenu.addActionListener(EventHandler.create(ActionListener.class, this, "updateTree")); MenuCommonFunctions.updateOrInsertMenuItem(menu, updateMenu); // Add a new Sub Folder JMenuItem newSubFolder = new JMenuItem(I18N.tr("New folder"), SifIcon.getIcon("folder_add")); newSubFolder.setToolTipText(I18N.tr("Create a sub-folder")); newSubFolder.setActionCommand("TreeNodeFolder:newSubFolder"); newSubFolder.addActionListener(EventHandler.create(ActionListener.class, this, "onNewSubFolder")); MenuCommonFunctions.updateOrInsertMenuItem(menu, newSubFolder); // Remove the folder //The root folder cannot be removed if (parent instanceof TreeNodeFolder) { JMenuItem folderRemove = new JMenuItem(I18N.tr("Delete"), SifIcon.getIcon("remove")); folderRemove.setToolTipText(I18N.tr("Remove permanently the folder")); folderRemove.setActionCommand("delete"); folderRemove.addActionListener(EventHandler.create(ActionListener.class, this, "onDeleteFolder")); MenuCommonFunctions.updateOrInsertMenuItem(menu, folderRemove, true); } }
From source file:org.orbisgis.view.components.fstree.TreeNodeFolder.java
@Override public void feedPopupMenu(JPopupMenu menu) { if (menu.getComponentCount() > 0) { menu.addSeparator();// www.ja v a2 s.com } // Open the folder JMenuItem copyPathMenu = new JMenuItem(I18N.tr("Copy the path")); copyPathMenu.setToolTipText(I18N.tr("Copy the folder path in the clipboard")); copyPathMenu.setActionCommand("TreeNodeFolder:CopyPath"); copyPathMenu.addActionListener(EventHandler.create(ActionListener.class, this, "onCopyPath")); MenuCommonFunctions.updateOrInsertMenuItem(menu, copyPathMenu); // Read the file system to update the tree JMenuItem updateMenu = new JMenuItem(I18N.tr("Update"), OrbisGISIcon.getIcon("arrow_refresh")); updateMenu.setToolTipText(I18N.tr("Update the content of this folder from the file system")); updateMenu.setActionCommand("Update"); updateMenu.addActionListener(EventHandler.create(ActionListener.class, this, "updateTree")); MenuCommonFunctions.updateOrInsertMenuItem(menu, updateMenu); // Add a new Sub Folder JMenuItem newSubFolder = new JMenuItem(I18N.tr("New folder"), OrbisGISIcon.getIcon("folder_add")); newSubFolder.setToolTipText(I18N.tr("Create a sub-folder")); newSubFolder.setActionCommand("TreeNodeFolder:newSubFolder"); newSubFolder.addActionListener(EventHandler.create(ActionListener.class, this, "onNewSubFolder")); MenuCommonFunctions.updateOrInsertMenuItem(menu, newSubFolder); // Remove the folder //The root folder cannot be removed if (parent instanceof TreeNodeFolder) { JMenuItem folderRemove = new JMenuItem(I18N.tr("Delete"), OrbisGISIcon.getIcon("remove")); folderRemove.setToolTipText(I18N.tr("Remove permanently the folder")); folderRemove.setActionCommand("delete"); folderRemove.addActionListener(EventHandler.create(ActionListener.class, this, "onDeleteFolder")); MenuCommonFunctions.updateOrInsertMenuItem(menu, folderRemove, true); } }