core/com.nokia.carbide.cpp.codescanner/src/com/nokia/carbide/cpp/internal/codescanner/ui/CSProjectSelectionDialog.java
author stechong
Fri, 03 Apr 2009 09:33:43 -0500
branchRCL_2_0
changeset 33 2d1c891725ea
parent 2 d760517a8095
permissions -rw-r--r--
Added support for IAD rules; fix for Bug 8251.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
cawthron
parents:
diff changeset
     1
/*
cawthron
parents:
diff changeset
     2
* Copyright (c) 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.internal.codescanner.ui;
cawthron
parents:
diff changeset
    19
cawthron
parents:
diff changeset
    20
import org.eclipse.core.resources.IProject;
cawthron
parents:
diff changeset
    21
import org.eclipse.core.runtime.CoreException;
cawthron
parents:
diff changeset
    22
import org.eclipse.core.runtime.IStatus;
cawthron
parents:
diff changeset
    23
import org.eclipse.core.runtime.Status;
cawthron
parents:
diff changeset
    24
import org.eclipse.jface.viewers.ArrayContentProvider;
cawthron
parents:
diff changeset
    25
import org.eclipse.jface.viewers.DoubleClickEvent;
cawthron
parents:
diff changeset
    26
import org.eclipse.jface.viewers.IDoubleClickListener;
cawthron
parents:
diff changeset
    27
import org.eclipse.jface.viewers.ISelectionChangedListener;
cawthron
parents:
diff changeset
    28
import org.eclipse.jface.viewers.IStructuredSelection;
cawthron
parents:
diff changeset
    29
import org.eclipse.jface.viewers.ITableLabelProvider;
cawthron
parents:
diff changeset
    30
import org.eclipse.jface.viewers.LabelProvider;
cawthron
parents:
diff changeset
    31
import org.eclipse.jface.viewers.SelectionChangedEvent;
cawthron
parents:
diff changeset
    32
import org.eclipse.jface.viewers.TableViewer;
cawthron
parents:
diff changeset
    33
import org.eclipse.swt.SWT;
cawthron
parents:
diff changeset
    34
import org.eclipse.swt.graphics.Image;
cawthron
parents:
diff changeset
    35
import org.eclipse.swt.layout.GridData;
cawthron
parents:
diff changeset
    36
import org.eclipse.swt.widgets.Composite;
cawthron
parents:
diff changeset
    37
import org.eclipse.swt.widgets.Control;
cawthron
parents:
diff changeset
    38
import org.eclipse.swt.widgets.Shell;
cawthron
parents:
diff changeset
    39
import org.eclipse.swt.widgets.TableItem;
cawthron
parents:
diff changeset
    40
import org.eclipse.ui.dialogs.SelectionStatusDialog;
cawthron
parents:
diff changeset
    41
cawthron
parents:
diff changeset
    42
import com.nokia.carbide.cpp.internal.codescanner.CSPlugin;
cawthron
parents:
diff changeset
    43
cawthron
parents:
diff changeset
    44
/**
cawthron
parents:
diff changeset
    45
 * A class to handle selection of a project.
cawthron
parents:
diff changeset
    46
 */
cawthron
parents:
diff changeset
    47
