public void select() { final String directory = _preferencesStore.get(_preferencesString, Utilities.getWorkingDirectory()); final Shell shell = new Shell(Display.getDefault()); DirectoryDialog dialog = new DirectoryDialog(shell, SWT.MULTI); dialog.setFilterPath(directory); dialog.setText("Save JavaSeis Volume(s)"); String rtn = dialog.open(); if (rtn != null) { _preferencesStore.put(_preferencesString, rtn); PreferencesUtil.saveInstanceScopePreferences(ServiceComponent.PLUGIN_ID); } }
@Override public void run() { // Get the last-used directory for polygon region models from the preferences. final String directory = _preferencesStore.get(_preferencesString, Utilities.getWorkingDirectory()); // Create the file selection dialog. Shell shell = new Shell(Display.getCurrent()); FileDialog dialog = new FileDialog(shell, SWT.OPEN); dialog.setFilterPath(directory); dialog.setFilterNames( new String[] { "ABAVO Polygon Model (*." + PolygonRegionsModel.FILE_EXTENSION + ")", "Old ABAVO Polygon Model (*." + PolygonRegionsModel.FILE_EXTENSION_OLD + ")" }); dialog.setFilterExtensions( new String[] { "*." + PolygonRegionsModel.FILE_EXTENSION, "*." + PolygonRegionsModel.FILE_EXTENSION_OLD }); dialog.setText("Load Polygon Model"); shell.setLocation(_parent.getLocation()); // Open the file selection dialog and get the result. String result = dialog.open(); if (result != null && result.length() > 0) { File file = new File(result); // Check the file extension. boolean validFile = file.getAbsolutePath().endsWith("." + PolygonRegionsModel.FILE_EXTENSION); boolean validFileOld = file.getAbsolutePath().endsWith("." + PolygonRegionsModel.FILE_EXTENSION_OLD); if (!validFile && !validFileOld) { // Show the user an error message. UserAssistMessageBuilder message = new UserAssistMessageBuilder(); message.setDescription("Unable to read polygon model file."); message.addReason("Invalid file type."); message.addSolution( "Select a valid polygon model file (*." + PolygonRegionsModel.FILE_EXTENSION + ")."); MessageDialog.openError(shell, "File I/O Error", message.toString()); } else { boolean rescalePolygons = MessageDialog.openQuestion( shell, "Rescale Polygons", "Rescale polygons to plot maximum?"); try { // Store the directory location in the preferences. _preferencesStore.put(_preferencesString, file.getParent()); PreferencesUtil.saveInstanceScopePreferences(ServiceComponent.PLUGIN_ID); // Read the model from the file. if (validFile) { _model.readSession(file, rescalePolygons); } else if (validFileOld) { _model.readSessionOld(file, rescalePolygons); } String message = "Polygon regions model loaded:\n\'" + file.getAbsolutePath() + "\'"; MessageDialog.openInformation(shell, "File I/O", message); } catch (Exception ex) { // Show the user an error message. UserAssistMessageBuilder message = new UserAssistMessageBuilder(); message.setDescription("Unable to read polygon model file."); message.addReason(ex.toString()); MessageDialog.openError(shell, "File I/O Error", message.toString()); } } } shell.dispose(); }