Package org.cloudfoundry.ide.eclipse.server.ui.internal.wizards

Source Code of org.cloudfoundry.ide.eclipse.server.ui.internal.wizards.DeleteServicesWizard

/*******************************************************************************
* Copyright (c) 2012, 2014 Pivotal Software, Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Apache License,
* Version 2.0 (the "License�); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*  Contributors:
*     Pivotal Software, Inc. - initial API and implementation
********************************************************************************/
package org.cloudfoundry.ide.eclipse.server.ui.internal.wizards;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

import org.cloudfoundry.ide.eclipse.server.core.internal.CloudFoundryPlugin;
import org.cloudfoundry.ide.eclipse.server.core.internal.CloudFoundryServer;
import org.cloudfoundry.ide.eclipse.server.ui.internal.Messages;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.osgi.util.NLS;
import org.eclipse.ui.statushandlers.StatusManager;

/**
* @author Terry Denney
*/
public class DeleteServicesWizard extends Wizard {

  private final CloudFoundryServer cloudServer;

  private DeleteServicesWizardPage page;

  private final List<String> services;

  public DeleteServicesWizard(CloudFoundryServer cloudServer, List<String> services) {
    this.cloudServer = cloudServer;
    this.services = services;
    setWindowTitle(Messages.DeleteServicesWizard_TITLE_DELETE_SERVICE);
    setNeedsProgressMonitor(true);
  }

  @Override
  public void addPages() {
    page = new DeleteServicesWizardPage(cloudServer, services);
    addPage(page);
  }

  @Override
  public boolean performFinish() {
    try {
      getContainer().run(true, false, new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
          try {
            List<String> selectedServices = page.getSelectedServices();
            if (selectedServices.size() > 0) {
              cloudServer.getBehaviour().getDeleteServicesOperation(selectedServices).run(monitor);
            }
          }
          catch (CoreException e) {
            throw new InvocationTargetException(e);
          }
          catch (OperationCanceledException e) {
            throw new InterruptedException();
          }
          finally {
            monitor.done();
          }
        }
      });
      return true;
    }
    catch (InvocationTargetException e) {
      if (e.getCause() instanceof CoreException) {
        Status status = new Status(IStatus.ERROR, CloudFoundryPlugin.PLUGIN_ID, NLS.bind(
            Messages.DeleteServicesWizard_ERROR_DELETE_SERVICE, cloudServer.getServer().getName(), e.getCause()
                .getMessage()), e);
        StatusManager.getManager().handle(status, StatusManager.SHOW | StatusManager.BLOCK | StatusManager.LOG);
      }
    }
    catch (InterruptedException e) {
      // ignore
    }
    return false;
  }

}
TOP

Related Classes of org.cloudfoundry.ide.eclipse.server.ui.internal.wizards.DeleteServicesWizard

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.