public class CSProjectSelectionDialog extends SelectionStatusDialog {
cawthron
parents:
diff changeset
    48
	
cawthron
parents:
diff changeset
    49
	/**
cawthron
parents:
diff changeset
    50
	 * Inner class to handle labels of the project selection table.
cawthron
parents:
diff changeset
    51
	 */
cawthron
parents:
diff changeset
    52
	private class CSProjectLabelProvider extends LabelProvider implements
cawthron
parents:
diff changeset
    53
		ITableLabelProvider {
cawthron
parents:
diff changeset
    54
cawthron
parents:
diff changeset
    55
		public String getColumnText(Object element, int index) {
cawthron
parents:
diff changeset
    56
			IProject project = (IProject) element;
cawthron
parents:
diff changeset
    57
			String projectName = "";
cawthron
parents:
diff changeset
    58
			try {
cawthron
parents:
diff changeset
    59
				projectName = project.getDescription().getName();
cawthron
parents:
diff changeset
    60
			}
cawthron
parents:
diff changeset
    61
			catch (CoreException e) {
cawthron
parents:
diff changeset
    62
				//ignore
cawthron
parents:
diff changeset
    63
			}
cawthron
parents:
diff changeset
    64
			return projectName;
cawthron
parents:
diff changeset
    65
		}
cawthron
parents:
diff changeset
    66
		
cawthron
parents:
diff changeset
    67
		public Image getColumnImage(Object element, int index) {
cawthron
parents:
diff changeset
    68
			return null;
cawthron
parents:
diff changeset
    69
		}
cawthron
parents:
diff changeset
    70
cawthron
parents:
diff changeset
    71
	}
cawthron
parents:
diff changeset
    72
cawthron
parents:
diff changeset
    73
	// private members for various controls of this preference page
cawthron
parents:
diff changeset
    74
	private IProject[] projects;
cawthron
parents:
diff changeset
    75
	private TableViewer tableViewer;
cawthron
parents:
diff changeset
    76
cawthron
parents:
diff changeset
    77
	/**
cawthron
parents:
diff changeset
    78
	 * Create an instance of this dialog.
cawthron
parents:
diff changeset
    79
	 * @param parentShell 
cawthron
parents:
diff changeset
    80
	 * @param projectList - list of projects to be displayed in this dialog
cawthron
parents:
diff changeset
    81
	 */
cawthron
parents:
diff changeset
    82
	CSProjectSelectionDialog(Shell parentShell, IProject[] projectList) {
cawthron
parents:
diff changeset
    83
		super(parentShell);
cawthron
parents:
diff changeset
    84
		setTitle("Project Specific Settings");  
cawthron
parents:
diff changeset
    85
		setMessage("Select the project to configure :"); 
cawthron
parents:
diff changeset
    86
		projects = projectList;
cawthron
parents:
diff changeset
    87
		
cawthron
parents:
diff changeset
    88
        int shellStyle = getShellStyle();
cawthron
parents:
diff changeset
    89
        setShellStyle(shellStyle | SWT.MAX | SWT.RESIZE);
cawthron
parents:
diff changeset
    90
	}
cawthron
parents:
diff changeset
    91
cawthron
parents:
diff changeset
    92
	/**
cawthron
parents:
diff changeset
    93
	 * Create contents of this dialog.
cawthron
parents:
diff changeset
    94
	 * @param parent - the parent composite
cawthron
parents:
diff changeset
    95
	 */
cawthron
parents:
diff changeset
    96
	protected Control createDialogArea(Composite parent) {
cawthron
parents:
diff changeset
    97
		Composite container = (Composite)super.createDialogArea(parent);
cawthron
parents:
diff changeset
    98
		createMessageArea(container);
cawthron
parents:
diff changeset
    99
		
cawthron
parents:
diff changeset
   100
		tableViewer = new TableViewer(container, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
cawthron
parents:
diff changeset
   101
		GridData data= new GridData(SWT.FILL, SWT.FILL, true, true);
cawthron
parents:
diff changeset
   102
		data.heightHint= 200;
cawthron
parents:
diff changeset
   103
		data.widthHint= 200;
cawthron
parents:
diff changeset
   104
		tableViewer.getTable().setLayoutData(data);
cawthron
parents:
diff changeset
   105
		tableViewer.setLabelProvider(new CSProjectLabelProvider());
cawthron
parents:
diff changeset
   106
		tableViewer.setContentProvider(new ArrayContentProvider());
cawthron
parents:
diff changeset
   107
		tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
cawthron
parents:
diff changeset
   108
			public void selectionChanged(SelectionChangedEvent event) {
cawthron
parents:
diff changeset
   109
				doSelectionChanged(((IStructuredSelection) event.getSelection()).toArray());
cawthron
parents:
diff changeset
   110
			}
cawthron
parents:
diff changeset
   111
		});
cawthron
parents:
diff changeset
   112
		tableViewer.addDoubleClickListener(new IDoubleClickListener() {
cawthron
parents:
diff changeset
   113
			public void doubleClick(DoubleClickEvent event) {
cawthron
parents:
diff changeset
   114
                okPressed();
cawthron
parents:
diff changeset
   115
			}
cawthron
parents:
diff changeset
   116
		});
cawthron
parents:
diff changeset
   117
cawthron
parents:
diff changeset
   118
		initializeTable();
cawthron
parents:
diff changeset
   119
		doSelectionChanged(null);
cawthron
parents:
diff changeset
   120
		return container;
cawthron
parents:
diff changeset
   121
	}
cawthron
parents:
diff changeset
   122
cawthron
parents:
diff changeset
   123
    /**
cawthron
parents:
diff changeset
   124
     * Compute the result and return it.
cawthron
parents:
diff changeset
   125
     */
cawthron
parents:
diff changeset
   126
	protected void computeResult() {
cawthron
parents:
diff changeset
   127
	}
cawthron
parents:
diff changeset
   128
cawthron
parents:
diff changeset
   129
	/**
cawthron
parents:
diff changeset
   130
	 * Handle selection within this dialog.
cawthron
parents:
diff changeset
   131
	 * @param objects - objects selected
cawthron
parents:
diff changeset
   132
	 */
cawthron
parents:
diff changeset
   133
	private void doSelectionChanged(Object[] objects) {
cawthron
parents:
diff changeset
   134
		if (objects == null || objects.length != 1) {
cawthron
parents:
diff changeset
   135
			updateStatus(new Status(IStatus.ERROR, CSPlugin.PLUGIN_ID, ""));
cawthron
parents:
diff changeset
   136
			setSelectionResult(null);
cawthron
parents:
diff changeset
   137
		} else {
cawthron
parents:
diff changeset
   138
			updateStatus(new Status(IStatus.OK, CSPlugin.PLUGIN_ID, "")); 
cawthron
parents:
diff changeset
   139
			setSelectionResult(objects);
cawthron
parents:
diff changeset
   140
		}
cawthron
parents:
diff changeset
   141
	}
cawthron
parents:
diff changeset
   142
cawthron
parents:
diff changeset
   143
	/**
cawthron
parents:
diff changeset
   144
	 * Initialize the project selection table.
cawthron
parents:
diff changeset
   145
	 */
cawthron
parents:
diff changeset
   146
	private void initializeTable() {
cawthron
parents:
diff changeset
   147
		for (int i = 0; i < projects.length; i++) {
cawthron
parents:
diff changeset
   148
			TableItem tableItem = new TableItem(tableViewer.getTable(), SWT.LEFT, i);
cawthron
parents:
diff changeset
   149
			tableItem.setData(projects[i]);
cawthron
parents:
diff changeset
   150
			tableItem.setText(projects[i].getName());
cawthron
parents:
diff changeset
   151
		}
cawthron
parents:
diff changeset
   152
	}
cawthron
parents:
diff changeset
   153
}