1 /*******************************************************************************
2 * Copyright (c) 2011 MontaVista Software
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Yufen Kuo (ykuo@mvista.com) - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.internal
.lttng
.ui
.project
.dialogs
;
16 import org
.eclipse
.jface
.wizard
.WizardPage
;
17 import org
.eclipse
.swt
.SWT
;
18 import org
.eclipse
.swt
.events
.ModifyEvent
;
19 import org
.eclipse
.swt
.events
.ModifyListener
;
20 import org
.eclipse
.swt
.events
.SelectionAdapter
;
21 import org
.eclipse
.swt
.events
.SelectionEvent
;
22 import org
.eclipse
.swt
.graphics
.Font
;
23 import org
.eclipse
.swt
.layout
.GridData
;
24 import org
.eclipse
.swt
.layout
.GridLayout
;
25 import org
.eclipse
.swt
.widgets
.Button
;
26 import org
.eclipse
.swt
.widgets
.Composite
;
27 import org
.eclipse
.swt
.widgets
.DirectoryDialog
;
28 import org
.eclipse
.swt
.widgets
.Display
;
29 import org
.eclipse
.swt
.widgets
.Label
;
30 import org
.eclipse
.swt
.widgets
.Text
;
32 public class TraceLibraryPathWizardPage
extends WizardPage
{
33 private static final String LTTVTRACEREAD_LOADER_LIBNAME
= "lttvtraceread_loader"; //$NON-NLS-1$
34 private Button browsePathButton
;
35 private Text traceLibraryPath
;
37 protected TraceLibraryPathWizardPage(String pageName
) {
42 public void createControl(Composite parent
) {
43 Composite client
= new Composite(parent
, SWT
.NONE
);
44 client
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
46 GridLayout layout
= new GridLayout(3, false);
47 layout
.marginHeight
= 0;
48 layout
.marginWidth
= 0;
49 client
.setLayout(layout
);
51 Label label
= new Label(client
, SWT
.NONE
);
52 label
.setText(Messages
.TraceLibraryPath_label
);
53 traceLibraryPath
= new Text(client
, SWT
.BORDER
);
54 traceLibraryPath
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
55 traceLibraryPath
.addModifyListener(new ModifyListener() {
58 public void modifyText(ModifyEvent e
) {
59 boolean valid
= validatePage();
60 setPageComplete(valid
);
64 browsePathButton
= new Button(client
, SWT
.PUSH
);
65 browsePathButton
.setLayoutData(new GridData(SWT
.END
, SWT
.CENTER
, false, false));
66 browsePathButton
.setText(Messages
.TraceLibraryPath_browseBtn
);
67 browsePathButton
.addSelectionListener(new SelectionAdapter() {
70 public void widgetSelected(SelectionEvent e
) {
71 String dir
= new DirectoryDialog(Display
.getDefault()
72 .getActiveShell()).open();
74 traceLibraryPath
.setText(dir
);
81 Label noLabel
= new Label(client
, SWT
.NONE
);
82 noLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.TOP
, false, false));
84 Label descTextLabel
= new Label(client
, SWT
.WRAP
);
85 descTextLabel
.setText(Messages
.TraceLibraryPathWizard_Message
);
86 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
88 gd
.horizontalSpan
= 2;
89 descTextLabel
.setLayoutData(gd
);
91 Label noteBoldLabel
= new Label(client
, SWT
.BOLD
);
92 noteBoldLabel
.setText(Messages
.TraceLibraryPath_Note
);
93 noteBoldLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.TOP
, false, false));
94 Font font
= noteBoldLabel
.getFont();
95 if (font
.getFontData().length
> 0)
96 noteBoldLabel
.setFont(new Font(client
.getDisplay(), font
97 .getFontData()[0].getName(), font
.getFontData()[0]
98 .getHeight(), SWT
.BOLD
));
100 Label noteTextLabel
= new Label(client
, SWT
.WRAP
);
101 noteTextLabel
.setText(Messages
.TraceLibraryPath_Message
);
102 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
104 gd
.horizontalSpan
= 2;
105 noteTextLabel
.setLayoutData(gd
);
110 public String
getPath() {
111 if (traceLibraryPath
!= null && !traceLibraryPath
.isDisposed()) {
112 String path
= traceLibraryPath
.getText();
113 if (path
!= null && !path
.trim().isEmpty())
119 private boolean validatePage() {
120 String path
= getPath();
122 File file
= new File(path
);
123 if (file
.exists() && file
.isDirectory()) {
124 File loaderLib
= new File(path
,
125 System
.mapLibraryName(LTTVTRACEREAD_LOADER_LIBNAME
));
126 if (!loaderLib
.exists()) {
127 setErrorMessage(Messages
.TraceLibraryPathWizardPage_TraceLoaderLibrary_notExists
);
131 setErrorMessage(Messages
.TraceLibraryPathWizardPage_SpecifiedTraceLibraryLocation_notExists
);
135 setErrorMessage(null);