From 60b09ee10314bdbffb54767e386adef13f2786ec Mon Sep 17 00:00:00 2001 From: Allen Byrne <50328838+byrnHDF@users.noreply.github.com> Date: Mon, 4 Dec 2023 15:34:07 -0600 Subject: [PATCH] Convert plugin option to a list (#169) * Implement plugins path option as a list --- .../hdf/view/HDFView.java | 17 +- .../hdf/view/ViewProperties.java | 615 ++++++++++++++---- .../view/dialog/UserOptionsGeneralPage.java | 39 +- .../hdf/view/dialog/UserOptionsHDFPage.java | 263 +++++--- .../hdf/object/h5/H5Plugins.java | 67 ++ 5 files changed, 734 insertions(+), 267 deletions(-) diff --git a/src/org.hdfgroup.hdfview/hdf/view/HDFView.java b/src/org.hdfgroup.hdfview/hdf/view/HDFView.java index 7d1ff53d..c8a841b6 100644 --- a/src/org.hdfgroup.hdfview/hdf/view/HDFView.java +++ b/src/org.hdfgroup.hdfview/hdf/view/HDFView.java @@ -295,7 +295,7 @@ public HDFView(String root, String start_dir) } if (FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5) != null) - H5.H5PLappend(ViewProperties.getPluginDir()); + ViewProperties.loadPluginPaths(); treeViews = ViewProperties.getTreeViewList(); metaDataViews = ViewProperties.getMetaDataViewList(); @@ -937,9 +937,6 @@ public void widgetSelected(SelectionEvent e) // currentDir until isWorkDirChanged() is fixed currentDir = ViewProperties.getWorkDir(); - if (FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5) != null) - H5.H5PLappend(ViewProperties.getPluginDir()); - // if (userOptionDialog.isFontChanged()) { Font font = null; @@ -1381,26 +1378,36 @@ public void drop(DropTargetEvent e) } /** + * Get a list of treeview implementations. + * * @return a list of treeview implementations. */ public static final List getListOfTreeViews() { return treeViews; } /** + * Get a list of imageview implementations. + * * @return a list of imageview implementations. */ public static final List getListOfImageViews() { return imageViews; } /** + * Get a list of tableview implementations. + * * @return a list of tableview implementations. */ public static final List getListOfTableViews() { return tableViews; } /** + * Get a list of metaDataview implementations. + * * @return a list of metaDataview implementations. */ public static final List getListOfMetaDataViews() { return metaDataViews; } /** + * Get a list of paletteview implementations. + * * @return a list of paletteview implementations. */ public static final List getListOfPaletteViews() { return paletteViews; } @@ -1412,6 +1419,8 @@ public TreeView getTreeView() } /** + * Get the combobox associated with a URL entry. + * * @return the combobox associated with a URL entry. */ public Combo getUrlBar() { return urlBar; } diff --git a/src/org.hdfgroup.hdfview/hdf/view/ViewProperties.java b/src/org.hdfgroup.hdfview/hdf/view/ViewProperties.java index b8a6922f..f1c01df7 100644 --- a/src/org.hdfgroup.hdfview/hdf/view/ViewProperties.java +++ b/src/org.hdfgroup.hdfview/hdf/view/ViewProperties.java @@ -124,15 +124,15 @@ public class ViewProperties extends PreferenceStore { * Used to create different DataViews for a given HObject. */ public static enum DataViewType { - /** */ + /** table type */ TABLE, - /** */ + /** image type */ IMAGE, - /** */ + /** palette type */ PALETTE, - /** */ + /** metadata type */ METADATA, - /** */ + /** treeview type */ TREEVIEW } @@ -140,27 +140,27 @@ public static enum DataViewType { * Property keys control how the data is displayed. */ public static enum DATA_VIEW_KEY { - /** */ + /** data is char */ CHAR, - /** */ + /** data is converted to byte */ CONVERTBYTE, - /** */ + /** data is transposed */ TRANSPOSED, - /** */ + /** data is read only */ READONLY, - /** */ + /** data is object */ OBJECT, - /** */ + /** data is bitmask */ BITMASK, - /** */ + /** data is bitmask op */ BITMASKOP, - /** */ + /** data is border */ BORDER, - /** */ + /** data is info */ INFO, - /** */ + /** data is index based 1 */ INDEXBASE1, - /** */ + /** data is view name */ VIEW_NAME } @@ -168,9 +168,9 @@ public static enum DATA_VIEW_KEY { * Property keys control how the data is displayed. */ public static enum BITMASK_OP { - /** */ + /** use bitmask and */ AND, - /** */ + /** use bitmask extract */ EXTRACT } @@ -212,12 +212,6 @@ public static enum BITMASK_OP { private static ClassLoader extClassLoader = null; - /** default plugin directory */ - private static String pluginDir = System.getProperty("user.dir") + "/plugin"; - - /** a list of plugin paths */ - private static ArrayList pluginPaths = new ArrayList<>(50); - /** a list of srb accounts */ private static ArrayList srbAccountList = new ArrayList<>(5); @@ -255,7 +249,7 @@ public static enum BITMASK_OP { private static ArrayList paletteList = new ArrayList<>(5); /** a list of plugin paths */ - private static ArrayList pluginPathList = new ArrayList<>(5); + private static ArrayList pluginPathList = new ArrayList<>(5); /** flag to indicate if enum data is converted to strings */ private static boolean convertEnum = true; @@ -333,8 +327,6 @@ public ViewProperties(String viewRoot, String viewStart) setUsersGuide(rootDir + usersGuide); - setPluginDir(rootDir + "/plugin"); - setDefault("users.guide", viewRoot + "/UsersGuide/index.html"); setDefault("image.contrast", false); setDefault("image.showvalues", false); @@ -557,160 +549,368 @@ else if (PaletteViewFactory.class.isAssignableFrom(theClass)) { return extClassLoader; } - /** @return the Folder Close Icon */ + /** + * Get the Folder Close Icon + * + * @return the Folder Close Icon + */ public static Image getFoldercloseIcon() { return foldercloseIcon; } - /** @return the Folder Close with Attribute Icon */ + /** + * Get the Folder Close with Attribute Icon + * + * @return the Folder Close with Attribute Icon + */ public static Image getFoldercloseIconA() { return foldercloseIconA; } - /** @return the Folder Open Icon */ + /** + * Get the Folder Open Icon + * + * @return the Folder Open Icon + */ public static Image getFolderopenIcon() { return folderopenIcon; } - /** @return the Folder Open with Attribute Icon */ + /** + * Get the Folder Open with Attribute Icon + * + * @return the Folder Open with Attribute Icon + */ public static Image getFolderopenIconA() { return folderopenIconA; } - /** @return the HDF Icon */ + /** + * Get the HDF Icon + * + * @return the HDF Icon + */ public static Image getHdfIcon() { return hdfIcons[1]; } - /** @return the HDF Icons */ + /** + * Get the HDF Icons + * + * @return the HDF Icons + */ public static Image[] getHdfIcons() { return hdfIcons; } - /** @return the HDF4 Icon */ + /** + * Get the HDF4 Icon + * + * @return the HDF4 Icon + */ public static Image getH4Icon() { return h4Icon; } - /** @return the read-only HDF4 Icon */ + /** + * Get the read-only HDF4 Icon + * + * @return the read-only HDF4 Icon + */ public static Image getH4IconR() { return h4IconR; } - /** @return the HDF5 Icon */ + /** + * Get the HDF5 Icon + * + * @return the HDF5 Icon + */ public static Image getH5Icon() { return h5Icon; } - /** @return the read-only HDF5 Icon */ + /** + * Get the read-only HDF5 Icon + * + * @return the read-only HDF5 Icon + */ public static Image getH5IconR() { return h5IconR; } - /** @return the netcdf Icon */ + /** + * Get the netcdf Icon + * + * @return the netcdf Icon + */ public static Image getNC3Icon() { return ncIcon; } - /** @return the read-only netcdf Icon */ + /** + * Get the read-only netcdf Icon + * + * @return the read-only netcdf Icon + */ public static Image getNC3IconR() { return ncIconR; } - /** @return the Dataset Icon */ + /** + * Get the Dataset Icon + * + * @return the Dataset Icon + */ public static Image getDatasetIcon() { return datasetIcon; } - /** @return the Dataset with Attribute Icon */ + /** + * Get the Dataset with Attribute Icon + * + * @return the Dataset with Attribute Icon + */ public static Image getDatasetIconA() { return datasetIconA; } - /** @return the Datatype Icon */ + /** + * Get the Datatype Icon + * + * @return the Datatype Icon + */ public static Image getDatatypeIcon() { return datatypeIcon; } - /** @return the Datatype with Attribute Icon */ + /** + * Get the Datatype with Attribute Icon + * + * @return the Datatype with Attribute Icon + */ public static Image getDatatypeIconA() { return datatypeIconA; } - /** @return the Link Icon */ + /** + * Get the Link Icon + * + * @return the Link Icon + */ public static Image getLinkIcon() { return linkIcon; } - /** @return the File Open Icon */ + /** + * Get the File Open Icon + * + * @return the File Open Icon + */ public static Image getFileopenIcon() { return fileopenIcon; } - /** @return the File Save Icon */ + /** + * Get the File Save Icon + * + * @return the File Save Icon + */ public static Image getFilesaveIcon() { return filesaveIcon; } - /** @return the File New Icon */ + /** + * Get the File New Icon + * + * @return the File New Icon + */ public static Image getFilenewIcon() { return filenewIcon; } - /** @return the File Close Icon */ + /** + * Get the File Close Icon + * + * @return the File Close Icon + */ public static Image getFilecloseIcon() { return filecloseIcon; } - /** @return the Palette Icon */ + /** + * Get the Palette Icon + * + * @return the Palette Icon + */ public static Image getPaletteIcon() { return paletteIcon; } - /** @return the Bright Icon */ + /** + * Get the Bright Icon + * + * @return the Bright Icon + */ public static Image getBrightIcon() { return brightIcon; } - /** @return the Autocontrast Icon */ + /** + * Get the Autocontrast Icon + * + * @return the Autocontrast Icon + */ public static Image getAutocontrastIcon() { return autocontrastIcon; } - /** @return the Image Icon */ + /** + * Get the Image Icon + * + * @return the Image Icon + */ public static Image getImageIcon() { return imageIcon; } - /** @return the Table Icon */ + /** + * Get the Table Icon + * + * @return the Table Icon + */ public static Image getTableIcon() { return tableIcon; } - /** @return the Text Icon */ + /** + * Get the Text Icon + * + * @return the Text Icon + */ public static Image getTextIcon() { return textIcon; } - /** @return the Image with Attribute Icon */ + /** + * Get the Image with Attribute Icon + * + * @return the Image with Attribute Icon + */ public static Image getImageIconA() { return imageIconA; } - /** @return the Table with Attribute Icon */ + /** + * Get the Table with Attribute Icon + * + * @return the Table with Attribute Icon + */ public static Image getTableIconA() { return tableIconA; } - /** @return the Text with Attribute Icon */ + /** + * Get the Text with Attribute Icon + * + * @return the Text with Attribute Icon + **/ public static Image getTextIconA() { return textIconA; } - /** @return the Zoom In Icon */ + /** + * Get the Zoom In Icon + * + * @return the Zoom In Icon + */ public static Image getZoominIcon() { return zoominIcon; } - /** @return the Zoom Out Icon */ + /** + * Get the Zoom Out Icon + * + * @return the Zoom Out Icon + */ public static Image getZoomoutIcon() { return zoomoutIcon; } - /** @return the Blank Icon */ + /** + * Get the Blank Icon + * + * @return the Blank Icon + */ public static Image getBlankIcon() { return blankIcon; } - /** @return the Help Icon */ + /** + * Get the Help Icon + * + * @return the Help Icon + */ public static Image getHelpIcon() { return helpIcon; } - /** @return the Copy Icon */ + /** + * Get the Copy Icon + * + * @return the Copy Icon + */ public static Image getCopyIcon() { return copyIcon; } - /** @return the Cut Icon */ + /** + * Get the Cut Icon + * + * @return the Cut Icon + */ public static Image getCutIcon() { return cutIcon; } - /** @return the Paste Icon */ + /** + * Getthe Paste Icon + * + * @return the Paste Icon + */ public static Image getPasteIcon() { return pasteIcon; } - /** @return the HDFView Icon */ + /** + * Get the HDFView Icon + * + * @return the HDFView Icon + */ public static Image getHDFViewIcon() { return hdfviewIcon; } - /** @return the Large HDF Icon */ + /** + * Get the Large HDF Icon + * + * @return the Large HDF Icon + */ public static Image getLargeHdfIcon() { return hdfIcons[2]; } - /** @return the Previous Icon */ + /** + * Get the Previous Icon + * + * @return the Previous Icon + */ public static Image getPreviousIcon() { return previousIcon; } - /** @return the Next Icon */ + /** + * Get the Next Icon + * + * @return the Next Icon + */ public static Image getNextIcon() { return nextIcon; } - /** @return the First Icon */ + /** + * Get the First Icon + * + * @return the First Icon + */ public static Image getFirstIcon() { return firstIcon; } - /** @return the Last Icon */ + /** + * Get the Last Icon + * + * @return the Last Icon + */ public static Image getLastIcon() { return lastIcon; } - /** @return the Chart Icon */ + /** + * Get the Chart Icon + * + * @return the Chart Icon + */ public static Image getChartIcon() { return chartIcon; } - /** @return the Animation Icon */ + /** + * Get the Animation Icon + * + * @return the Animation Icon + */ public static Image getAnimationIcon() { return animationIcon; } - /** @return the Apps Icon */ + /** + * Get the Apps Icon + * + * @return the Apps Icon + */ public static Image getAppsIcon() { return iconAPPS; } - /** @return the Url Icon */ + /** + * Get the Url Icon + * + * @return the Url Icon + */ public static Image getUrlIcon() { return iconURL; } - /** @return the Video Icon */ + /** + * Get the Video Icon + * + * @return the Video Icon + */ public static Image getVideoIcon() { return iconVIDEO; } - /** @return the Xls Icon */ + /** + * Get the Xls Icon + * + * @return the Xls Icon + */ public static Image getXlsIcon() { return iconXLS; } - /** @return the Pdf Icon */ + /** + * Get the Pdf Icon + * + * @return the Pdf Icon + */ public static Image getPdfIcon() { return iconPDF; } - /** @return the Audio Icon */ + /** + * Get the Audio Icon + * + * @return the Audio Icon + */ public static Image getAudioIcon() { return iconAUDIO; } - /** @return the Question Icon */ + /** + * Get the Question Icon + * + * @return the Question Icon + */ public static Image getQuestionIcon() { return questionIcon; } /** Load the Icons */ @@ -1367,10 +1567,6 @@ public void load() throws IOException if (!isDefault("work.dir")) setWorkDir(propVal); - propVal = getString("plugin.dir"); - if (!isDefault("plugin.dir")) - setPluginDir(propVal); - propVal = getString("file.extension"); if (!isDefault("file.extension")) { setFileExtension(propVal); @@ -1482,9 +1678,6 @@ public void save() throws IOException if (workDir != null) setValue("work.dir", workDir); - if (pluginDir != null) - setValue("plugin.dir", pluginDir); - if (fileExt != null) setValue("file.extension", fileExt); @@ -1609,13 +1802,25 @@ else if (isReadSWMR) super.save(); } - /** @return the name of the user property file */ + /** + * Get the name of the user property file + * + * @return the name of the user property file + */ public static String getPropertyFile() { return propertyFile; } - /** @return the root directory where the HDFView is installed. */ + /** + * Get the root directory where the HDFView is installed. + * + * @return the root directory where the HDFView is installed. + */ public static String getViewRoot() { return rootDir; } - /** @return the default work directory, where the open file starts. */ + /** + * Get the default work directory, where the open file starts. + * + * @return the default work directory, where the open file starts. + */ public static String getWorkDir() { String workPath = workDir; @@ -1631,41 +1836,53 @@ public static String getWorkDir() return workPath; } - /** @return the default plugin directory. */ - public static String getPluginDir() - { - String pluginPath = pluginDir; - log.trace("getPluginDir: pluginDir={}", pluginDir); - if (pluginPath == null) { - pluginPath = System.getProperty("hdfview.plugindir"); - log.trace("getPluginDir: hdfview.plugindir={}", pluginPath); - if (pluginPath == null) { - pluginPath = System.getProperty("user.dir") + "/plugin"; - } - } - log.trace("getPluginDir: final pluginPath={}", pluginPath); - return pluginPath; - } - - /** @return the maximum number of the most recent file */ + /** + * Get the maximum number of the most recent file + * + * @return the maximum number of the most recent file + */ public static int getMaxRecentFiles() { return MAX_RECENT_FILES; } - /** @return the path of the HDFView users guide */ + /** + * Get the path of the HDFView users guide + * + * @return the path of the HDFView users guide + */ public static String getUsersGuide() { return usersGuide; }; - /** @return the delimiter of data values */ + /** + * Get the delimiter of data values + * + * @return the delimiter of data values + */ public static String getDataDelimiter() { return delimiter; } - /** @return the image origin */ + /** + * Get the image origin + * + * @return the image origin + */ public static String getImageOrigin() { return origin; } - /** @return the default index type for display */ + /** + * Get the default index type for display + * + * @return the default index type for display + */ public static String getIndexType() { return indexType; } - /** @return the default index order for display */ + /** + * Get the default index order for display + * + * @return the default index order for display + */ public static String getIndexOrder() { return indexOrder; } - /** @return the timer refresh size */ + /** + * Get the timer refresh size + * + * @return the timer refresh size + */ public static int getTimerRefresh() { return timerRefresh; } /** @@ -1676,13 +1893,25 @@ public static String getPluginDir() */ public static void setTimerRefresh(int trefresh) { timerRefresh = trefresh; } - /** @return the font size */ + /** + * Get the font size + * + * @return the font size + */ public static int getFontSize() { return fontSize; } - /** @return the font type */ + /** + * Get the font type + * + * @return the font type + */ public static String getFontType() { return fontType; } - /** @return the file extensions of supported file formats */ + /** + * Get the file extensions of supported file formats + * + * @return the file extensions of supported file formats + */ public static String getFileExtension() { return fileExt; } /** @@ -1713,37 +1942,81 @@ public static void setFontType(String ftype) } } - /** @return the path of the H5toH5 converter */ + /** + * Get the path of the H5toH5 converter + * + * @return the path of the H5toH5 converter + */ public static String getH4toH5() { return h4toh5; } - /** @return the list of most recent files */ + /** + * Get the list of most recent files + * + * @return the list of most recent files + */ public static List getMRF() { return recentFiles; } - /** @return the list of palette files */ + /** + * Get the list of palette files + * + * @return the list of palette files + */ public static List getPaletteList() { return paletteList; } - /** @return the plugin path list */ - public static List getPluginPaths() { return pluginPathList; } + /** + * Get the plugin path list + * + * @return the plugin path list + */ + public static String[] getPluginPaths() { return pluginPathList.toArray(new String[0]); } - /** @return the SRB account list */ + /** + * Get the SRB account list + * + * @return the SRB account list + */ public static List getSrbAccount() { return srbAccountList; } - /** @return a list of treeview modules */ + /** + * Get a list of treeview modules + * + * @return a list of treeview modules + */ public static List getTreeViewList() { return moduleListTreeView; } - /** @return a list of metadataview modules */ + /** + * Get a list of metadataview modules + * + * @return a list of metadataview modules + */ public static List getMetaDataViewList() { return moduleListMetaDataView; } - /** @return a list of tableview modules */ + /** + * Get a list of tableview modules + * + * @return a list of tableview modules + */ public static List getTableViewList() { return moduleListTableView; } - /** @return a list of imageview modules */ + /** + * Get a list of imageview modules + * + * @return a list of imageview modules + */ public static List getImageViewList() { return moduleListImageView; } - /** @return a list of paletteview modules */ + /** + * Get a list of paletteview modules + * + * @return a list of paletteview modules + */ public static List getPaletteViewList() { return moduleListPaletteView; } - /** @return a list of helpview modules */ + /** + * Get a list of helpview modules + * + * @return a list of helpview modules + */ public static List getHelpViewList() { return moduleListHelpView; } /** @@ -1793,22 +2066,81 @@ public static void setWorkDir(String wDir) } /** - * set the path of the default plugin directory + * Load the paths of the default plugin directories * - * @param plDir the default plugin directory + * @return the array of paths */ - public static void setPluginDir(String plDir) + public static String[] loadPluginPaths() { - log.trace("ViewProperties:setPluginDir plDir={}", plDir); - pluginDir = plDir; + try { + log.trace("ViewProperties:loadPluginPaths"); + pluginPathList = H5Plugins.getPluginPaths(); + } + catch (Exception err) { + } + return getPluginPaths(); } /** - * Sets the list of plugin paths. + * Inserts the plugin path. * - * @param pluginPathsList The list of plugin paths. + * @param pluginPath The plugin path. + * @param pathIndex The index to insert the plugin path. */ - public static void setPluginPaths(ArrayList pluginPathsList) { pluginPaths = pluginPathsList; } + public static void insertPluginPath(String pluginPath, int pathIndex) + { + try { + H5Plugins.insertPluginPath(pluginPath, pathIndex); + pluginPathList = H5Plugins.getPluginPaths(); + } + catch (Exception err) { + } + } + + /** + * Prepends the plugin path. + * + * @param pluginPath The plugin path. + */ + public static void prependPluginPath(String pluginPath) + { + try { + H5Plugins.prependPluginPath(pluginPath); + pluginPathList = H5Plugins.getPluginPaths(); + } + catch (Exception err) { + } + } + + /** + * Appends the plugin path. + * + * @param pluginPath The plugin path. + */ + public static void appendPluginPath(String pluginPath) + { + try { + H5Plugins.appendPluginPath(pluginPath); + pluginPathList = H5Plugins.getPluginPaths(); + } + catch (Exception err) { + } + } + + /** + * Removes the plugin path. + * + * @param pathIndex The index to remove the plugin path. + */ + public static void deletePluginPath(int pathIndex) + { + try { + H5Plugins.deletePluginPath(pathIndex); + pluginPathList = H5Plugins.getPluginPaths(); + } + catch (Exception err) { + } + } /** * set the file extension @@ -1996,7 +2328,9 @@ public static int getMaxMembers() public static void setLateLib(String vers) { LateLib = vers; } /** - * @return the convertEnum + * Check if the enum value is to be converted + * + * @return true if the enum value is to be converted */ public static boolean isConvertEnum() { return convertEnum; } @@ -2008,13 +2342,16 @@ public static int getMaxMembers() public static boolean showRegRefValues() { return showRegRefValues; } /** - * @return the isIndexBase1 + * Check if the data index starts at 1 + * + * @return true if the data index starts at 1 */ public static boolean isIndexBase1() { return isIndexBase1; } /** - * @param convertEnum - * the convertEnum to set + * Set enum data to be converted + * + * @param convertEnum true to set enum data conversion */ public static void setConvertEnum(boolean convertEnum) { ViewProperties.convertEnum = convertEnum; } diff --git a/src/org.hdfgroup.hdfview/hdf/view/dialog/UserOptionsGeneralPage.java b/src/org.hdfgroup.hdfview/hdf/view/dialog/UserOptionsGeneralPage.java index 1ecb68c5..97010020 100644 --- a/src/org.hdfgroup.hdfview/hdf/view/dialog/UserOptionsGeneralPage.java +++ b/src/org.hdfgroup.hdfview/hdf/view/dialog/UserOptionsGeneralPage.java @@ -356,7 +356,7 @@ protected Control createContents(Composite parent) org.eclipse.swt.widgets.Group workingDirectoryGroup = new org.eclipse.swt.widgets.Group(composite, SWT.NONE); - workingDirectoryGroup.setLayout(new GridLayout(3, false)); + workingDirectoryGroup.setLayout(new GridLayout(4, false)); workingDirectoryGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); workingDirectoryGroup.setFont(curFont); workingDirectoryGroup.setText("Default Working Directory"); @@ -364,7 +364,7 @@ protected Control createContents(Composite parent) checkCurrentUserDir = new Button(workingDirectoryGroup, SWT.CHECK); checkCurrentUserDir.setFont(curFont); checkCurrentUserDir.setText("\"User Work\" or"); - checkCurrentUserDir.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + checkCurrentUserDir.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 2, 1)); checkCurrentUserDir.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) @@ -380,7 +380,7 @@ public void widgetSelected(SelectionEvent e) checkUserHomeDir = new Button(workingDirectoryGroup, SWT.CHECK); checkUserHomeDir.setFont(curFont); checkUserHomeDir.setText("\"User Home\" or"); - checkUserHomeDir.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + checkUserHomeDir.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 2, 1)); checkUserHomeDir.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) @@ -395,12 +395,12 @@ public void widgetSelected(SelectionEvent e) workField = new Text(workingDirectoryGroup, SWT.SINGLE | SWT.BORDER); workField.setFont(curFont); - workField.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + workField.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 3, 1)); currentDirButton = new Button(workingDirectoryGroup, SWT.PUSH); currentDirButton.setFont(curFont); currentDirButton.setText("Browse..."); - currentDirButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + currentDirButton.setLayoutData(new GridData(SWT.END, SWT.FILL, false, false)); currentDirButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) @@ -466,23 +466,23 @@ public void widgetSelected(SelectionEvent e) org.eclipse.swt.widgets.Group fileAccessModeGroup = new org.eclipse.swt.widgets.Group(composite, SWT.NONE); fileAccessModeGroup.setLayout(new GridLayout(2, true)); - fileAccessModeGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + fileAccessModeGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); fileAccessModeGroup.setFont(curFont); fileAccessModeGroup.setText("Default File Access Mode"); checkReadOnly = new Button(fileAccessModeGroup, SWT.RADIO); checkReadOnly.setFont(curFont); checkReadOnly.setText("Read Only"); - checkReadOnly.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, false, false)); + checkReadOnly.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); rwButton = new Button(fileAccessModeGroup, SWT.RADIO); rwButton.setFont(curFont); rwButton.setText("Read/Write"); - rwButton.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, false, false)); + rwButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); org.eclipse.swt.widgets.Group textFontGroup = new org.eclipse.swt.widgets.Group(composite, SWT.NONE); textFontGroup.setLayout(new GridLayout(4, false)); - textFontGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + textFontGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); textFontGroup.setFont(curFont); textFontGroup.setText("Text Font"); @@ -495,7 +495,7 @@ public void widgetSelected(SelectionEvent e) fontSizeChoice = new Combo(textFontGroup, SWT.SINGLE | SWT.READ_ONLY); fontSizeChoice.setFont(curFont); fontSizeChoice.setItems(fontSizeChoices); - fontSizeChoice.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + fontSizeChoice.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); label = new Label(textFontGroup, SWT.RIGHT); label.setFont(curFont); @@ -506,15 +506,16 @@ public void widgetSelected(SelectionEvent e) fontTypeChoice = new Combo(textFontGroup, SWT.SINGLE | SWT.READ_ONLY); fontTypeChoice.setFont(curFont); fontTypeChoice.setItems(fontNames); - fontTypeChoice.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + fontTypeChoice.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); org.eclipse.swt.widgets.Group imageGroup = new org.eclipse.swt.widgets.Group(composite, SWT.NONE); - imageGroup.setLayout(new GridLayout(5, false)); - imageGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + imageGroup.setLayout(new GridLayout(6, false)); + imageGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); imageGroup.setFont(curFont); imageGroup.setText("Image"); helpButton = new Button(imageGroup, SWT.PUSH); + helpButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); helpButton.setImage(ViewProperties.getHelpIcon()); helpButton.setToolTipText("Help on Auto Contrast"); helpButton.addSelectionListener(new SelectionAdapter() { @@ -556,12 +557,14 @@ public void widgetSelected(SelectionEvent e) checkAutoContrast = new Button(imageGroup, SWT.CHECK); checkAutoContrast.setFont(curFont); checkAutoContrast.setText("Autogain Image Contrast"); - checkAutoContrast.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + checkAutoContrast.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); checkShowValues = new Button(imageGroup, SWT.CHECK); checkShowValues.setFont(curFont); checkShowValues.setText("Show Values"); - checkShowValues.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + checkShowValues.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + + label = new Label(imageGroup, SWT.NONE); label = new Label(imageGroup, SWT.RIGHT); label.setFont(curFont); @@ -569,11 +572,11 @@ public void widgetSelected(SelectionEvent e) imageOriginChoice = new Combo(imageGroup, SWT.SINGLE | SWT.READ_ONLY); imageOriginChoice.setFont(curFont); - imageOriginChoice.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + imageOriginChoice.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); org.eclipse.swt.widgets.Group dataGroup = new org.eclipse.swt.widgets.Group(composite, SWT.NONE); dataGroup.setLayout(new GridLayout(4, false)); - dataGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + dataGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); dataGroup.setFont(curFont); dataGroup.setText("Data"); @@ -606,7 +609,7 @@ public void widgetSelected(SelectionEvent e) org.eclipse.swt.widgets.Group objectsGroup = new org.eclipse.swt.widgets.Group(composite, SWT.NONE); objectsGroup.setLayout(new GridLayout(5, true)); - objectsGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + objectsGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); objectsGroup.setFont(curFont); objectsGroup.setText("Objects to Open"); diff --git a/src/org.hdfgroup.hdfview/hdf/view/dialog/UserOptionsHDFPage.java b/src/org.hdfgroup.hdfview/hdf/view/dialog/UserOptionsHDFPage.java index 43b6921f..cae29b7d 100644 --- a/src/org.hdfgroup.hdfview/hdf/view/dialog/UserOptionsHDFPage.java +++ b/src/org.hdfgroup.hdfview/hdf/view/dialog/UserOptionsHDFPage.java @@ -24,6 +24,8 @@ import org.slf4j.LoggerFactory; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Font; @@ -46,7 +48,9 @@ public class UserOptionsHDFPage extends UserOptionsDefaultPage { private static final Logger log = LoggerFactory.getLogger(UserOptionsHDFPage.class); - private Text fileExtField, pluginField; + private Text fileExtField; + private Combo pluginCombo; + private Button clearTextButton, deleteTextButton, insertTextButton; private Button checkConvertEnum, checkShowRegRefValues, helpButton; private Button checkNativeOrder, checkDecOrder, checkIncOrder; private Button checkIndexName, checkIndexCreateOrder; @@ -54,8 +58,7 @@ public class UserOptionsHDFPage extends UserOptionsDefaultPage { early114LibVersion, earlyLateLibVersion; private Button lateLibVersion, late18LibVersion, late110LibVersion, late112LibVersion, late114LibVersion, lateLateLibVersion; - private Button checkCurrentUserDir, checkUserHomeDir; - private Button currentDirButton, userHomeButton; + private Button pluginDirButton; /** Default early libversion for files */ private static String earlyLibVers; @@ -70,8 +73,12 @@ public class UserOptionsHDFPage extends UserOptionsDefaultPage { private static String indexOrder; /** Path to plugins */ - private String pluginDir; - private boolean isPluginDirChanged; + private String pluginDir = null; + private int pluginDirIndex = -1; + private boolean isPluginListChanged = false; + + /** a list of plugin paths */ + private static String[] pluginPathList; /** * Configuration page for HDF-specific application settings. @@ -79,7 +86,7 @@ public class UserOptionsHDFPage extends UserOptionsDefaultPage { public UserOptionsHDFPage() { super("HDF Settings"); - isPluginDirChanged = false; + isPluginListChanged = false; } /** @@ -170,20 +177,6 @@ else if (checkNativeOrder.getSelection()) if (checkShowRegRefValues != null) ViewProperties.setShowRegRefValue(checkShowRegRefValues.getSelection()); - if (pluginField != null) { - String pluginPath = pluginField.getText(); - if (checkCurrentUserDir.getSelection()) - pluginPath = System.getProperty("user.dir"); - else if (checkUserHomeDir.getSelection()) - pluginPath = System.getProperty("user.home"); - - if ((pluginPath != null) && (pluginPath.length() > 0)) { - pluginPath = pluginPath.trim(); - isPluginDirChanged = !pluginPath.equals(ViewProperties.getPluginDir()); - ViewProperties.setPluginDir(pluginPath); - } - } - return true; } @@ -192,7 +185,7 @@ else if (checkUserHomeDir.getSelection()) * * @return true if the plugin directory changed. */ - public boolean isPluginDirChanged() { return isPluginDirChanged; } + public boolean isPluginListChanged() { return isPluginListChanged; } /** * Loads all stored values in the FieldEditors. @@ -201,6 +194,14 @@ protected void load() { getPreferenceStore(); + try { + curFont = new Font(Display.getCurrent(), ViewProperties.getFontType(), + ViewProperties.getFontSize(), SWT.NORMAL); + } + catch (Exception ex) { + curFont = null; + } + fileExtField.setText(ViewProperties.getFileExtension()); earlyLibVers = ViewProperties.getEarlyLib(); @@ -233,29 +234,13 @@ protected void load() checkDecOrder.setSelection(indexOrder.compareTo("H5_ITER_DEC") == 0); checkNativeOrder.setSelection(indexOrder.compareTo("H5_ITER_NATIVE") == 0); - pluginDir = ViewProperties.getPluginDir(); - if (pluginDir == null) - pluginDir = rootDir; - - pluginField.setText(pluginDir); - - if (pluginDir.equals(System.getProperty("user.dir"))) { - checkCurrentUserDir.setSelection(true); - checkUserHomeDir.setSelection(false); - pluginField.setEnabled(false); - } - else if (pluginDir.equals(System.getProperty("user.home"))) { - checkCurrentUserDir.setSelection(false); - checkUserHomeDir.setSelection(true); - pluginField.setEnabled(false); - } - else { - checkCurrentUserDir.setSelection(false); - checkUserHomeDir.setSelection(false); - pluginField.setEnabled(true); - } - - log.trace("UserOptionsHDFlPage: pluginDir={}", pluginDir); + pluginPathList = ViewProperties.loadPluginPaths(); + pluginCombo.setItems(pluginPathList); + pluginCombo.setVisibleItemCount(pluginPathList.length); + pluginCombo.setText(""); + pluginCombo.deselectAll(); + pluginDirIndex = -1; + pluginDir = null; } /** @@ -270,11 +255,11 @@ protected Control createContents(Composite parent) { shell = parent.getShell(); Composite composite = new Composite(parent, SWT.NONE); - composite.setLayout(new GridLayout(1, false)); + composite.setLayout(new GridLayout()); org.eclipse.swt.widgets.Group fileExtensionGroup = new org.eclipse.swt.widgets.Group(composite, SWT.NONE); - fileExtensionGroup.setLayout(new GridLayout(2, true)); + fileExtensionGroup.setLayout(new GridLayout(2, false)); fileExtensionGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); fileExtensionGroup.setFont(curFont); fileExtensionGroup.setText("File Extensions"); @@ -284,13 +269,13 @@ protected Control createContents(Composite parent) label.setText("Extensions: "); fileExtField = new Text(fileExtensionGroup, SWT.SINGLE | SWT.BORDER); - fileExtField.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + fileExtField.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); fileExtField.setFont(curFont); org.eclipse.swt.widgets.Group defaultLibVersionGroup = new org.eclipse.swt.widgets.Group(composite, SWT.NONE); defaultLibVersionGroup.setLayout(new GridLayout()); - defaultLibVersionGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + defaultLibVersionGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); defaultLibVersionGroup.setFont(curFont); defaultLibVersionGroup.setText("Default Lib Version"); @@ -304,32 +289,32 @@ protected Control createContents(Composite parent) earlyLibVersion = new Button(earlyLibVersionGroup, SWT.RADIO); earlyLibVersion.setFont(curFont); earlyLibVersion.setText("Earliest"); - earlyLibVersion.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false)); + earlyLibVersion.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); early18LibVersion = new Button(earlyLibVersionGroup, SWT.RADIO); early18LibVersion.setFont(curFont); early18LibVersion.setText("v18"); - early18LibVersion.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false)); + early18LibVersion.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); early110LibVersion = new Button(earlyLibVersionGroup, SWT.RADIO); early110LibVersion.setFont(curFont); early110LibVersion.setText("v110"); - early110LibVersion.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false)); + early110LibVersion.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); early112LibVersion = new Button(earlyLibVersionGroup, SWT.RADIO); early112LibVersion.setFont(curFont); early112LibVersion.setText("v112"); - early112LibVersion.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false)); + early112LibVersion.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); early114LibVersion = new Button(earlyLibVersionGroup, SWT.RADIO); early114LibVersion.setFont(curFont); early114LibVersion.setText("v114"); - early114LibVersion.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false)); + early114LibVersion.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); earlyLateLibVersion = new Button(earlyLibVersionGroup, SWT.RADIO); earlyLateLibVersion.setFont(curFont); earlyLateLibVersion.setText("Latest"); - earlyLateLibVersion.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false)); + earlyLateLibVersion.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); org.eclipse.swt.widgets.Group lateLibVersionGroup = new org.eclipse.swt.widgets.Group(defaultLibVersionGroup, SWT.NONE); @@ -341,36 +326,36 @@ protected Control createContents(Composite parent) lateLibVersion = new Button(lateLibVersionGroup, SWT.RADIO); lateLibVersion.setFont(curFont); lateLibVersion.setText("Earliest"); - lateLibVersion.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false)); + lateLibVersion.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); late18LibVersion = new Button(lateLibVersionGroup, SWT.RADIO); late18LibVersion.setFont(curFont); late18LibVersion.setText("v18"); - late18LibVersion.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false)); + late18LibVersion.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); late110LibVersion = new Button(lateLibVersionGroup, SWT.RADIO); late110LibVersion.setFont(curFont); late110LibVersion.setText("v110"); - late110LibVersion.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false)); + late110LibVersion.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); late112LibVersion = new Button(lateLibVersionGroup, SWT.RADIO); late112LibVersion.setFont(curFont); late112LibVersion.setText("v112"); - late112LibVersion.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false)); + late112LibVersion.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); late114LibVersion = new Button(lateLibVersionGroup, SWT.RADIO); late114LibVersion.setFont(curFont); late114LibVersion.setText("v114"); - late114LibVersion.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false)); + late114LibVersion.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); lateLateLibVersion = new Button(lateLibVersionGroup, SWT.RADIO); lateLateLibVersion.setFont(curFont); lateLateLibVersion.setText("Latest"); - lateLateLibVersion.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false)); + lateLateLibVersion.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); org.eclipse.swt.widgets.Group dataGroup = new org.eclipse.swt.widgets.Group(composite, SWT.NONE); dataGroup.setLayout(new GridLayout(4, false)); - dataGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + dataGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); dataGroup.setFont(curFont); dataGroup.setText("Data"); @@ -394,17 +379,17 @@ public void widgetSelected(SelectionEvent e) checkConvertEnum = new Button(dataGroup, SWT.CHECK); checkConvertEnum.setFont(curFont); checkConvertEnum.setText("Convert Enum"); - checkConvertEnum.setLayoutData(new GridData(SWT.BEGINNING, SWT.FILL, false, false)); + checkConvertEnum.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); checkShowRegRefValues = new Button(dataGroup, SWT.CHECK); checkShowRegRefValues.setFont(curFont); checkShowRegRefValues.setText("Show RegRef Values"); - checkShowRegRefValues.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + checkShowRegRefValues.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); org.eclipse.swt.widgets.Group displayIndexingGroup = new org.eclipse.swt.widgets.Group(composite, SWT.NONE); displayIndexingGroup.setLayout(new GridLayout()); - displayIndexingGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + displayIndexingGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); displayIndexingGroup.setFont(curFont); displayIndexingGroup.setText("Display Indexing Options"); @@ -418,99 +403,165 @@ public void widgetSelected(SelectionEvent e) checkIndexName = new Button(indexingTypeGroup, SWT.RADIO); checkIndexName.setFont(curFont); checkIndexName.setText("By Name"); - checkIndexName.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false)); + checkIndexName.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); checkIndexCreateOrder = new Button(indexingTypeGroup, SWT.RADIO); checkIndexCreateOrder.setFont(curFont); checkIndexCreateOrder.setText("By Creation Order"); - checkIndexCreateOrder.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false)); + checkIndexCreateOrder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); org.eclipse.swt.widgets.Group indexingOrderGroup = new org.eclipse.swt.widgets.Group(displayIndexingGroup, SWT.NONE); indexingOrderGroup.setLayout(new GridLayout(3, true)); - indexingOrderGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + indexingOrderGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); indexingOrderGroup.setFont(curFont); indexingOrderGroup.setText("Indexing Order"); checkIncOrder = new Button(indexingOrderGroup, SWT.RADIO); checkIncOrder.setFont(curFont); checkIncOrder.setText("Increments"); - checkIncOrder.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false)); + checkIncOrder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); checkDecOrder = new Button(indexingOrderGroup, SWT.RADIO); checkDecOrder.setFont(curFont); checkDecOrder.setText("Decrements"); - checkDecOrder.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false)); + checkDecOrder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); checkNativeOrder = new Button(indexingOrderGroup, SWT.RADIO); checkNativeOrder.setFont(curFont); checkNativeOrder.setText("Native"); - checkNativeOrder.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false)); + checkNativeOrder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); org.eclipse.swt.widgets.Group pluginDirectoryGroup = new org.eclipse.swt.widgets.Group(composite, SWT.NONE); pluginDirectoryGroup.setLayout(new GridLayout(3, false)); pluginDirectoryGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); pluginDirectoryGroup.setFont(curFont); - pluginDirectoryGroup.setText("Default Plugin Directory (*/plugin)"); - - checkCurrentUserDir = new Button(pluginDirectoryGroup, SWT.CHECK); - checkCurrentUserDir.setFont(curFont); - checkCurrentUserDir.setText("\"User Work\" or"); - checkCurrentUserDir.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); - checkCurrentUserDir.addSelectionListener(new SelectionAdapter() { + pluginDirectoryGroup.setText("Plugin Paths"); + + pluginPathList = ViewProperties.loadPluginPaths(); + pluginCombo = new Combo(pluginDirectoryGroup, SWT.BORDER | SWT.SINGLE); + pluginCombo.setFont(curFont); + pluginCombo.setItems(pluginPathList); + pluginCombo.setVisibleItemCount(pluginPathList.length); + pluginCombo.deselectAll(); + pluginCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); + pluginCombo.addKeyListener(new KeyAdapter() { @Override - public void widgetSelected(SelectionEvent e) + public void keyPressed(KeyEvent e) { - boolean isCheckCurrentUserDirSelected = checkCurrentUserDir.getSelection(); - if (isCheckCurrentUserDirSelected) - checkUserHomeDir.setSelection(false); - pluginField.setEnabled(!isCheckCurrentUserDirSelected); - currentDirButton.setEnabled(!isCheckCurrentUserDirSelected); + if (e.keyCode == SWT.CR) { + String dirname = pluginCombo.getText(); + if (dirname == null || dirname.length() < 1 || dirname.equals(pluginDir)) + return; + pluginCombo.setText(dirname); + } } }); - - checkUserHomeDir = new Button(pluginDirectoryGroup, SWT.CHECK); - checkUserHomeDir.setFont(curFont); - checkUserHomeDir.setText("\"User Home\" or"); - checkUserHomeDir.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); - checkUserHomeDir.addSelectionListener(new SelectionAdapter() { + pluginCombo.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - boolean isCheckUserHomeDirSelected = checkUserHomeDir.getSelection(); - if (isCheckUserHomeDirSelected) - checkCurrentUserDir.setSelection(false); - pluginField.setEnabled(!isCheckUserHomeDirSelected); - currentDirButton.setEnabled(!isCheckUserHomeDirSelected); + pluginDirIndex = pluginCombo.getSelectionIndex(); + pluginDir = pluginCombo.getItem(pluginDirIndex); } }); - pluginField = new Text(pluginDirectoryGroup, SWT.SINGLE | SWT.BORDER); - pluginField.setFont(curFont); - pluginField.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); - - currentDirButton = new Button(pluginDirectoryGroup, SWT.PUSH); - currentDirButton.setFont(curFont); - currentDirButton.setText("Browse..."); - currentDirButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); - currentDirButton.addSelectionListener(new SelectionAdapter() { + pluginDirButton = new Button(pluginDirectoryGroup, SWT.PUSH); + pluginDirButton.setFont(curFont); + pluginDirButton.setText("Browse..."); + pluginDirButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.FILL, false, false)); + pluginDirButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { final DirectoryDialog dChooser = new DirectoryDialog(shell); - dChooser.setFilterPath(pluginDir); - dChooser.setText("Select a Base Directory"); + dChooser.setFilterPath(System.getProperty("user.dir")); + dChooser.setText("Select a Directory"); String dir = dChooser.open(); if (dir == null) return; - pluginField.setText(dir + "/plugin"); + pluginCombo.setText(dir); } }); + insertTextButton = new Button(pluginDirectoryGroup, SWT.PUSH); + insertTextButton.setFont(curFont); + insertTextButton.setToolTipText("Append current selection"); + insertTextButton.setText("Add Path"); + insertTextButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + insertTextButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) + { + String dirname = pluginCombo.getText(); + if (dirname == null || dirname.length() < 1) { + return; + } + ViewProperties.appendPluginPath(dirname); + pluginPathList = ViewProperties.loadPluginPaths(); + pluginCombo.setItems(pluginPathList); + pluginCombo.setVisibleItemCount(pluginPathList.length); + pluginCombo.setText(""); + pluginCombo.deselectAll(); + pluginDirIndex = -1; + pluginDir = null; + } + }); + + deleteTextButton = new Button(pluginDirectoryGroup, SWT.PUSH); + deleteTextButton.setFont(curFont); + deleteTextButton.setToolTipText("Remove current selection"); + deleteTextButton.setText("Remove Path"); + deleteTextButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + deleteTextButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) + { + String dirname = pluginCombo.getText(); + if (dirname == null || dirname.length() < 1) { + return; + } + String[] items = pluginCombo.getItems(); + for (int idx = 0; idx < items.length; idx++) { + if (items[idx].equals(dirname)) { + pluginDirIndex = idx; + } + } + ViewProperties.deletePluginPath(pluginDirIndex); + pluginPathList = ViewProperties.loadPluginPaths(); + pluginCombo.setItems(pluginPathList); + pluginCombo.setVisibleItemCount(pluginPathList.length); + pluginCombo.setText(""); + pluginCombo.deselectAll(); + pluginDirIndex = -1; + pluginDir = null; + } + }); + + clearTextButton = new Button(pluginDirectoryGroup, SWT.PUSH); + clearTextButton.setFont(curFont); + clearTextButton.setToolTipText("Clear current selection"); + clearTextButton.setText("Clear Path Text"); + clearTextButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + clearTextButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) + { + pluginCombo.setText(""); + pluginCombo.deselectAll(); + pluginDirIndex = -1; + pluginDir = null; + } + }); + + // shell.pack(); + + log.info("UserOptionsHDFPage: plugin combobox created"); + load(); return composite; } diff --git a/src/org.hdfgroup.object/hdf/object/h5/H5Plugins.java b/src/org.hdfgroup.object/hdf/object/h5/H5Plugins.java index 4ecf1bfa..0b74ee93 100644 --- a/src/org.hdfgroup.object/hdf/object/h5/H5Plugins.java +++ b/src/org.hdfgroup.object/hdf/object/h5/H5Plugins.java @@ -14,6 +14,9 @@ package hdf.object.h5; +import java.util.ArrayList; +import java.util.List; + import hdf.hdf5lib.H5; import hdf.hdf5lib.HDF5Constants; import hdf.hdf5lib.exceptions.HDF5Exception; @@ -52,4 +55,68 @@ public static final long getTotalPluginPaths() throws HDF5Exception return totalPaths; } + + /** + * Get the list of paths for the HDF5 library. + * + * @return list of plugin paths + * + * @throws HDF5Exception If there is an error at the HDF5 library level. + */ + public static final ArrayList getPluginPaths() throws HDF5Exception + { + ArrayList pathList = new ArrayList<>(5); + totalPaths = H5.H5PLsize(); + log.trace("getPluginPaths(): total plugin paths {}", totalPaths); + for (int indx = 0; indx < totalPaths; indx++) + pathList.add(H5.H5PLget(indx)); + + return pathList; + } + + /** + * Replaces the plugin path. + * + * @param pluginPath The plugin path. + * @param pathIndex The index to replace the plugin path. + */ + public static void replacePluginPath(String pluginPath, int pathIndex) throws HDF5Exception + { + H5.H5PLreplace(pluginPath, pathIndex); + } + + /** + * Inserts the plugin path. + * + * @param pluginPath The plugin path. + * @param pathIndex The index to insert the plugin path. + */ + public static void insertPluginPath(String pluginPath, int pathIndex) throws HDF5Exception + { + H5.H5PLinsert(pluginPath, pathIndex); + } + + /** + * Removes the plugin path. + * + * @param pathIndex The index to remove the plugin path. + */ + public static void deletePluginPath(int pathIndex) throws HDF5Exception { H5.H5PLremove(pathIndex); } + + /** + * Prepend the plugin path. + * + * @param pluginPath The plugin path. + */ + public static void prependPluginPath(String pluginPath) throws HDF5Exception + { + H5.H5PLprepend(pluginPath); + } + + /** + * Append the plugin path. + * + * @param pluginPath The plugin path. + */ + public static void appendPluginPath(String pluginPath) throws HDF5Exception { H5.H5PLappend(pluginPath); } }