imakerplugin/com.nokia.s60tools.imaker/src/com/nokia/s60tools/imaker/internal/dialogs/ProductSelectionDialog.java
changeset 0 61163b28edca
equal deleted inserted replaced
-1:000000000000 0:61163b28edca
       
     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 "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 package com.nokia.s60tools.imaker.internal.dialogs;
       
    18 
       
    19 
       
    20 import java.lang.reflect.InvocationTargetException;
       
    21 import java.util.List;
       
    22 
       
    23 import org.eclipse.jface.dialogs.IDialogConstants;
       
    24 import org.eclipse.jface.dialogs.MessageDialog;
       
    25 import org.eclipse.jface.viewers.ColumnLabelProvider;
       
    26 import org.eclipse.jface.viewers.ISelectionChangedListener;
       
    27 import org.eclipse.jface.viewers.IStructuredContentProvider;
       
    28 import org.eclipse.jface.viewers.IStructuredSelection;
       
    29 import org.eclipse.jface.viewers.SelectionChangedEvent;
       
    30 import org.eclipse.jface.viewers.TableViewer;
       
    31 import org.eclipse.jface.viewers.TableViewerColumn;
       
    32 import org.eclipse.jface.viewers.Viewer;
       
    33 import org.eclipse.swt.SWT;
       
    34 import org.eclipse.swt.layout.GridData;
       
    35 import org.eclipse.swt.layout.GridLayout;
       
    36 import org.eclipse.swt.widgets.Composite;
       
    37 import org.eclipse.swt.widgets.Control;
       
    38 import org.eclipse.swt.widgets.Shell;
       
    39 import org.eclipse.swt.widgets.Table;
       
    40 
       
    41 import com.nokia.s60tools.imaker.IEnvironment;
       
    42 import com.nokia.s60tools.imaker.UIConfiguration;
       
    43 
       
    44 public class ProductSelectionDialog extends MessageDialog {
       
    45 	private UIConfiguration selectedConfiguration = null;
       
    46 	private IEnvironment activeEnvironment = null;
       
    47 	protected boolean dontShowAgain;
       
    48 	private final int style = SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL;
       
    49 	
       
    50 	public ProductSelectionDialog(Shell parentShell, IEnvironment env) {
       
    51 		super(parentShell, "Select product", null, // accept
       
    52         // the
       
    53         // default
       
    54         // window
       
    55         // icon
       
    56 		"The following products are available\n", QUESTION,
       
    57 		new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL },
       
    58 		0);
       
    59 		this.activeEnvironment = env;
       
    60 	}
       
    61 
       
    62 	@Override
       
    63 	protected Control createCustomArea(Composite parent) {
       
    64 		parent.setLayout(new GridLayout(1,true));
       
    65 		
       
    66 		//table 
       
    67 		Composite tableComp = new Composite(parent,SWT.FILL);
       
    68 		tableComp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
       
    69 		tableComp.setLayout(new GridLayout(1,true));
       
    70 		GridData gridData = new GridData(GridData.FILL,GridData.FILL,true,true);
       
    71 		gridData.heightHint = 180;
       
    72 		Table table = new Table(tableComp,style);
       
    73 		table.setLayoutData(gridData);
       
    74 		
       
    75 		TableViewer viewer = new TableViewer(table);
       
    76 
       
    77 		viewer.getTable().setHeaderVisible(true);
       
    78 		viewer.getTable().setLinesVisible(true);
       
    79 
       
    80 		setContentProvider(viewer);
       
    81 		createColumns(viewer);
       
    82 		
       
    83 		viewer.addSelectionChangedListener(new ISelectionChangedListener() {
       
    84 			public void selectionChanged(SelectionChangedEvent event) {
       
    85 				IStructuredSelection sc = (IStructuredSelection) event.getSelection();
       
    86 				selectedConfiguration = (UIConfiguration) sc.getFirstElement();
       
    87 			}
       
    88 		});
       
    89 		
       
    90 		viewer.setInput(this);
       
    91 		return parent;
       
    92 	}
       
    93 	
       
    94 	private void createColumns(TableViewer viewer) {
       
    95 		int columnSizes[] = {110,320};
       
    96 		
       
    97 		TableViewerColumn column = new TableViewerColumn(viewer,SWT.NONE);
       
    98 		column.getColumn().setText("Name");
       
    99 		column.getColumn().setWidth(columnSizes[0]);
       
   100 		column.setLabelProvider(new ColumnLabelProvider() {
       
   101 			@Override
       
   102 			public String getText(Object element) {
       
   103 				UIConfiguration c = (UIConfiguration) element;
       
   104 				return c.getConfigurationName();
       
   105 			}		
       
   106 		});
       
   107 
       
   108 		column = new TableViewerColumn(viewer,SWT.NONE);
       
   109 		column.getColumn().setText("Makefile");
       
   110 		column.getColumn().setWidth(columnSizes[1]);
       
   111 		column.setLabelProvider(new ColumnLabelProvider() {
       
   112 			@Override
       
   113 			public String getText(Object element) {
       
   114 				UIConfiguration c = (UIConfiguration) element;
       
   115 				return c.getFilePath();
       
   116 			}		
       
   117 		});
       
   118 		
       
   119 	}
       
   120 
       
   121 	private void setContentProvider(TableViewer viewer) {
       
   122 		viewer.setContentProvider(new ConfMLFilesContentProvider());
       
   123 	}
       
   124 
       
   125 	public UIConfiguration getSelectedConfiguration() {
       
   126 		return selectedConfiguration;
       
   127 	}
       
   128 
       
   129 	public boolean displayDialog() {
       
   130 		return open() == 0;
       
   131 	}
       
   132 
       
   133 	public boolean isDontShowAgain() {
       
   134 		return dontShowAgain;
       
   135 	}
       
   136 	
       
   137 	/**
       
   138 	 * provide content for the table
       
   139 	 */
       
   140 	private class ConfMLFilesContentProvider implements IStructuredContentProvider {
       
   141 
       
   142 		public Object[] getElements(Object inputElement) {
       
   143 			List<UIConfiguration> configurations;
       
   144 			try {
       
   145 				configurations = activeEnvironment.getConfigurations();
       
   146 				return configurations.toArray();
       
   147 			} catch (InvocationTargetException e) {
       
   148 				return new UIConfiguration[]{};
       
   149 			}
       
   150 		}
       
   151 
       
   152 		public void dispose() {}
       
   153 
       
   154 		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}		
       
   155 	}
       
   156 }