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 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.lttng
.ui
.views
.project
.dialogs
;
17 import org
.eclipse
.core
.resources
.IProject
;
18 import org
.eclipse
.core
.resources
.IResource
;
19 import org
.eclipse
.linuxtools
.lttng
.ui
.TraceHelper
;
20 import org
.eclipse
.swt
.SWT
;
21 import org
.eclipse
.swt
.events
.ModifyEvent
;
22 import org
.eclipse
.swt
.events
.ModifyListener
;
23 import org
.eclipse
.swt
.events
.SelectionAdapter
;
24 import org
.eclipse
.swt
.events
.SelectionEvent
;
25 import org
.eclipse
.swt
.layout
.GridData
;
26 import org
.eclipse
.swt
.layout
.GridLayout
;
27 import org
.eclipse
.swt
.widgets
.Button
;
28 import org
.eclipse
.swt
.widgets
.Composite
;
29 import org
.eclipse
.swt
.widgets
.Control
;
30 import org
.eclipse
.swt
.widgets
.DirectoryDialog
;
31 import org
.eclipse
.swt
.widgets
.Display
;
32 import org
.eclipse
.swt
.widgets
.Label
;
33 import org
.eclipse
.swt
.widgets
.Text
;
34 import org
.eclipse
.ui
.dialogs
.PropertyPage
;
36 public class TraceLibraryPathPropertyPage
extends PropertyPage
{
38 private static final String LTTVTRACEREAD_LOADER_LIBNAME
= "lttvtraceread_loader";
39 private Button browsePathButton
;
40 private Text traceLibraryPath
;
43 protected Control
createContents(Composite parent
) {
44 Composite client
= new Composite(parent
, SWT
.NONE
);
45 client
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
47 GridLayout layout
= new GridLayout(3, false);
48 layout
.marginHeight
= 0;
49 layout
.marginWidth
= 0;
50 client
.setLayout(layout
);
52 Label label
= new Label(client
, SWT
.NONE
);
53 label
.setText(Messages
.TraceLibraryPath_label
);
54 traceLibraryPath
= new Text(client
, SWT
.BORDER
);
55 traceLibraryPath
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true,
57 traceLibraryPath
.addModifyListener(new ModifyListener() {
60 public void modifyText(ModifyEvent e
) {
61 setValid(validateInputs());
65 browsePathButton
= new Button(client
, SWT
.PUSH
);
66 browsePathButton
.setLayoutData(new GridData(SWT
.END
, SWT
.CENTER
, false,
68 browsePathButton
.setText(Messages
.TraceLibraryPath_browseBtn
);
69 browsePathButton
.addSelectionListener(new SelectionAdapter() {
72 public void widgetSelected(SelectionEvent e
) {
73 String dir
= new DirectoryDialog(Display
.getDefault()
74 .getActiveShell()).open();
76 traceLibraryPath
.setText(dir
);
86 public boolean validateInputs() {
87 String path
= traceLibraryPath
.getText();
88 if (path
!= null && !path
.trim().isEmpty()) {
89 File file
= new File(path
);
90 if (file
.exists() && file
.isDirectory()) {
91 File loaderLib
= new File(path
,
92 System
.mapLibraryName(LTTVTRACEREAD_LOADER_LIBNAME
));
93 if (!loaderLib
.exists()) {
94 setErrorMessage(Messages
.TraceLibraryPathWizardPage_TraceLoaderLibrary_notExists
);
98 setErrorMessage(Messages
.TraceLibraryPathWizardPage_SpecifiedTraceLibraryLocation_notExists
);
102 setErrorMessage(null);
107 protected void performDefaults() {
108 IResource resource
= (IResource
) getElement().getAdapter(
110 IProject project
= resource
.getProject();
111 if (project
!= null) {
112 String traceLibDir
= TraceHelper
.getTraceLibDirFromProject(project
);
113 if (traceLibDir
!= null) {
114 traceLibraryPath
.setText(traceLibDir
);
117 super.performDefaults();
121 public boolean performOk() {
122 IResource resource
= (IResource
) getElement().getAdapter(
124 IProject project
= resource
.getProject();
126 if (project
!= null) {
127 String libPath
= traceLibraryPath
.getText();
128 if (libPath
== null || libPath
.trim().isEmpty())
129 ok
= TraceHelper
.removeProjectPreference(project
,
132 ok
= TraceHelper
.setProjectPreference(project
,
133 "traceLibraryPath", traceLibraryPath
.getText());
135 return ok
&& super.performOk();