List of usage examples for org.eclipse.jface.dialogs Dialog Dialog
protected Dialog(IShellProvider parentShell)
From source file:eu.hydrologis.jgrass.ui.utilities.JGRasterChooserDialog.java
License:Open Source License
public void open(Shell parentShell, final int selectionType) { dialog = new Dialog(parentShell) { @Override/* www. j a va 2s. c o m*/ protected void configureShell(Shell shell) { super.configureShell(shell); shell.setText(Messages.getString("JGRasterChooserDialog.chooseraster")); //$NON-NLS-1$ } @Override protected Point getInitialSize() { return new Point(280, 380); } @Override protected Control createDialogArea(Composite parent) { parentPanel = (Composite) super.createDialogArea(parent); GridLayout gLayout = (GridLayout) parentPanel.getLayout(); gLayout.numColumns = 1; active = new JGRasterLayerTreeViewer(parentPanel, SWT.BORDER, selectionType, mapsetPath); makeCheckPanel(); return parentPanel; } @Override protected void buttonPressed(int buttonId) { String text = null; newLayers = new ArrayList<JGrassMapGeoResource>(); if (buttonId == OK) { List<IGeoResource> layers = (List<IGeoResource>) active.getSelectedLayers(); for (IGeoResource geoResource : layers) { newLayers.add((JGrassMapGeoResource) geoResource); try { text = geoResource.getInfo(null).getTitle(); } catch (IOException e) { UiUtilitiesPlugin.log("UiUtilitiesPlugin problem", e); //$NON-NLS-1$ e.printStackTrace(); } } if (text == null) { return; } } else { newLayers = null; } super.buttonPressed(buttonId); } }; dialog.setBlockOnOpen(true); dialog.open(); }
From source file:eu.hydrologis.jgrass.ui.utils.MapcalcGui.java
License:Open Source License
public MapcalcGui() { m_preferences = (ScopedPreferenceStore) ConsoleEditorPlugin.getDefault().getPreferenceStore(); mapsetPath = m_preferences.getString("string@option@ConsoleMapsetFolder"); if (mapsetPath == null || !(new File(mapsetPath).exists())) { Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell(); MessageBox msgBox = new MessageBox(shell, SWT.ICON_ERROR); msgBox.setMessage("No mapset has been defined or doesn't exist. Please check your preferences"); msgBox.open();/* w w w . j a v a2s . co m*/ return; } // this.mapsArray = new String[]{"map1", "map2"}; String cellPath = mapsetPath + File.separator + JGrassConstants.CELL; File cellFile = new File(cellPath); File[] filesList = cellFile.listFiles(); List<String> mapNames = new ArrayList<String>(); for (File file : filesList) { if (file.isFile()) { mapNames.add(file.getName()); } } mapsArray = (String[]) mapNames.toArray(new String[mapNames.size()]); // gisbase = m_preferences.getString("string@option@@ConsoleGrassenvGisbase"); // if (gisbase == null || !(new File(gisbase).exists())) { // Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell(); // MessageBox msgBox = new MessageBox(shell, SWT.ICON_ERROR); // msgBox // .setMessage("No gisbase has been defined or doesn't exist. Please check your preferences"); // msgBox.open(); // return; // } // list of old mapcalcs to load if wanted String oldMapcalcs = m_preferences.getString(MAPCALCS); oldMapcalcsSplits = oldMapcalcs.split("#"); Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell(); dialog = new Dialog(shell) { protected Control createContents(Composite parent) { return createGui(parent); } protected Point getInitialSize() { return new Point(500, 600); } }; createGui(shell); dialog.setBlockOnOpen(true); dialog.open(); }
From source file:eu.hydrologis.jgrass.uibuilder.jgrassdependent.GuiBuilderDialog.java
License:Open Source License
private void openHelpResult(final String helpString) { Display.getDefault().asyncExec(new Runnable() { public void run() { Dialog helpDialog = new Dialog(getShell()) { protected void configureShell(Shell newShell) { commandName = properties.getProperty(UIBuilderJGrassConstants.DIALOG_TITLE); if (commandName != null) { newShell.setText("Help for: " + commandName); newShell.setSize(600, 400); }//from w ww. j a v a2 s. c o m // set the position of the shell Point cursorLocation = parent.getDisplay().getCursorLocation(); cursorLocation.x = cursorLocation.x - newShell.getSize().x / 2; newShell.setLocation(cursorLocation); super.configureShell(newShell); } protected Control createDialogArea(Composite parent) { Composite composite = (Composite) super.createDialogArea(parent); final Text text = new Text(composite, SWT.READ_ONLY | SWT.WRAP | SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); if (helpString.contains("Total run time")) { String[] split1 = helpString.split("Running model... -------------------------------"); String[] split2 = split1[1].split("Total run time"); text.setText(split2[0].trim()); } else { text.setText(helpString); } return composite; } }; helpDialog.open(); } }); }
From source file:eu.hydrologis.stage.modules.widgets.MultipleModuleDescriptionDialog.java
License:Open Source License
public void open(final Shell parentShell) { dialog = new Dialog(parentShell) { protected void configureShell(Shell shell) { super.configureShell(shell); shell.setText(title);/*from w w w. j ava 2 s.c om*/ shell.setSize(DIALOG_WIDTH, 700); Monitor primary = Display.getDefault().getPrimaryMonitor(); Rectangle bounds = primary.getBounds(); Rectangle rect = shell.getBounds(); int x = bounds.x + (bounds.width - rect.width) / 2; int y = bounds.y + (bounds.height - rect.height) / 2; shell.setLocation(x, y); } protected int getShellStyle() { return SWT.DIALOG_TRIM | SWT.RESIZE; }; // protected Point getInitialSize() { // return new Point(620, 450); // } protected Control createDialogArea(Composite parent) { parentPanel = (Composite) super.createDialogArea(parent); parentPanel.setLayout(new GridLayout(1, false)); parentPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); String[] names = new String[moduleDescriptions.size()]; for (int i = 0; i < names.length; i++) { names[i] = moduleDescriptions.get(i).getName(); } namesCombo = new Combo(parentPanel, SWT.DROP_DOWN | SWT.READ_ONLY); namesCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); namesCombo.setItems(names); if (lastUsedModuleDescription != null) { for (int j = 0; j < moduleDescriptions.size(); j++) { if (moduleDescriptions.get(j).getClassName() .equals(lastUsedModuleDescription.getClassName())) { namesCombo.select(j); } } } else { namesCombo.select(0); } namesCombo.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { setGui(); } }); moduleComposite = new Composite(parentPanel, SWT.NONE); moduleComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); stackLayout = new StackLayout(); moduleComposite.setLayout(stackLayout); setGui(); return parentPanel; } protected void buttonPressed(int buttonId) { if (buttonId == Dialog.CANCEL) { currentModuleDescription = null; } // modification of whatever should be done in any gui super.buttonPressed(buttonId); } }; dialog.setBlockOnOpen(true); dialog.open(); }
From source file:eu.udig.catalog.jgrass.activeregion.dialogs.CatalogJGrassMapsetTreeViewerDialog.java
License:Open Source License
public void open(Shell parentShell) { try {/*from www. ja v a 2s . co m*/ setRequireContinue(false); Dialog dialog = new Dialog(parentShell) { @Override protected void configureShell(Shell shell) { super.configureShell(shell); shell.setText("Select mapset"); //$NON-NLS-1$ } @Override protected Point getInitialSize() { return new Point(250, 250); } @Override protected Control createDialogArea(Composite parent) { Composite parentPanel = (Composite) super.createDialogArea(parent); GridLayout gLayout = (GridLayout) parentPanel.getLayout(); gLayout.numColumns = 1; active = new CatalogJGrassMapsetsTreeViewer(parentPanel, SWT.BORDER, SWT.SINGLE); return parentPanel; } @Override protected void buttonPressed(int buttonId) { super.buttonPressed(buttonId); if (buttonId == OK) { newLayers = active.getSelectedLayers(); } else { newLayers = null; } setRequireContinue(true); } }; dialog.setBlockOnOpen(true); dialog.open(); while (!isContinueRequired()) { if (dialog.getShell().isDisposed()) { break; } if (Display.getCurrent().readAndDispatch()) { continue; } try { Thread.sleep(300); } catch (InterruptedException ex) { ex.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:eu.udig.catalog.jgrass.activeregion.dialogs.FeatureChooserDialog.java
License:Open Source License
public void open(Shell parentShell, final int selectionType) { Dialog dialog = new Dialog(parentShell) { @Override/*from w w w .ja v a 2s .co m*/ protected void configureShell(Shell shell) { super.configureShell(shell); shell.setText("Select vector map"); //$NON-NLS-1$ } @Override protected Point getInitialSize() { return new Point(280, 380); } @Override protected Control createDialogArea(Composite parent) { parentPanel = (Composite) super.createDialogArea(parent); GridLayout gLayout = (GridLayout) parentPanel.getLayout(); gLayout.numColumns = 1; active = new FeatureLayerTreeViewer(parentPanel, SWT.BORDER, selectionType); makeCheckPanel(); return parentPanel; } @Override protected void buttonPressed(int buttonId) { if (buttonId == OK) { Object tmp = null; try { tmp = ((List) active.getSelectedLayers()).get(0); } catch (Exception e) { e.printStackTrace(); selectedLayers = null; } if (tmp instanceof DataStore) { selectedLayers = (List<DataStore>) active.getSelectedLayers(); } else if (tmp instanceof UDIGSimpleFeatureStore) { List l = (List) active.getSelectedLayers(); List<DataStore> ll = new ArrayList<DataStore>(); for (Object object : l) { UDIGSimpleFeatureStore internal = (UDIGSimpleFeatureStore) object; ll.add(internal.getDataStore()); } selectedLayers = ll; } } else { selectedLayers = null; } super.buttonPressed(buttonId); } }; dialog.setBlockOnOpen(true); dialog.open(); }
From source file:eu.udig.catalog.jgrass.activeregion.dialogs.JGRasterChooserDialog.java
License:Open Source License
public void open(Shell parentShell, final int selectionType) { dialog = new Dialog(parentShell) { @Override//ww w. jav a 2 s . c o m protected void configureShell(Shell shell) { super.configureShell(shell); shell.setText(Messages.getString("JGRasterChooserDialog.chooseraster")); //$NON-NLS-1$ } @Override protected Point getInitialSize() { return new Point(280, 380); } @Override protected Control createDialogArea(Composite parent) { parentPanel = (Composite) super.createDialogArea(parent); GridLayout gLayout = (GridLayout) parentPanel.getLayout(); gLayout.numColumns = 1; active = new JGRasterLayerTreeViewer(parentPanel, SWT.BORDER, selectionType, mapsetPath); makeCheckPanel(); return parentPanel; } @Override protected void buttonPressed(int buttonId) { String text = null; newLayers = new ArrayList<JGrassMapGeoResource>(); if (buttonId == OK) { List<IGeoResource> layers = (List<IGeoResource>) active.getSelectedLayers(); for (IGeoResource geoResource : layers) { newLayers.add((JGrassMapGeoResource) geoResource); try { text = geoResource.getInfo(null).getTitle(); } catch (IOException e) { e.printStackTrace(); } } if (text == null) { return; } } else { newLayers = null; } super.buttonPressed(buttonId); } }; dialog.setBlockOnOpen(true); dialog.open(); }
From source file:eu.udig.catalog.jgrass.core.ChooseCoordinateReferenceSystemDialog.java
License:Open Source License
public void open(Shell parentShell) { goGo = false;/*w w w.ja v a 2s. co m*/ Dialog dialog = new Dialog(parentShell) { @Override protected void configureShell(Shell shell) { super.configureShell(shell); shell.setText("Choose CRS"); } // @Override // protected Point getInitialSize() { // return new Point(250, 250); // } @Override protected Control createDialogArea(Composite parent) { Composite comp = (Composite) super.createDialogArea(parent); GridLayout gLayout = (GridLayout) comp.getLayout(); gLayout.numColumns = 1; chooser = new CRSChooser(new Controller() { public void handleClose() { buttonPressed(OK); } public void handleOk() { buttonPressed(OK); } }); return chooser.createControl(parent); } @Override protected void buttonPressed(int buttonId) { if (buttonId == OK) { try { crs = chooser.getCRS(); } catch (Exception e) { } } close(); goGo = true; } }; dialog.setBlockOnOpen(true); dialog.open(); while (!goGo) { if (dialog.getShell().isDisposed()) { break; } if (Display.getCurrent().readAndDispatch()) { // dialog.getShell().getDisplay().readAndDispatch()) { continue; } if (goGo) { break; } try { Thread.sleep(300); } catch (InterruptedException ex) { ex.printStackTrace(); } } }
From source file:eu.udig.catalog.jgrass.operations.GrassReprojectAction.java
License:Open Source License
public void run(IAction action) { Display.getDefault().syncExec(new Runnable() { public void run() { shell = PlatformUI.getWorkbench().getDisplay().getActiveShell(); maps.clear();/* ww w. jav a2 s. co m*/ final List<?> toList = selection.toList(); try { for (Object object : toList) { if (object instanceof JGrassMapGeoResource) { JGrassMapGeoResource mr = (JGrassMapGeoResource) object; maps.add(mr); } } Dialog dialog = new Dialog(shell) { private Text locNameText; private Text mapsetNameText; private Text crsText; private Text xresText; private Text yresText; protected Control createDialogArea(Composite maxparent) { Composite parent = new Composite(maxparent, SWT.None); parent.setLayout(new GridLayout()); parent.setLayoutData(new GridData( GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL)); // the location name group Group locNameGroup = new Group(parent, SWT.None); locNameGroup.setLayout(new GridLayout(2, false)); locNameGroup.setLayoutData(new GridData( GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL)); locNameGroup.setText("new location name"); locNameText = new Text(locNameGroup, SWT.BORDER); locNameText .setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_CENTER)); locNameText.setText("newLocation"); // the mapset name group Group mapsetNameGroup = new Group(parent, SWT.None); mapsetNameGroup.setLayout(new GridLayout(2, false)); mapsetNameGroup.setLayoutData(new GridData( GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL)); mapsetNameGroup.setText("new mapset name"); mapsetNameText = new Text(mapsetNameGroup, SWT.BORDER); mapsetNameText .setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_CENTER)); mapsetNameText.setText("newMapset"); // the crs choice group Group crsGroup = new Group(parent, SWT.None); crsGroup.setLayout(new GridLayout(2, false)); crsGroup.setLayoutData(new GridData( GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL)); crsGroup.setText("choose the coordinate reference system for the new location"); crsText = new Text(crsGroup, SWT.BORDER); crsText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_CENTER)); crsText.setEditable(false); final Button crsButton = new Button(crsGroup, SWT.BORDER); crsButton.setText(" Choose CRS "); crsButton.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() { public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { final ChooseCoordinateReferenceSystemDialog crsChooser = new ChooseCoordinateReferenceSystemDialog(); crsChooser.open(new Shell(Display.getDefault())); CoordinateReferenceSystem readCrs = crsChooser.getCrs(); if (readCrs == null) return; crsText.setText(readCrs.getName().toString()); crsText.setData(readCrs); } }); // the location name group Group resolutionGroup = new Group(parent, SWT.None); resolutionGroup.setLayout(new GridLayout(2, false)); resolutionGroup.setLayoutData(new GridData( GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL)); resolutionGroup.setText("output map resolution"); String res = ""; if (maps.size() > 0) { try { JGrassRegion activeWindow = maps.get(0).getActiveWindow(); res = String.valueOf(activeWindow.getNSResolution()); } catch (IOException e1) { e1.printStackTrace(); } } Label xresLabel = new Label(resolutionGroup, SWT.NONE); xresLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); xresLabel.setText("X resolution"); xresText = new Text(resolutionGroup, SWT.BORDER); xresText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_CENTER)); xresText.setText(res); Label yresLabel = new Label(resolutionGroup, SWT.NONE); yresLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); yresLabel.setText("Y resolution"); yresText = new Text(resolutionGroup, SWT.BORDER); yresText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_CENTER)); yresText.setText(res); return parent; } protected void okPressed() { locationName = locNameText.getText(); if (locationName == null || locationName.length() < 1) { locationName = "newLocation"; } mapsetName = mapsetNameText.getText(); if (mapsetName == null || mapsetName.length() < 1) { mapsetName = "newMapset"; } xRes = xresText.getText(); yRes = yresText.getText(); Object crsData = crsText.getData(); if (crsData instanceof CoordinateReferenceSystem) { crs = (CoordinateReferenceSystem) crsData; } super.okPressed(); } }; dialog.setBlockOnOpen(true); open = dialog.open(); } catch (Exception e) { String message = "An error occurred while exporting the maps."; ExceptionDetailsDialog.openError("ERROR", message, IStatus.ERROR, JGrassPlugin.PLUGIN_ID, e); } } }); if (open == SWT.CANCEL) { return; } /* * run with backgroundable progress monitoring */ IRunnableWithProgress operation = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { if (locationName == null || mapsetName == null || crs == null || maps.size() < 1) { MessageBox msgBox = new MessageBox(shell, SWT.ICON_ERROR); msgBox.setMessage("An error occurred in processing the user supplied data."); msgBox.open(); return; } /* * finally do some processing */ int mapNum = maps.size(); monitor.beginTask("Reprojecting maps to new Location...", mapNum); for (int i = 0; i < mapNum; i++) { JGrassMapGeoResource tmpMap = maps.get(i); JGrassMapEnvironment jgMEnv = new JGrassMapEnvironment(tmpMap.getMapFile()); try { /* * TODO get envelope from original region and reproject it. * then adapt it to the output resolution and * finally reproject the map on the new grid. */ JGrassRegion sourceRegion = jgMEnv.getActiveRegion(); CoordinateReferenceSystem sourceCrs = jgMEnv.getCoordinateReferenceSystem(); com.vividsolutions.jts.geom.Envelope sourceEnvelope = sourceRegion.getEnvelope(); MathTransform tr = CRS.findMathTransform(sourceCrs, crs); com.vividsolutions.jts.geom.Envelope outputEnvelope = JTS.transform(sourceEnvelope, tr); double west = outputEnvelope.getMinX(); double east = outputEnvelope.getMaxX(); double south = outputEnvelope.getMinY(); double north = outputEnvelope.getMaxY(); double xResolution = Double.parseDouble(xRes); double yResolution = Double.parseDouble(yRes); Coordinate tmp1 = new Coordinate(west, south); Coordinate tmp2 = new Coordinate(west + xResolution, south + yResolution); JTS.transform(tmp1, tmp1, tr); JTS.transform(tmp2, tmp2, tr); xResolution = tmp2.x - tmp1.x; yResolution = tmp2.y - tmp1.y; // if in metric, snap to integer bounds int intWest = (int) Math.floor(west); int intSouth = (int) Math.floor(south); if (west - intWest < xResolution && south - intSouth < yResolution) { west = intWest; south = intSouth; } double w = east - west; double h = north - south; // modify the envelope to be in the requested resolution double cols = Math.floor(w / xResolution) + 1.0; double rows = Math.floor(h / yResolution) + 1.0; double newEast = west + cols * xResolution; double newNorth = south + rows * yResolution; ReferencedEnvelope referencedEnvelope = new ReferencedEnvelope(west, newEast, south, newNorth, crs); GridToEnvelopeMapper g2eMapper = new GridToEnvelopeMapper(); g2eMapper.setEnvelope(referencedEnvelope); GridEnvelope2D gridEnvelope2D = new GridEnvelope2D(0, 0, (int) cols, (int) rows); g2eMapper.setGridRange(gridEnvelope2D); g2eMapper.setPixelAnchor(PixelInCell.CELL_CENTER); MathTransform gridToEnvelopeTransform = g2eMapper.createTransform(); GridGeometry outputGridGeometry = new GridGeometry2D(gridEnvelope2D, gridToEnvelopeTransform, crs); GridCoverage2D coverage2D = JGrassCatalogUtilities.getGridcoverageFromGrassraster(jgMEnv, sourceRegion); // GrassCoverageReadParam gcReadParam = new // GrassCoverageReadParam(sourceRegion); GridCoverage2D reprojected = (GridCoverage2D) Operations.DEFAULT.resample(coverage2D, crs, outputGridGeometry, Interpolation.getInstance(Interpolation.INTERP_BICUBIC)); JGrassRegion jgRegion = new JGrassRegion(west, newEast, south, newNorth, xResolution, yResolution); // GridCoverage2D coverage2D = tmp.read(null); // GridCoverage2D reprojected = (GridCoverage2D) // Operations.DEFAULT.resample( // coverage2D, crs); // Envelope2D envelope2D = reprojected.getEnvelope2D(); // JGrassRegion jgRegion = new JGrassRegion(envelope2D); if (i == 0) { // create the location structure File grassDbFile = jgMEnv.getLOCATION().getParentFile(); File newLocationFile = new File(grassDbFile, locationName); try { JGrassCatalogUtilities.createLocation(newLocationFile.getAbsolutePath(), crs, jgRegion); JGrassCatalogUtilities.createMapset(newLocationFile.getAbsolutePath(), mapsetName, null, jgRegion); } catch (Exception e) { // ignore this for now } mapsetFile = new File(newLocationFile, mapsetName); } File newMapFile = new File(mapsetFile, JGrassConstants.CELL + File.separator + tmpMap.getMapFile().getName()); JGrassCatalogUtilities.writeGridCoverageFromGrassraster(newMapFile, jgRegion, reprojected); } catch (Exception e) { e.printStackTrace(); } monitor.worked(1); } monitor.done(); JGrassCatalogUtilities.addServiceToCatalog( mapsetFile.getParent() + File.separator + JGrassCatalogUtilities.JGRASS_WORKSPACE_FILENAME, new NullProgressMonitor()); } }; PlatformGIS.runInProgressDialog("Reprojecting maps to new Location...", true, operation, true); }
From source file:eu.udig.catalog.teradata.Activator.java
public static boolean checkTeradataDrivers() { if (TeradataServiceExtension.getFactory().isAvailable()) { return true; } else {//from ww w. j a va 2 s .c om PlatformGIS.asyncInDisplayThread(new Runnable() { public void run() { final Shell shell = Display.getCurrent().getActiveShell(); try { final String pluginName = LICENSE_PLUGIN_ID; final File pluginsDir = findPluginsDir(); LicenseDialog dialog = new LicenseDialog(shell); if (dialog.open() == Window.CANCEL) return; File newPlugin; boolean needUserCopy; File requiredPluginDir = new File(pluginsDir, pluginName); try { newPlugin = requiredPluginDir; createPluginStructure(newPlugin); needUserCopy = false; } catch (Exception e) { newPlugin = new File(System.getProperty("user.home"), pluginName); createPluginStructure(newPlugin); needUserCopy = true; } final String dest = new File(newPlugin, "libs").getPath(); final File finalNewPlugin = newPlugin; transfer(dest, JDBC_FILE_NAME, dialog); transfer(dest, CONFIG_FILE_NAME, dialog); if (needUserCopy) { while (!requiredPluginDir.exists()) { Dialog dialog2 = new Dialog(shell) { protected Control createDialogArea(Composite parent) { Control comp; try { Browser browser = new Browser(parent, SWT.NONE); String mainMessage = String.format(Messages.GetHTMLCopyPluginMsg, finalNewPlugin.getParentFile().getAbsolutePath(), finalNewPlugin.getAbsolutePath(), pluginsDir.getAbsolutePath()); browser.setText(mainMessage); browser.addLocationListener(new LocationListener() { @Override public void changing(LocationEvent event) { event.doit = false; org.eclipse.swt.program.Program.launch(event.location); } @Override public void changed(LocationEvent event) { } }); comp = browser; } catch (SWTError e) { Text text = new Text(parent, SWT.MULTI | SWT.READ_ONLY | SWT.WRAP | SWT.BORDER | SWT.SHADOW_IN); String mainMessage = String.format(Messages.GetDriverMsg, finalNewPlugin.getAbsolutePath(), pluginsDir.getAbsolutePath()); text.setText(mainMessage); comp = text; } GridDataFactory.fillDefaults().hint(500, 200).applyTo(comp); return comp; }; @Override protected Button createButton(Composite parent, int id, String label, boolean defaultButton) { Button button = super.createButton(parent, id, label, defaultButton); if (id == Window.OK) button.setText("Restart"); return button; } }; if (dialog2.open() == Window.CANCEL) return; } } String cmd = buildCommandLine(shell); if (cmd != null) { System.setProperty(PROP_EXIT_CODE, Integer.toString(24)); System.setProperty(PROP_EXIT_DATA, cmd); PlatformUI.getWorkbench().getActiveWorkbenchWindow().getWorkbench().restart(); //PlatformUI.getWorkbench().restart(); } } catch (IOException e1) { throw new RuntimeException(e1); } } public File findPluginsDir() throws IOException { Bundle bundle = Platform.getBundle(GEOTOOLS_LIBS_PLUGIN); String filePath = FileLocator.toFileURL(FileLocator.find(bundle, new Path("gtlib"), emptyMap())) .getFile(); return new File(filePath).getParentFile().getParentFile(); } private void transfer(String dest, String driver, LicenseDialog dialog) throws IOException { RandomAccessFile out = null; RandomAccessFile in = null; try { String fromPath = new File(dialog.getPath(), driver).getPath(); String toPath = new File(dest, driver).getPath(); out = new RandomAccessFile(toPath, "rw"); in = new RandomAccessFile(fromPath.trim(), "r"); out.seek(0); byte[] cs = new byte[(int) in.length()]; in.readFully(cs); out.write(cs); } finally { if (out != null) try { out.close(); } catch (IOException e1) { throw new RuntimeException(e1); } if (in != null) try { in.close(); } catch (IOException e1) { throw new RuntimeException(e1); } } } }, true); return false; } }