public ViewPopupMenu(DcObject dco, int viewType, int viewIdx) {
this.dco = dco;
DcModule current = DcModules.getCurrent();
DcModule module = dco.getModule();
if (viewType == View._TYPE_SEARCH &&
!module.isChildModule() &&
!(current.getIndex() == DcModules._CONTAINER &&
dco.getModule().getIndex() != DcModules._CONTAINER)) {
if (module.isAbstract())
PluginHelper.add(this, "SaveSelected");
PluginHelper.add(this, "OpenItem");
if (module.getIndex() != DcModules._USER)
PluginHelper.add(this, "EditAsNew", null, dco, null, -1, module.getIndex());
}
String filename = dco.getFilename();
File file = !Utilities.isEmpty(filename) ? new File(filename) : null;
if (viewType == View._TYPE_SEARCH) {
if (dco.getModule().getParent() != null) {
// in case a child is selected, make sure its the child which is going to be deleted
// and not the parent (via the DcModules.getCurrent(), which returns the parent).
PluginHelper.add(this, "Delete", module.getIndex());
} else if ((current.getIndex() == DcModules._CONTAINER && dco.getModule().getIndex() != DcModules._CONTAINER)) {
PluginHelper.add(this, "Delete", DcModules._ITEM);
} else {
// make sure the actual SELECTED module is used for deleting the item. otherwise, if
// the media module is selected, the item from the, for example, software module view
// is deleted.
PluginHelper.add(this, "Delete", DcModules.getCurrent().getIndex());
}
if (file != null && SecurityCentre.getInstance().getUser().isAdmin() && dco.getModule().isFileBacked()) {
JMenu menuFile = ComponentFactory.getMenu(IconLibrary._icoDriveManager, DcResources.getText("lblFile"));
JMenuItem miDelete = ComponentFactory.getMenuItem(IconLibrary._icoDelete, DcResources.getText("lblDeleteFile"));
miDelete.addActionListener(this);
miDelete.setActionCommand("deleteFile");
miDelete.setEnabled(file.exists());
JMenuItem miMove = ComponentFactory.getMenuItem(DcResources.getText("lblMoveFile"));
miMove.addActionListener(this);
miMove.setActionCommand("moveFile");
miMove.setEnabled(file.exists());
JMenuItem miLocateHP = ComponentFactory.getMenuItem(IconLibrary._icoDriveScanner, DcResources.getText("lblLocateFile", DcResources.getText("lblMatchOnHashAndSize")));
miLocateHP.addActionListener(this);
miLocateHP.setActionCommand("locateFileHP");
miLocateHP.setEnabled(!file.exists() && dco.isFilled(DcObject._SYS_FILEHASH) && dco.isFilled(DcObject._SYS_FILESIZE));
JMenuItem miLocateMP = ComponentFactory.getMenuItem(IconLibrary._icoDriveScanner, DcResources.getText("lblLocateFile", DcResources.getText("lblMatchOnFilenameAndSize")));
miLocateMP.addActionListener(this);
miLocateMP.setActionCommand("locateFileMP");
miLocateMP.setEnabled(!file.exists() && dco.isFilled(DcObject._SYS_FILESIZE));
JMenuItem miLocateLP = ComponentFactory.getMenuItem(IconLibrary._icoDriveScanner, DcResources.getText("lblLocateFile", DcResources.getText("lblMatchOnFilename")));
miLocateLP.addActionListener(this);
miLocateLP.setActionCommand("locateFileLP");
miLocateLP.setEnabled(!file.exists());
menuFile.add(miDelete);
menuFile.add(miMove);
menuFile.add(miLocateHP);
menuFile.add(miLocateMP);
menuFile.add(miLocateLP);
addSeparator();
add(menuFile);
}
} else {
PluginHelper.add(this, "RemoveRow", DcModules.getCurrent().getIndex());
PluginHelper.add(this, "AddRow", DcModules.getCurrent().getIndex());
}
if (viewType == View._TYPE_SEARCH &&
module.getIndex() == DcModules._USER &&
SecurityCentre.getInstance().getUser().isAuthorized("SetPassword")) {
addSeparator();
PluginHelper.add(this, "SetPassword", "", dco, null, viewType, DcModules.getCurrent().getIndex());
}
if (!DcModules.getCurrent().isAbstract()) {
addSeparator();
PluginHelper.add(this, "ItemExporterWizard", "", dco, null, viewIdx, dco.getModule().getIndex());
}
if (viewType == View._TYPE_SEARCH && DcModules.getCurrent().hasReports()) {
PluginHelper.add(this, "Report", "", dco, null, viewIdx, DcModules.getCurrent().getIndex());
}
addSeparator();
PluginHelper.add(this, "Sort");
if ( viewType == View._TYPE_SEARCH &&
module.canBeLend() &&
SecurityCentre.getInstance().getUser().isAuthorized("Loan")) {
addSeparator();
PluginHelper.add(this, "Loan");
}
addSeparator();
JMenu menuAdmin = ComponentFactory.getMenu(IconLibrary._icoModuleTypeProperty16, DcResources.getText("lblAdministration"));
Collection<DcPropertyModule> modules = new ArrayList<DcPropertyModule>();
for (DcFieldDefinition definition : module.getFieldDefinitions().getDefinitions()) {
DcField field = module.getField(definition.getIndex());
DcPropertyModule pm = DcModules.getPropertyModule(field);
if (pm != null && !modules.contains(pm))
modules.add(pm);
}
for (DcModule pm : modules) {
try {
Plugin plugin = Plugins.getInstance().get("ManageItem", dco, null, viewIdx, pm.getIndex());
if ( plugin != null &&SecurityCentre.getInstance().getUser().isAuthorized(plugin) &&
UserMode.isCorrectXpLevel(plugin.getXpLevel())) {
JMenuItem item = ComponentFactory.getMenuItem(plugin);
item.setEnabled(plugin.isEnabled());
item.setIcon(plugin.getIcon());
menuAdmin.add(item);
}
} catch (InvalidPluginException e) {
logger.error(e, e);
}
}
if (menuAdmin.getItemCount() > 0)
add(menuAdmin);
addSeparator();
PluginHelper.add(this, "ViewSettings");
if (viewType == View._TYPE_SEARCH) {
FileImporter importer = module.getImporter();
if (importer != null && importer.allowReparsing() && module.getFileField() != null) {
addSeparator();
PluginHelper.add(this, "AttachFileInfo");
}
}
addSeparator();
if (current.getIndex() != DcModules._ITEM) {
PluginHelper.add(this, "UpdateAll", module.getIndex());
PluginHelper.add(this, "FindReplace", module.getIndex());
}
if (file != null && dco.getModule().isFileBacked())
PluginHelper.add(this, "FileLauncher", module.getIndex());
Collection<Plugin> plugins = Plugins.getInstance().getUserPlugins(dco, viewType, module.getIndex());
for (Plugin plugin : plugins) {
if (plugin.isShowInPopupMenu()) {
addSeparator();
add(ComponentFactory.getMenuItem(plugin));
}