예제 #1
0
  @Override
  public IStatus execute(final IProgressMonitor monitor)
      throws CoreException, InvocationTargetException {
    final SubMonitor progress =
        SubMonitor.convert(
            monitor,
            Messages.getString("org.kalypso.model.flood.ui.map.operations.ImportTinOperation.0"),
            100); //$NON-NLS-1$

    /* Add sources as new tin references */
    progress.subTask(
        Messages.getString(
            "org.kalypso.model.flood.ui.map.operations.ImportTinOperation.1")); //$NON-NLS-1$
    m_tinRefs = new ITinReference[m_sources.length];
    final Feature[] changedFeatures = new Feature[m_sources.length];

    for (int i = 0; i < m_sources.length; i++) {
      final IGmlSource source = m_sources[i];

      final ITinReference tinRef = m_tins.addNew(-1, ITinReference.QNAME, ITinReference.class);
      tinRef.setName(source.getName());
      tinRef.setDescription(source.getDescription());
      tinRef.setSourceLocation(source.getLocation());
      tinRef.setSourceFeaturePath(source.getPath());
      tinRef.setSourceType(typeForSource(source));

      m_tinRefs[i] = tinRef;
      changedFeatures[i] = tinRef;
    }
    ProgressUtilities.worked(progress, 20);

    /* post command for events stuff... */
    final Feature parentFeature = m_tins.getParentFeature();
    final GMLWorkspace workspace = parentFeature.getWorkspace();
    final ModellEvent modelEvent =
        new FeatureStructureChangeModellEvent(
            workspace,
            parentFeature,
            changedFeatures,
            FeatureStructureChangeModellEvent.STRUCTURE_CHANGE_ADD);
    workspace.fireModellEvent(modelEvent);
    /* Save data model */
    // progress.subTask( "speichere Datenmodell" );
    // m_provider.saveModel( IFloodModel.class, progress.newChild( 20 ) );
    /* update tins */
    progress.subTask(
        Messages.getString(
            "org.kalypso.model.flood.ui.map.operations.ImportTinOperation.2")); //$NON-NLS-1$
    final UpdateTinsOperation updateOp = new UpdateTinsOperation(m_tinRefs, m_provider);
    updateOp.execute(progress.newChild(60));

    /* Jump to imported tins */
    final GM_Envelope envelope = FeatureHelper.getEnvelope(changedFeatures);
    final GM_Envelope scaledBox =
        envelope == null ? null : GeometryUtilities.scaleEnvelope(envelope, 1.05);
    if (m_mapPanel != null && scaledBox != null) m_mapPanel.setBoundingBox(scaledBox);

    return Status.OK_STATUS;
  }
  /** @see org.apache.tools.ant.Task#execute() */
  @Override
  public void execute() throws BuildException {
    try {
      // Initialise ant-stuff: progress monitor and logging
      final Project antProject = getProject();
      final String message = getDescription();
      final String taskMessage = message == null || message.length() == 0 ? getTaskName() : message;

      final Hashtable<?, ?> references = antProject == null ? null : antProject.getReferences();
      final IProgressMonitor monitor =
          references == null
              ? null
              : (IProgressMonitor) references.get(AntCorePlugin.ECLIPSE_PROGRESS_MONITOR);

      // REMARK: It is NOT possible to put this inner class into an own .class file (at least not
      // inside the plugin
      // code) else we get an LinkageError when accessing the Project class.
      final ILogger logger =
          new ILogger() {
            /**
             * @see org.kalypso.contribs.java.util.logging.ILogger#log(java.util.logging.Level, int,
             *     java.lang.String)
             */
            @Override
            public void log(final Level level, final int msgCode, final String logMessage) {
              final String outString = LoggerUtilities.formatLogStylish(level, msgCode, logMessage);
              final int antLevel = mapLevelToAnt(level);

              antProject.log(RainfallGenerationTask.this, outString, antLevel);
            }
          };

      logger.log(Level.INFO, LoggerUtilities.CODE_NEW_MSGBOX, taskMessage);

      // Real work starts here: create the operation, convert and validate parameters
      final SubMonitor progress = SubMonitor.convert(monitor, taskMessage, 100);
      progress.subTask("Operation wird initialisiert");

      ProgressUtilities.worked(progress, 4);

      final IStatus status =
          executeOperation(antProject, progress.newChild(95, SubMonitor.SUPPRESS_NONE));
      // TODO: write status into logger
    } catch (final Throwable e) {
      e.printStackTrace();
      throw new BuildException(e);
    }
  }