Ejemplo n.º 1
0
  private IStatus removeEvent(final Feature featureToRemove, final IProgressMonitor monitor)
      throws CoreException, Exception {
    final String msg =
        String.format(
            Messages.getString("RemoveEventOperation_4"), featureToRemove.getName()); // $NON-NLS-1$
    monitor.beginTask(msg, 100);

    final IRunoffEvent runoffEvent = (IRunoffEvent) featureToRemove.getAdapter(IRunoffEvent.class);
    IStatus removeResult = null;
    if (runoffEvent != null) {
      monitor.subTask(Messages.getString("RemoveEventOperation_5")); // $NON-NLS-1$
      deleteThemes(m_wspThemes, runoffEvent);
      monitor.worked(10);

      /* Delete underlying tin files */
      monitor.subTask(Messages.getString("RemoveEventOperation_6")); // $NON-NLS-1$
      final ICoverageCollection resultCoverages = runoffEvent.getResultCoverages();
      removeResult = FloodModelHelper.removeResultCoverages(m_provider, resultCoverages);
      monitor.worked(60);

      /* Delete event folder */
      monitor.subTask(Messages.getString("RemoveEventOperation_7")); // $NON-NLS-1$
      final IFolder eventFolder = EventManagementWidget.getEventFolder(runoffEvent);
      eventFolder.delete(true, new SubProgressMonitor(monitor, 20));
    }

    /* Delete coverage from collection */
    monitor.subTask(Messages.getString("RemoveEventOperation_8")); // $NON-NLS-1$
    final CommandableWorkspace workspace =
        m_provider.getCommandableWorkSpace(IFloodModel.class.getName());
    final DeleteFeatureCommand command = new DeleteFeatureCommand(featureToRemove);
    workspace.postCommand(command);
    monitor.worked(10);

    // TODO: Probably we need a more sophisticated error handling here
    if (removeResult != null) return removeResult;
    return Status.OK_STATUS;
  }
Ejemplo n.º 2
0
  private void deleteThemes(final IKalypsoCascadingTheme wspThemes, final IRunoffEvent event) {
    final IKalypsoTheme[] allThemes = wspThemes.getAllThemes();
    for (final IKalypsoTheme kalypsoTheme : allThemes) {
      if (kalypsoTheme instanceof IKalypsoFeatureTheme) {
        final IKalypsoFeatureTheme featureTheme = (IKalypsoFeatureTheme) kalypsoTheme;
        final IKalypsoStyle[] styles = featureTheme.getStyles();
        for (final IKalypsoStyle style : styles) {
          if (style instanceof GisTemplateUserStyle) {
            final GisTemplateUserStyle pooledUserStyle = (GisTemplateUserStyle) style;
            final PoolableObjectType poolKey = pooledUserStyle.getPoolKey();

            final String styleLocationForEventWsp =
                AddEventOperation.styleLocationForEventWsp(event);

            if (poolKey.getLocation().equals(styleLocationForEventWsp)) {
              wspThemes.removeTheme(kalypsoTheme);
              break;
            }
          }
        }
        // check for result coverages
        final FeatureList featureList = featureTheme.getFeatureList();
        if (featureList != null) {
          for (final Object object : featureList) {
            if (object instanceof Feature) {
              final Feature feature = (Feature) object;

              // the papa papa of the coverage is the event
              final Feature parent = feature.getOwner().getOwner();
              if (parent != null) {
                if (parent.getId().equals(event.getId())) {
                  wspThemes.removeTheme(kalypsoTheme);
                }
              }
            }
          }
        }
      }
    }
  }