2 * Copyright 2015 Samsung Electronics All Rights Reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package oic.simulator.serviceprovider.view.dialogs;
19 import java.lang.reflect.InvocationTargetException;
21 import java.util.Date;
24 import oic.simulator.serviceprovider.Activator;
25 import oic.simulator.serviceprovider.manager.ResourceManager;
26 import oic.simulator.serviceprovider.model.Resource;
27 import oic.simulator.serviceprovider.model.SingleResource;
29 import org.eclipse.core.runtime.FileLocator;
30 import org.eclipse.core.runtime.IPath;
31 import org.eclipse.core.runtime.IProgressMonitor;
32 import org.eclipse.core.runtime.Path;
33 import org.eclipse.jface.operation.IRunnableWithProgress;
34 import org.eclipse.jface.resource.ImageDescriptor;
35 import org.eclipse.jface.wizard.Wizard;
36 import org.oic.simulator.ILogger.Level;
37 import org.oic.simulator.SimulatorException;
40 * This class creates a UI wizard for delete resource operation.
42 public class DeleteResourceWizard extends Wizard {
44 private DeleteResourcePage page;
46 private String status;
48 public DeleteResourceWizard() {
49 setWindowTitle("Delete resources");
50 IPath path = new Path("/icons/oic_logo_64x64.png");
51 URL find = FileLocator.find(Activator.getDefault().getBundle(), path,
53 setDefaultPageImageDescriptor(ImageDescriptor.createFromURL(find));
55 setNeedsProgressMonitor(true);
59 public void addPages() {
60 page = new DeleteResourcePage();
65 public boolean performFinish() {
70 getContainer().run(true, false, new IRunnableWithProgress() {
73 public void run(IProgressMonitor monitor)
74 throws InvocationTargetException, InterruptedException {
75 ResourceManager resourceManager = Activator.getDefault()
76 .getResourceManager();
78 monitor.beginTask("Resource Deletion", 2);
80 Set<SingleResource> singleResources = page
81 .getSelectedSingleResourcesList();
82 if (null != singleResources
83 && singleResources.size() > 0) {
84 Activator.getDefault().getResourceManager()
85 .removeSingleResources(singleResources);
87 Resource res = resourceManager
88 .getCurrentResourceInSelection();
89 if (null != res && res instanceof SingleResource) {
91 .contains((SingleResource) res)) {
93 .resourceSelectionChanged(null);
98 status = "Resources deleted.";
99 } catch (SimulatorException e) {
100 status = "Failed to delete some of the resources. Please try again.";
106 } catch (InvocationTargetException e) {
107 Activator.getDefault().getLogManager()
108 .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
109 } catch (InterruptedException e) {
110 Activator.getDefault().getLogManager()
111 .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
116 public String getStatus() {