List of usage examples for java.lang.reflect InvocationTargetException InvocationTargetException
public InvocationTargetException(Throwable target)
From source file:org.kalypso.kalypsomodel1d2d.ui.map.flowrel.FlowRelationshipCalcOperation.java
private TuhhCalculation createCalculation(final IFlowRelation1D flowRel, final TuhhCalculation template, final IProfile[] profiles) throws GMLSchemaException, InvocationTargetException { final IFeatureProviderFactory factory = flowRel.getWorkspace().getFeatureProviderFactory(); // Create empty project with one calculation and one reach final TuhhWspmProject project = TuhhWspmProject.create(null, factory); final TuhhCalculation calculation = project.createReibConstCalculation(); final boolean direction = true; // TODO: depends on building stuff final WspmWaterBody waterBody = project.createOrGetWaterBody("someWater", direction); //$NON-NLS-1$ project.createNewReach(waterBody.getName(), direction); final TuhhReach reach = TuhhWspmProject.createNewReachForWaterBody(waterBody); reach.setName("someReach"); //$NON-NLS-1$ // Add Profiles to reach double minStation = Double.MAX_VALUE; double maxStation = -Double.MAX_VALUE; for (final IProfile profil : profiles) { final double station = profil.getStation(); final IProfileFeature profile = waterBody.createNewProfile(); ((ProfileFeatureBinding) profile).setProfile(profil); reach.createProfileSegment(profile, station); minStation = Math.min(minStation, station); maxStation = Math.max(maxStation, station); }/* ww w . ja v a 2 s .c om*/ // Initialize calculation calculation.setCalcCreation("fe1d2d", new Date()); //$NON-NLS-1$ calculation.setDescription( Messages.getString("org.kalypso.kalypsomodel1d2d.ui.map.flowrel.FlowRelationshipCalcOperation.18")); //$NON-NLS-1$ calculation.setName("1dparameters"); //$NON-NLS-1$ calculation.setReachRef(reach); calculation.setSubReachDef(minStation - 1, maxStation + 1); /* Copy control parameters from template */ calculation.setVersion(template.getVersion()); final Double minQ = template.getMinQ(); final Double maxQ = template.getMaxQ(); final Double step = template.getQStep(); if (minQ == null || maxQ == null || step == null) { final IStatus status = new Status(IStatus.ERROR, KalypsoModel1D2DPlugin.PLUGIN_ID, Messages .getString("org.kalypso.kalypsomodel1d2d.ui.map.flowrel.FlowRelationshipCalcOperation.20")); //$NON-NLS-1$ // FIXME: bah! throw new InvocationTargetException(new CoreException(status)); } calculation.setQRange(minQ, maxQ, step); final boolean calcBuildings; if (flowRel instanceof ITeschkeFlowRelation) calcBuildings = false; else calcBuildings = true; calculation.setWaterlevelParameters(template.getIterationType(), template.getVerzoegerungsverlust(), template.getReibungsverlust(), calcBuildings, calcBuildings, template.isUseExtremeRoughness()); calculation.setStartSlope(template.getStartSlope()); final PolynomeProperties polynomeProperties = calculation.getPolynomeProperties(); final PolynomeProperties templateProperties = template.getPolynomeProperties(); polynomeProperties.setAlphaLimit(templateProperties.getAlphaLimit()); polynomeProperties.setAlphaSlope(templateProperties.getAlphaSlope()); polynomeProperties.setAreaSlope(templateProperties.getAreaSlope()); polynomeProperties.setRunoffSlope(templateProperties.getRunoffSlope()); polynomeProperties.setDeegree(templateProperties.getDeegree()); polynomeProperties.setIgnoreOutlier(templateProperties.getIgnoreOutlier()); polynomeProperties.setTripleForAll(templateProperties.getTripleForAll()); polynomeProperties.setTripleMode(templateProperties.getTripleMode()); polynomeProperties.setWeightSplinePoint(templateProperties.getWeightSplinePoint()); return calculation; }
From source file:org.kalypso.kalypsomodel1d2d.ui.map.temsys.model.ModelTinExporter.java
@Override public IStatus execute(final IProgressMonitor monitor) throws CoreException, InvocationTargetException { final IFE1D2DElement[] elements = m_model.getElements(); final int size = elements.length; monitor.beginTask("Exporting triangles", size); //$NON-NLS-1$ OutputStream os = null;//from ww w . j a v a 2s . c om try { final File dtmJavaFile = m_targetFile.getLocation().toFile(); os = new GZIPOutputStream(new FileOutputStream(dtmJavaFile)); final String crs = KalypsoDeegreePlugin.getDefault().getCoordinateSystem(); final TinResultWriter triangleWriter = new TinResultWriter(os, crs, null); int cnt = 0; for (final IFE1D2DElement element : elements) { if (++cnt % 100 == 0) monitor.subTask(String.format(" %d/%d", cnt, size)); //$NON-NLS-1$ if (element instanceof IPolyElement) { final IPolyElement poly = (IPolyElement) element; final GM_Polygon surface = poly.getGeometry(); if (surface != null) { final GM_Position[] exteriorRing = surface.getSurfacePatch().getExteriorRing(); setMinMax(exteriorRing); triangleWriter.add(exteriorRing[0], exteriorRing[1], exteriorRing[2]); if (exteriorRing.length > 4) triangleWriter.add(exteriorRing[2], exteriorRing[3], exteriorRing[4]); } } ProgressUtilities.worked(monitor, 1); } triangleWriter.finished(); os.close(); return Status.OK_STATUS; } catch (final CoreException e) { e.printStackTrace(); throw e; } catch (final Exception e) { e.printStackTrace(); throw new InvocationTargetException(e); } finally { IOUtils.closeQuietly(os); monitor.done(); m_targetFile.refreshLocal(IResource.DEPTH_ONE, new NullProgressMonitor()); } }
From source file:org.kalypso.kalypsomodel1d2d.ui.wizard.ImportWspmWizard.java
@Override public boolean performFinish() { // FIXME: move into separate class final TuhhCalculation calculation = m_importPage.getCalculation(); final TuhhReach reach = calculation.getReach(); final TuhhReachProfileSegment[] segments = m_importPage.getReachProfileSegments(); final IRiverProfileNetworkCollection profNetworkColl = m_networkModel; final IFEDiscretisationModel1d2d discModel = m_discretisationModel; final IFlowRelationshipModel flowRelModel = m_flowRelationCollection; final List<Feature> discModelAdds = m_discModelAdds; // TODO: do not every time create a new network: if an re-import happens // - find out if same network already exists... (how?) // - ask user to overwrite or not /* Set user friendly name and description */ final IRiverProfileNetwork foundNetwork = findExistingNetwork(profNetworkColl, reach); final IRiverProfileNetwork existingNetwork; if (foundNetwork == null) existingNetwork = null;// www . j a v a 2 s . co m else { final String msg = Messages.getString("org.kalypso.kalypsomodel1d2d.ui.wizard.ImportWspmWizard.11", //$NON-NLS-1$ foundNetwork.getName()); final MessageDialog messageDialog = new MessageDialog( getShell(), getWindowTitle(), null, msg, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }, 1); final int open = messageDialog.open(); System.out.println( Messages.getString("org.kalypso.kalypsomodel1d2d.ui.wizard.ImportWspmWizard.12") + open); //$NON-NLS-1$ if (open == 2 || open == -1) return false; if (open == 0) existingNetwork = foundNetwork; else existingNetwork = null; // do create a new network } /* Do import */ final ICoreRunnableWithProgress op = new ICoreRunnableWithProgress() { @Override public IStatus execute(final IProgressMonitor monitor) throws InvocationTargetException { monitor.beginTask(Messages.getString("org.kalypso.kalypsomodel1d2d.ui.wizard.ImportWspmWizard.4"), //$NON-NLS-1$ 3); try { /* Check if its the right calculation and if results are present */ if (calculation.getCalcMode() != TuhhCalculation.MODE.REIB_KONST) return new Status(IStatus.WARNING, KalypsoModel1D2DPlugin.PLUGIN_ID, Messages.getString("org.kalypso.kalypsomodel1d2d.ui.wizard.ImportWspmWizard.5")); //$NON-NLS-1$ try { /* Import reach into profile collection */ monitor.subTask( Messages.getString("org.kalypso.kalypsomodel1d2d.ui.wizard.ImportWspmWizard.6")); //$NON-NLS-1$ final SortedMap<BigDecimal, IProfileFeature> profilesByStation = doImportNetwork(reach, segments, profNetworkColl, existingNetwork); monitor.worked(1); /* Create 1D-Network */ monitor.subTask( Messages.getString("org.kalypso.kalypsomodel1d2d.ui.wizard.ImportWspmWizard.7")); //$NON-NLS-1$ final SortedMap<BigDecimal, IFE1D2DNode> elementsByStation = doCreate1DNet(reach, segments, discModel, discModelAdds); monitor.worked(1); /* Create 1D-Network parameters (flow relations) */ monitor.subTask( Messages.getString("org.kalypso.kalypsomodel1d2d.ui.wizard.ImportWspmWizard.8")); //$NON-NLS-1$ final IStatus status = doReadResults(calculation, segments, elementsByStation, flowRelModel, profilesByStation); monitor.worked(1); return status; } catch (final Exception e) { e.printStackTrace(); return StatusUtilities.statusFromThrowable(e, Messages.getString("org.kalypso.kalypsomodel1d2d.ui.wizard.ImportWspmWizard.9")); //$NON-NLS-1$ } } catch (final Throwable t) { // TODO: remove all added features from terrainModel // TODO: remove all added features from discModel throw new InvocationTargetException(t); } finally { monitor.done(); } } }; final IStatus status = RunnableContextHelper.execute(getContainer(), true, false, op); if (!status.isOK()) KalypsoModel1D2DPlugin.getDefault().getLog().log(status); ErrorDialog.openError(getShell(), getWindowTitle(), Messages.getString("org.kalypso.kalypsomodel1d2d.ui.wizard.ImportWspmWizard.10"), status); //$NON-NLS-1$ return !status.matches(IStatus.ERROR); }
From source file:org.kalypso.metadoc.impl.FileExportTarget.java
@Override public IStatus commitDocument(final IExportableObject document, final ExtendedProperties conf, final IProgressMonitor monitor) throws InvocationTargetException { monitor.beginTask("Export von " + document.getPreferredDocumentName(), IProgressMonitor.UNKNOWN); FileOutputStream stream = null; try {//from ww w. j a v a 2 s.c o m final File file = (File) conf.getProperty(CONF_FILEEXPORT_FILE); final File docFile; if (file.isDirectory()) docFile = new File(file, document.getPreferredDocumentName()); else docFile = file; stream = new FileOutputStream(docFile); return document.exportObject(stream, monitor); } catch (final FileNotFoundException e) { throw new InvocationTargetException(e); } finally { IOUtils.closeQuietly(stream); monitor.done(); } }
From source file:org.kalypso.model.hydrology.operation.hydrotope.HydrotopeBuilder.java
private void removeOverlappingGeometriesFromExisting() throws InvocationTargetException { try {/*from www. jav a 2 s . co m*/ final IFeatureBindingCollection<IHydrotope> hydrotopes = m_hydrotopes.getHydrotopes(); if (CollectionUtils.isEmpty(hydrotopes)) return; final Geometry intersectionArea = buildIntersectionArea(); final GM_Envelope gmEnvelope = JTSAdapter.wrap(intersectionArea.getEnvelopeInternal(), COORDINATE_SYSTEM); final List<IHydrotope> list = hydrotopes.query(gmEnvelope); for (final IHydrotope hydrotop : list) { final Geometry hydrotopGeom = JTSAdapter.export(hydrotop.getGeometry()); if (hydrotopGeom.disjoint(intersectionArea) || hydrotopGeom.touches(intersectionArea)) continue; if (hydrotopGeom.coveredBy(intersectionArea)) hydrotopes.remove(hydrotop); else { final Geometry difference = hydrotopGeom.difference(intersectionArea); final GM_MultiSurface newHydrotopGeometry = toMultiSurface(difference, COORDINATE_SYSTEM); if (newHydrotopGeometry.isEmpty()) hydrotopes.remove(hydrotop); else hydrotop.setGeometry(newHydrotopGeometry); } } } catch (final GM_Exception e) { throw new InvocationTargetException(e); } }
From source file:org.kalypso.model.rcm.RainfallGenerationOperation.java
@Override public IStatus execute(final IProgressMonitor monitor) throws CoreException, InvocationTargetException { IRainfallCatchmentModel rcm = null;//from w ww .java 2 s . c om // FIXME: does not belong here -> instead the whole process (i.e. result status of the outer operation) should be // save in one go into the log -> // the log should also show information about the analysis of the available entries etc. GeoStatusLog log = null; try { // Real work starts here: create the operation, convert and validate parameters final SubMonitor progress = SubMonitor.convert(monitor, Messages.getString("RainfallGenerationOperation_0"), 100); //$NON-NLS-1$ rcm = m_modelProvider.getRainfallCatchmentModell(progress.newChild(9)); log = initializeLog(rcm); final ITarget targetDefinition = rcm.getTarget(); if (targetDefinition == null) { final String message = String.format(Messages.getString("RainfallGenerationOperation_1")); //$NON-NLS-1$ final Status status = new Status(IStatus.OK, KalypsoModelRcmActivator.PLUGIN_ID, message); log.log(status); return status; } final Feature[] catchments = targetDefinition.resolveCatchments(); final IMetadata[] metadata = rcm.getMetadata().toArray(new IMetadata[0]); final IRainfallGenerator[] generators = rcm.getGenerators().toArray(new IRainfallGenerator[0]); final RainfallGenerationOp operation = new RainfallGenerationOp(catchments, generators, metadata, m_variables, log); final IStatus status = operation.execute(progress.newChild(90, SubMonitor.SUPPRESS_NONE)); /* Find target links right now, to avoid long waiting time if anything fails here. */ final IObservation[] observations = operation.getResult(); final TimeseriesLinkType[] targetLinks = findCatchmentLinks(targetDefinition, catchments); writeObservations(targetDefinition, observations, targetLinks, catchments); return status; } catch (final CoreException e) { if (log != null) log.log(e.getStatus()); // TODO: log other exceptions as well? throw e; } catch (final RuntimeException e) { if (RuntimeException.class == e.getClass()) throw new InvocationTargetException(e.getCause()); else throw new InvocationTargetException(e); } catch (final Throwable e) { throw new InvocationTargetException(e); } finally { /* Write the log, if one was created. */ if (log != null) log.serialize(); if (rcm != null) rcm.getWorkspace().dispose(); } }
From source file:org.kalypso.model.wspm.pdb.ui.internal.admin.gaf.ImportGafWizard.java
@Override public IStatus postInit(final IProgressMonitor monitor) throws InvocationTargetException { try {// w w w. j a v a 2s. c o m monitor.beginTask(Messages.getString("ImportGafWizard.1"), IProgressMonitor.UNKNOWN); //$NON-NLS-1$ m_data.initFromDb(); m_data.init(getDialogSettings()); return Status.OK_STATUS; } catch (final Exception e) { e.printStackTrace(); throw new InvocationTargetException(e); } finally { monitor.done(); } }
From source file:org.kalypso.model.wspm.tuhh.core.profile.importer.wprof.WProfImportOperation.java
/** * @see org.kalypso.contribs.eclipse.jface.operation.ICoreRunnableWithProgress#execute(org.eclipse.core.runtime.IProgressMonitor) *//*w w w. j a v a 2 s .c o m*/ @Override public IStatus execute(final IProgressMonitor monitor) throws CoreException, InvocationTargetException { try { doImport(monitor); } catch (final IOException e) { throw new InvocationTargetException(e); } catch (final GmlSerializeException e) { throw new InvocationTargetException(e); } finally { monitor.done(); } return Status.OK_STATUS; }
From source file:org.kalypso.model.wspm.tuhh.core.wspwin.WspWinExportGmlOperation.java
@Override public IStatus execute(final IProgressMonitor monitor) throws InvocationTargetException { try {//from www . ja v a2s. c o m final WspmWaterBody[] waters = m_data.getWaterBodies(); monitor.beginTask(Messages.getString("WspWinExportGmlOperation_0"), waters.length); //$NON-NLS-1$ final File outputDir = m_data.getOutputDir(); if (outputDir.isDirectory()) FileUtils.cleanDirectory(outputDir); final TYPE projectType = m_data.getProjectType(); final String probez = getProjectName(waters); final String roughnessType = m_data.getRoughnessType(); final boolean preferRoghnessClasses = m_data.getPreferRoughnessClasses(); final boolean preferVegetationClasses = m_data.getPreferVegetationClasses(); final WspWinProjectWriter wspWinWriter = new WspWinProjectWriter(probez, projectType, outputDir, roughnessType, preferRoghnessClasses, preferVegetationClasses); for (final WspmWaterBody waterBody : waters) { monitor.subTask(waterBody.getName()); final TuhhReach[] reaches = m_data.getReaches(waterBody); wspWinWriter.addReaches(waterBody, reaches); } wspWinWriter.write(); return Status.OK_STATUS; } catch (final IOException e) { e.printStackTrace(); throw new InvocationTargetException(e); } finally { monitor.done(); } }
From source file:org.kalypso.model.wspm.tuhh.ui.imports.sobek.SobekImportOperation.java
@Override public IStatus execute(final IProgressMonitor monitor) throws CoreException, InvocationTargetException { monitor.beginTask(Messages.getString("SobekImportOperation.0"), 100); //$NON-NLS-1$ try {/*from w w w . ja v a 2 s.c o m*/ // find files for parsing final FileAndHistoryData inputDir = m_data.getInputDir(); final SobekModelParser modelParser = new SobekModelParser(inputDir.getFile()); final SobekModel model = modelParser.read(new SubProgressMonitor(monitor, 30)); final Sobek2Wspm sobek2Wspm = new Sobek2Wspm(m_data); sobek2Wspm.convert(model); final CommandableWorkspace workspace = m_data.getWorkspace(); final WspmWaterBody water = m_data.getWater(); final Feature[] newFeatures = sobek2Wspm.getNewFeatures(); workspace.fireModellEvent(new FeatureStructureChangeModellEvent(workspace, water, newFeatures, FeatureStructureChangeModellEvent.STRUCTURE_CHANGE_ADD)); workspace.postCommand(new EmptyCommand(StringUtils.EMPTY, false)); return sobek2Wspm.getStatus(); } catch (final IOException e) { e.printStackTrace(); throw new InvocationTargetException(e); } catch (final CoreException e) { throw e; } catch (final Exception e) { e.printStackTrace(); throw new InvocationTargetException(e); } }