Internalize lttng.ui APIs
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / internal / lttng / ui / project / dialogs / TraceLibraryPathWizardPage.java
1 /*******************************************************************************
2 * Copyright (c) 2011 MontaVista Software
3 *
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
8 *
9 * Contributors:
10 * Yufen Kuo (ykuo@mvista.com) - Initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.linuxtools.internal.lttng.ui.project.dialogs;
13
14 import java.io.File;
15
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;
31
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;
36
37 protected TraceLibraryPathWizardPage(String pageName) {
38 super(pageName);
39 }
40
41 @Override
42 public void createControl(Composite parent) {
43 Composite client = new Composite(parent, SWT.NONE);
44 client.setLayoutData(new GridData(GridData.FILL_BOTH));
45
46 GridLayout layout = new GridLayout(3, false);
47 layout.marginHeight = 0;
48 layout.marginWidth = 0;
49 client.setLayout(layout);
50
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() {
56
57 @Override
58 public void modifyText(ModifyEvent e) {
59 boolean valid = validatePage();
60 setPageComplete(valid);
61 }
62
63 });
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() {
68
69 @Override
70 public void widgetSelected(SelectionEvent e) {
71 String dir = new DirectoryDialog(Display.getDefault()
72 .getActiveShell()).open();
73 if (dir != null) {
74 traceLibraryPath.setText(dir);
75 }
76
77 }
78
79 });
80
81 Label noLabel = new Label(client, SWT.NONE);
82 noLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false));
83
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);
87 gd.widthHint = 400;
88 gd.horizontalSpan = 2;
89 descTextLabel.setLayoutData(gd);
90
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));
99
100 Label noteTextLabel = new Label(client, SWT.WRAP);
101 noteTextLabel.setText(Messages.TraceLibraryPath_Message);
102 gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
103 gd.widthHint = 400;
104 gd.horizontalSpan = 2;
105 noteTextLabel.setLayoutData(gd);
106 setControl(client);
107
108 }
109
110 public String getPath() {
111 if (traceLibraryPath != null && !traceLibraryPath.isDisposed()) {
112 String path = traceLibraryPath.getText();
113 if (path != null && !path.trim().isEmpty())
114 return path;
115 }
116 return null;
117 }
118
119 private boolean validatePage() {
120 String path = getPath();
121 if (path != null) {
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);
128 return false;
129 }
130 } else {
131 setErrorMessage(Messages.TraceLibraryPathWizardPage_SpecifiedTraceLibraryLocation_notExists);
132 return false;
133 }
134 }
135 setErrorMessage(null);
136 return true;
137
138 }
139
140 }
This page took 0.037633 seconds and 5 git commands to generate.