carbidesdk/com.nokia.carbide.cpp.sdk.examples/src/com/nokia/carbide/cpp/sdk/examples/actions/CreateReportAction.java
author timkelly
Fri, 27 Mar 2009 10:37:25 -0500
changeset 13 a515b8873c8c
parent 2 d760517a8095
permissions -rw-r--r--
Update to describe how SFO CDK works
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
cawthron
parents:
diff changeset
     1
/*
cawthron
parents:
diff changeset
     2
* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
cawthron
parents:
diff changeset
     3
* All rights reserved.
cawthron
parents:
diff changeset
     4
* This component and the accompanying materials are made available
cawthron
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
cawthron
parents:
diff changeset
     6
* which accompanies this distribution, and is available
cawthron
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
cawthron
parents:
diff changeset
     8
*
cawthron
parents:
diff changeset
     9
* Initial Contributors:
cawthron
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
cawthron
parents:
diff changeset
    11
*
cawthron
parents:
diff changeset
    12
* Contributors:
cawthron
parents:
diff changeset
    13
*
cawthron
parents:
diff changeset
    14
* Description: 
cawthron
parents:
diff changeset
    15
*
cawthron
parents:
diff changeset
    16
*/
cawthron
parents:
diff changeset
    17
cawthron
parents:
diff changeset
    18
package com.nokia.carbide.cpp.sdk.examples.actions;
cawthron
parents:
diff changeset
    19
cawthron
parents:
diff changeset
    20
import com.nokia.carbide.cpp.sdk.examples.jobs.ProjectReportJob;
cawthron
parents:
diff changeset
    21
cawthron
parents:
diff changeset
    22
import org.eclipse.core.resources.IProject;
cawthron
parents:
diff changeset
    23
import org.eclipse.core.resources.ResourcesPlugin;
cawthron
parents:
diff changeset
    24
import org.eclipse.jface.action.IAction;
cawthron
parents:
diff changeset
    25
import org.eclipse.jface.dialogs.Dialog;
cawthron
parents:
diff changeset
    26
import org.eclipse.jface.viewers.ArrayContentProvider;
cawthron
parents:
diff changeset
    27
import org.eclipse.jface.viewers.ISelection;
cawthron
parents:
diff changeset
    28
import org.eclipse.ui.IWorkbenchWindow;
cawthron
parents:
diff changeset
    29
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
cawthron
parents:
diff changeset
    30
import org.eclipse.ui.dialogs.ListDialog;
cawthron
parents:
diff changeset
    31
import org.eclipse.ui.model.WorkbenchLabelProvider;
cawthron
parents:
diff changeset
    32
cawthron
parents:
diff changeset
    33
/**
cawthron
parents:
diff changeset
    34
 * This action is invoked when the user chooses our menu item.
cawthron
parents:
diff changeset
    35
 * The action is responsible for prompting the user for a
cawthron
parents:
diff changeset
    36
 * a project.
cawthron
parents:
diff changeset
    37
 * The report creation is performed in {@link ProjectReportJob}
cawthron
parents:
diff changeset
    38
 */
cawthron
parents:
diff changeset
    39
public class CreateReportAction implements IWorkbenchWindowActionDelegate {
cawthron
parents:
diff changeset
    40
	
cawthron
parents:
diff changeset
    41
	private IWorkbenchWindow window;
cawthron
parents:
diff changeset
    42
cawthron
parents:
diff changeset
    43
	public CreateReportAction() {
cawthron
parents:
diff changeset
    44
	}
cawthron
parents:
diff changeset
    45
cawthron
parents:
diff changeset
    46
	public void dispose() {
cawthron
parents:
diff changeset
    47
	}
cawthron
parents:
diff changeset
    48
cawthron
parents:
diff changeset
    49
	public void init(IWorkbenchWindow window) {
cawthron
parents:
diff changeset
    50
		this.window = window;
cawthron
parents:
diff changeset
    51
	}
cawthron
parents:
diff changeset
    52
cawthron
parents:
diff changeset
    53
	public void run(IAction action) {
cawthron
parents:
diff changeset
    54
		// Ask the user to choose a project
cawthron
parents:
diff changeset
    55
		ListDialog dialog = new ListDialog(window.getShell());
cawthron
parents:
diff changeset
    56
		dialog.setTitle("Project Report Example");
cawthron
parents:
diff changeset
    57
		dialog.setMessage("Please select a project");
cawthron
parents:
diff changeset
    58
		dialog.setInput(ResourcesPlugin.getWorkspace().getRoot().getProjects());
cawthron
parents:
diff changeset
    59
		dialog.setContentProvider(new ArrayContentProvider());
cawthron
parents:
diff changeset
    60
		dialog.setLabelProvider(new WorkbenchLabelProvider());
cawthron
parents:
diff changeset
    61
		if (dialog.open() == Dialog.OK) {
cawthron
parents:
diff changeset
    62
			Object[] selection = dialog.getResult();
cawthron
parents:
diff changeset
    63
			if (selection != null && selection.length > 0 &&
cawthron
parents:
diff changeset
    64
				selection[0] instanceof IProject) {
cawthron
parents:
diff changeset
    65
				IProject project = (IProject) selection[0];
cawthron
parents:
diff changeset
    66
				
cawthron
parents:
diff changeset
    67
				// Do all the work in a WorkspaceJob
cawthron
parents:
diff changeset
    68
				ProjectReportJob job = new ProjectReportJob(project);
cawthron
parents:
diff changeset
    69
				job.schedule();
cawthron
parents:
diff changeset
    70
			}
cawthron
parents:
diff changeset
    71
		}
cawthron
parents:
diff changeset
    72
	}
cawthron
parents:
diff changeset
    73
cawthron
parents:
diff changeset
    74
	public void selectionChanged(IAction action, ISelection selection) {
cawthron
parents:
diff changeset
    75
	}
cawthron
parents:
diff changeset
    76
}