sysperfana/perfinvestigator/com.nokia.carbide.cpp.pi.wizards/src/com/nokia/carbide/cpp/internal/pi/wizards/ui/util/PkgListBaseCustomItem.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.util;
       
    19 
       
    20 import org.eclipse.jface.viewers.ILabelProvider;
       
    21 import org.eclipse.swt.SWT;
       
    22 import org.eclipse.swt.custom.TreeEditor;
       
    23 import org.eclipse.swt.events.SelectionListener;
       
    24 import org.eclipse.swt.widgets.Button;
       
    25 import org.eclipse.swt.widgets.Tree;
       
    26 import org.eclipse.swt.widgets.TreeItem;
       
    27 
       
    28 public class PkgListBaseCustomItem {
       
    29 	private PkgListTreeViewer viewer;
       
    30 	private Object element;
       
    31 	private TreeItem treeItem;
       
    32 	private TreeEditor editor = null;
       
    33 	// hide button because Button.setSelection doesn't fire event
       
    34 	// but we need to catch the selection to fire event for the viewer
       
    35 	// , we can't subclass Button either... so we wrap button around and
       
    36 	// provide only limited access, so we can intercept setSelection()
       
    37 	private Button button = null;
       
    38 	
       
    39 	PkgListBaseCustomItem(PkgListTreeViewer myViewer, final Object myElement, TreeItem myTreeItem) {
       
    40 		viewer = myViewer;
       
    41 		element = myElement;
       
    42 		treeItem = myTreeItem;
       
    43 	}
       
    44 	
       
    45 	public void createButton(int buttonSytle, SelectionListener listener) {
       
    46 		Tree tree = viewer.getTree();
       
    47 		button = new Button(tree, buttonSytle);
       
    48 		editor = new TreeEditor(tree);
       
    49 		button.pack();
       
    50 		button.setBackground(tree.getBackground());
       
    51 		button.setText(((ILabelProvider) viewer.getLabelProvider()).getText(element));
       
    52 		button.addSelectionListener(listener);
       
    53 		editor.grabHorizontal = true;
       
    54 		editor.setEditor(button, treeItem);
       
    55 		editor.minimumWidth = button.getSize().x;
       
    56 		editor.horizontalAlignment = SWT.LEFT;		
       
    57 	}
       
    58 
       
    59 	public boolean getSelection() {
       
    60 		return button.getSelection();
       
    61 	}
       
    62 	
       
    63 	public void setSelection(boolean selection) {
       
    64 		button.setSelection(selection);
       
    65 	}
       
    66 	
       
    67 	public void setEnabled(boolean enabled) {
       
    68 		button.setEnabled(enabled);
       
    69 	}
       
    70 	
       
    71 	public boolean getEnabled() {
       
    72 		return button.getEnabled();
       
    73 	}
       
    74 	
       
    75 	public void dispose() {
       
    76 		if (editor != null) {
       
    77 			editor.dispose();
       
    78 		}
       
    79 		if (button != null) {
       
    80 			button.dispose();
       
    81 		}
       
    82 	}
       
    83 	
       
    84 	public TreeItem getTreeItem() {
       
    85 		return treeItem;
       
    86 	}
       
    87 }