sysperfana/perfinvestigator/com.nokia.carbide.cpp.pi.wizards/src/com/nokia/carbide/cpp/internal/pi/wizards/ui/NewPIWizardRemovePkgDialog.java
changeset 2 b9ab3b238396
equal deleted inserted replaced
1:1050670c6980 2:b9ab3b238396
       
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of the License "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description: 
       
    15  *
       
    16  */
       
    17 
       
    18 package com.nokia.carbide.cpp.internal.pi.wizards.ui;
       
    19 
       
    20 import java.util.ArrayList;
       
    21 
       
    22 import org.eclipse.jface.dialogs.IDialogConstants;
       
    23 import org.eclipse.jface.dialogs.TrayDialog;
       
    24 import org.eclipse.swt.SWT;
       
    25 import org.eclipse.swt.events.SelectionAdapter;
       
    26 import org.eclipse.swt.events.SelectionEvent;
       
    27 import org.eclipse.swt.layout.GridData;
       
    28 import org.eclipse.swt.layout.GridLayout;
       
    29 import org.eclipse.swt.widgets.Composite;
       
    30 import org.eclipse.swt.widgets.Control;
       
    31 import org.eclipse.swt.widgets.Label;
       
    32 import org.eclipse.swt.widgets.Shell;
       
    33 import org.eclipse.swt.widgets.Table;
       
    34 import org.eclipse.swt.widgets.TableItem;
       
    35 
       
    36 import com.nokia.carbide.cpp.internal.pi.wizards.ui.util.IPkgEntry;
       
    37 
       
    38 public class NewPIWizardRemovePkgDialog extends TrayDialog{
       
    39 	
       
    40 	private IPkgEntry[] entryList;
       
    41 	private IPkgEntry[] removeList;
       
    42 	
       
    43 	// control
       
    44 	private Composite composite = null;
       
    45 	private Table table = null;
       
    46 	private Label label = null;
       
    47 	
       
    48 	protected NewPIWizardRemovePkgDialog(Shell arg0, IPkgEntry[] pkgFiles) {
       
    49 		super(arg0);
       
    50 		entryList = pkgFiles;
       
    51 	}
       
    52 
       
    53 	public Control createDialogArea(Composite parent) {
       
    54 		getShell().setText(Messages.getString("NewPIWizardRemovePkgDialog.shell.title")); //$NON-NLS-1$
       
    55 		GridLayout gridLayout = new GridLayout();
       
    56 		gridLayout.numColumns = 1;
       
    57 		composite = new Composite(parent, SWT.NONE);
       
    58 		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
       
    59 		composite.setLayout(gridLayout);
       
    60 		label = new Label(composite, SWT.NONE);
       
    61 		label.setText(Messages.getString("NewPIWizardRemovePkgDialog.check.pkg.label")); //$NON-NLS-1$
       
    62 		table = new Table(composite, SWT.CHECK | SWT.H_SCROLL | SWT.BORDER);
       
    63 		
       
    64 		// load settings
       
    65 		if (entryList != null) {
       
    66 			for (int i = 0; i < entryList.length; i++) {
       
    67 				TableItem item = new TableItem(table, SWT.NONE);
       
    68 				String pkgText = Messages.getString("NewPIWizardRemovePkgDialog.sample.file") + entryList[i].getPkgFile(); //$NON-NLS-1$
       
    69 				if (entryList[i].getSdk() != null) {
       
    70 					pkgText += Messages.getString("NewPIWizardRemovePkgDialog.sdk") + entryList[i].getSdk().getUniqueId(); //$NON-NLS-1$
       
    71 				}
       
    72 				item.setText(pkgText);
       
    73 				item.setData(entryList[i]);	// bound the pkgFile to the button, so we can retrieve later
       
    74 				item.setChecked(false);
       
    75 			}
       
    76 		}
       
    77 		table.addSelectionListener(new SelectionAdapter() {
       
    78 
       
    79 			public void widgetSelected(SelectionEvent e) {
       
    80 				TableItem[] items = table.getItems();
       
    81 				getButton(IDialogConstants.OK_ID).setEnabled(false);
       
    82 				if (items != null) {
       
    83 					for (TableItem item : items) {
       
    84 						if (item.getChecked()) {
       
    85 							getButton(IDialogConstants.OK_ID).setEnabled(true);
       
    86 						}
       
    87 					}
       
    88 				}
       
    89 			}
       
    90 		});
       
    91 		
       
    92 		return composite;
       
    93 	}
       
    94 	
       
    95 	public void okPressed() {
       
    96 		ArrayList<IPkgEntry> removeArrayList = new ArrayList<IPkgEntry>();
       
    97 		TableItem[] items = table.getItems();
       
    98 		for (int i = 0; i < items.length; i++) {
       
    99 			if (items[i].getChecked()) {
       
   100 				removeArrayList.add((IPkgEntry) items[i].getData());
       
   101 			}
       
   102 		}
       
   103 		removeList = removeArrayList.toArray(new IPkgEntry[removeArrayList.size()]);
       
   104 		super.okPressed();
       
   105 	}
       
   106 	
       
   107 	public IPkgEntry[] getRemovedList () {
       
   108 		return removeList;
       
   109 	}
       
   110 	
       
   111 	protected void createButtonsForButtonBar(Composite parent) {
       
   112 		super.createButtonsForButtonBar(parent);
       
   113 		// now buttons are there, we can  disable key
       
   114 		getButton(IDialogConstants.OK_ID).setEnabled(false);
       
   115 	}
       
   116 }