sysperfana/perfinvestigator/com.nokia.carbide.cpp.pi.wizards/src/com/nokia/carbide/cpp/internal/pi/wizards/ui/NewPIWizardPageCustomTask.java
changeset 2 b9ab3b238396
child 12 ae255c9aa552
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.io.File;
       
    21 
       
    22 import org.eclipse.swt.SWT;
       
    23 import org.eclipse.swt.events.ModifyEvent;
       
    24 import org.eclipse.swt.events.ModifyListener;
       
    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.Button;
       
    30 import org.eclipse.swt.widgets.Composite;
       
    31 import org.eclipse.swt.widgets.FileDialog;
       
    32 import org.eclipse.swt.widgets.Group;
       
    33 import org.eclipse.swt.widgets.Label;
       
    34 import org.eclipse.swt.widgets.Text;
       
    35 import org.eclipse.ui.PlatformUI;
       
    36 
       
    37 import com.nokia.carbide.cpp.internal.pi.wizards.ui.util.CarbidePiWizardHelpIds;
       
    38 
       
    39 
       
    40 public class NewPIWizardPageCustomTask
       
    41 extends NewPIWizardPage
       
    42 implements INewPIWizardSettings
       
    43 {
       
    44 private final static String UID_PROPERTY= ".uid"; //$NON-NLS-1$
       
    45 private final static String DAT_EXTENSION= "dat"; //$NON-NLS-1$
       
    46 
       
    47 protected NewPIWizardPageCustomTask(final NewPIWizard wizard) {
       
    48 	super(Messages.getString("NewPIWizardPageCustomTask.super.label")); //$NON-NLS-1$
       
    49 	setTitle(Messages.getString("NewPIWizardPageCustomTask.title")); //$NON-NLS-1$
       
    50     setDescription(Messages.getString("NewPIWizardPageCustomTask.description")); //$NON-NLS-1$
       
    51 }
       
    52 
       
    53 // controls
       
    54 Composite container;
       
    55 Group formatGroup;
       
    56 Composite optionComposite;
       
    57 Group exampleGroup;
       
    58 Group baseGroup;
       
    59 Group seperatorGroup;
       
    60 Button buttonValue;
       
    61 Button buttonName;
       
    62 Button buttonSemicolon;
       
    63 Button buttonComma;
       
    64 Button buttonSpace;
       
    65 
       
    66 private Text sampleFileText;
       
    67 
       
    68 public void createControl(Composite parent) {
       
    69 	super.createControl(parent);
       
    70 	container = new Composite(parent, SWT.NULL);
       
    71 	container.setData(UID_PROPERTY, "container"); //$NON-NLS-1$
       
    72 	GridLayout layout = new GridLayout();
       
    73 	container.setLayout(layout);
       
    74 	layout.numColumns = 1;
       
    75 	layout.verticalSpacing = 9;
       
    76 
       
    77 	Label labelDetailLabel = new Label(container, SWT.NONE);
       
    78 	labelDetailLabel.setText(Messages.getString("NewPIWizardPageCustomTask.detail.label")); //$NON-NLS-1$
       
    79 
       
    80 	Label labelSampleFile = new Label(container, SWT.NONE);
       
    81 	labelSampleFile.setText(Messages.getString("NewPIWizardPageSampleFile.dat.file.name")); //$NON-NLS-1$
       
    82 	
       
    83 	// subcomposite with textbox/button
       
    84 	Composite subContainer = new Composite(container, SWT.NULL);
       
    85 	subContainer.setData(UID_PROPERTY, "subContainer"); //$NON-NLS-1$
       
    86 	GridLayout subLayout = new GridLayout();
       
    87 	subContainer.setLayout(subLayout);
       
    88 	subContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
       
    89 	subLayout.numColumns = 2;
       
    90 	subLayout.verticalSpacing = 9;
       
    91 
       
    92 	sampleFileText = new Text(subContainer, SWT.BORDER | SWT.SINGLE);
       
    93 	sampleFileText.setData(UID_PROPERTY, "sampleFileText"); //$NON-NLS-1$
       
    94 	sampleFileText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
       
    95 	sampleFileText.addModifyListener(new ModifyListener() {
       
    96 		public void modifyText(ModifyEvent e) {
       
    97 			validatePage();
       
    98 		}
       
    99 	});
       
   100 
       
   101 	Button button = new Button(subContainer, SWT.PUSH);
       
   102 	button.setText(Messages.getString("NewPIWizardPageSampleFile.browse")); //$NON-NLS-1$
       
   103 	button.addSelectionListener(new SelectionAdapter() {
       
   104 		public void widgetSelected(SelectionEvent e) {
       
   105 			handleBrowse();
       
   106 		}
       
   107 	});
       
   108 	
       
   109 	// group with the options
       
   110 	formatGroup = new Group(container, SWT.NONE);
       
   111 	GridLayout groupLayout = new GridLayout();
       
   112 	groupLayout.numColumns = 2;
       
   113 	groupLayout.verticalSpacing = 9;
       
   114 	formatGroup.setLayout(groupLayout);
       
   115 	formatGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
       
   116 	formatGroup.setText(Messages.getString("NewPIWizardPageCustomTask.format.group")); //$NON-NLS-1$
       
   117 	optionComposite = new Composite (formatGroup, SWT.NONE);
       
   118 	GridLayout optionLayout = new GridLayout();
       
   119 	optionLayout.numColumns = 1;
       
   120 	optionLayout.verticalSpacing = 9;
       
   121 	optionComposite.setLayout(optionLayout);
       
   122 	optionComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
       
   123 	
       
   124 	exampleGroup = new Group(formatGroup, SWT.NONE);
       
   125 	GridLayout exampleLayout = new GridLayout();
       
   126 	exampleLayout.numColumns = 2;
       
   127 	exampleLayout.verticalSpacing = 9;
       
   128 	exampleGroup.setLayout(groupLayout);
       
   129 	exampleGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
       
   130 	exampleGroup.setText(Messages.getString("NewPIWizardPageCustomTask.example.group")); //$NON-NLS-1$
       
   131 	Text exampleText = new Text(exampleGroup, SWT.NONE);
       
   132 	exampleText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
       
   133 	baseGroup = new Group(optionComposite, SWT.NONE);
       
   134 	GridLayout baseLayout = new GridLayout();
       
   135 	baseLayout.numColumns = 1;
       
   136 	baseLayout.verticalSpacing = 9;
       
   137 	baseGroup.setLayout(optionLayout);
       
   138 	baseGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
       
   139 	baseGroup.setText(Messages.getString("NewPIWizardPageCustomTask.base.group")); //$NON-NLS-1$
       
   140 	buttonValue = new Button(baseGroup, SWT.RADIO);
       
   141 	buttonValue.setText(Messages.getString("NewPIWizardPageCustomTask.button.value")); //$NON-NLS-1$
       
   142 	buttonName = new Button(baseGroup, SWT.RADIO);
       
   143 	buttonName.setText(Messages.getString("NewPIWizardPageCustomTask.button.name")); //$NON-NLS-1$
       
   144 	seperatorGroup = new Group(optionComposite, SWT.NONE);
       
   145 	GridLayout seperatorLayout = new GridLayout();
       
   146 	seperatorLayout.numColumns = 1;
       
   147 	seperatorLayout.verticalSpacing = 9;
       
   148 	seperatorGroup.setLayout(optionLayout);
       
   149 	seperatorGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
       
   150 	seperatorGroup.setText(Messages.getString("NewPIWizardPageCustomTask.seperator.group")); //$NON-NLS-1$
       
   151 	buttonSemicolon = new Button(seperatorGroup, SWT.RADIO);
       
   152 	buttonSemicolon.setText(Messages.getString("NewPIWizardPageCustomTask.button.semicolon")); //$NON-NLS-1$
       
   153 	buttonComma = new Button(seperatorGroup, SWT.RADIO);
       
   154 	buttonComma.setText(Messages.getString("NewPIWizardPageCustomTask.button.comma")); //$NON-NLS-1$
       
   155 	buttonSpace = new Button(seperatorGroup, SWT.RADIO);
       
   156 	buttonSpace.setText(Messages.getString("NewPIWizardPageCustomTask.button.space")); //$NON-NLS-1$
       
   157 	
       
   158 	// fake default for demo
       
   159 	sampleFileText.setText(Messages.getString("NewPIWizardPageCustomTask.13")); //$NON-NLS-1$
       
   160 	buttonValue.setSelection(true);
       
   161 	buttonName.setSelection(false);
       
   162 	buttonSemicolon.setSelection(true);
       
   163 	buttonComma.setSelection(false);
       
   164 	buttonSpace.setSelection(false);
       
   165 	exampleText.setText(Messages.getString("NewPIWizardPageCustomTask.14")); //$NON-NLS-1$
       
   166 	
       
   167 	
       
   168 	validatePage();
       
   169 	setControl(container);
       
   170 	PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), CarbidePiWizardHelpIds.PI_IMPORT_WIZARD_CUSTOM);
       
   171 }
       
   172 
       
   173 public void validatePage() {
       
   174 	if (sampleFileText.getText().length() == 0) {
       
   175 		updateStatus(Messages.getString("NewPIWizardCustomTask.dat.file.name.must.be.specified")); //$NON-NLS-1$
       
   176 		return;
       
   177 	}
       
   178 	int dotLoc = sampleFileText.getText().lastIndexOf('.');
       
   179 	if (dotLoc != -1) {
       
   180 		String ext = sampleFileText.getText().substring(dotLoc + 1);
       
   181 		if (ext.equalsIgnoreCase(DAT_EXTENSION) == false) {
       
   182 			updateStatus(Messages.getString("NewPIWizardPageSampleFile.dat.file.extension.must.be.dat")); //$NON-NLS-1$
       
   183 			return;
       
   184 		}
       
   185 	}
       
   186 
       
   187 
       
   188 	if (!(new File(sampleFileText.getText()).exists())) {
       
   189 		updateStatus(Messages.getString("NewPIWizardPageSampleFile.dat.file.name.does.not.exist")); //$NON-NLS-1$
       
   190 		return;
       
   191 	}
       
   192 	if (!(new File(sampleFileText.getText()).isFile())) {
       
   193 		updateStatus(Messages.getString("NewPIWizardPageSampleFile.dat.must.be.a.file")); //$NON-NLS-1$
       
   194 		return;		
       
   195 	}
       
   196 
       
   197 	updateStatus(null);
       
   198 }
       
   199 
       
   200 private void updateStatus(String message) {
       
   201 	// need to enable finish, setPageComplete eventually check global states
       
   202 	writePageDataToNewPIWizardSettings();
       
   203 	setErrorMessage(message);
       
   204 	setPageComplete(message == null);
       
   205 }
       
   206 	
       
   207 private void handleBrowse() {
       
   208 	FileDialog dialog = new FileDialog(getShell());
       
   209 	String[] datExtensions = {"*.dat", //$NON-NLS-1$
       
   210 //								"*.base64",
       
   211 								"*.*"}; //$NON-NLS-1$
       
   212 	String[] datNames = {Messages.getString("NewPIWizardPageSampleFile.sample.filter.name"), //$NON-NLS-1$
       
   213 //							"Profiler Sample Files (*.base64)",
       
   214 							Messages.getString("NewPIWizardPageSampleFile.all.filter.name")}; //$NON-NLS-1$
       
   215 	dialog.setFilterExtensions(datExtensions);
       
   216 	dialog.setFilterNames(datNames);
       
   217 	// Try guiding user to path user is trying to fill
       
   218 	File clueFile = new File(sampleFileText.getText());
       
   219 	String cluePath = null;
       
   220 	if (clueFile.isDirectory()) {
       
   221 		cluePath = clueFile.getAbsolutePath();
       
   222 	} else {
       
   223 		cluePath = clueFile.getParent();
       
   224 	}
       
   225 	if (cluePath != null) {
       
   226 		dialog.setFilterPath(cluePath);
       
   227 	}
       
   228 	String filePath = dialog.open();
       
   229 
       
   230 	if (filePath != null) {
       
   231 		if (filePath.length() > 0) {
       
   232 			sampleFileText.setText(filePath);
       
   233 		}
       
   234 	}		
       
   235 }
       
   236 
       
   237 public void writePageDataToNewPIWizardSettings() {
       
   238 }
       
   239 
       
   240 public void setupPageFromFromNewPIWizardSettings() {
       
   241 }
       
   242 }
       
   243