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
.internal
.lttng
.ui
.project
.dialogs
;
17 import org
.eclipse
.core
.resources
.IProject
;
18 import org
.eclipse
.core
.resources
.IResource
;
19 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.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
.graphics
.Font
;
26 import org
.eclipse
.swt
.layout
.GridData
;
27 import org
.eclipse
.swt
.layout
.GridLayout
;
28 import org
.eclipse
.swt
.widgets
.Button
;
29 import org
.eclipse
.swt
.widgets
.Composite
;
30 import org
.eclipse
.swt
.widgets
.Control
;
31 import org
.eclipse
.swt
.widgets
.DirectoryDialog
;
32 import org
.eclipse
.swt
.widgets
.Display
;
33 import org
.eclipse
.swt
.widgets
.Label
;
34 import org
.eclipse
.swt
.widgets
.Text
;
35 import org
.eclipse
.ui
.dialogs
.PropertyPage
;
37 public class TraceLibraryPathPropertyPage
extends PropertyPage
{
39 private static final String LTTVTRACEREAD_LOADER_LIBNAME
= "lttvtraceread_loader"; //$NON-NLS-1$
40 private Button browsePathButton
;
41 private Text traceLibraryPath
;
44 protected Control
createContents(Composite parent
) {
45 Composite client
= new Composite(parent
, SWT
.NONE
);
46 client
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
48 GridLayout layout
= new GridLayout(3, false);
49 layout
.marginHeight
= 0;
50 layout
.marginWidth
= 0;
51 client
.setLayout(layout
);
53 Label label
= new Label(client
, SWT
.NONE
);
54 label
.setText(Messages
.TraceLibraryPath_label
);
55 traceLibraryPath
= new Text(client
, SWT
.BORDER
);
56 traceLibraryPath
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true,
58 traceLibraryPath
.addModifyListener(new ModifyListener() {
61 public void modifyText(ModifyEvent e
) {
62 setValid(validateInputs());
66 browsePathButton
= new Button(client
, SWT
.PUSH
);
67 browsePathButton
.setLayoutData(new GridData(SWT
.END
, SWT
.CENTER
, false,
69 browsePathButton
.setText(Messages
.TraceLibraryPath_browseBtn
);
70 browsePathButton
.addSelectionListener(new SelectionAdapter() {
73 public void widgetSelected(SelectionEvent e
) {
74 String dir
= new DirectoryDialog(Display
.getDefault()
75 .getActiveShell()).open();
77 traceLibraryPath
.setText(dir
);
84 Label noLabel
= new Label(client
, SWT
.NONE
);
85 noLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.TOP
, false, false));
87 Label descTextLabel
= new Label(client
, SWT
.WRAP
);
88 descTextLabel
.setText(Messages
.TraceLibraryPathProperty_Message
);
89 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
91 gd
.horizontalSpan
= 2;
92 descTextLabel
.setLayoutData(gd
);
94 Label noteBoldLabel
= new Label(client
, SWT
.BOLD
);
95 noteBoldLabel
.setText(Messages
.TraceLibraryPath_Note
);
96 noteBoldLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.TOP
, false,
98 Font font
= noteBoldLabel
.getFont();
99 if (font
.getFontData().length
> 0)
100 noteBoldLabel
.setFont(new Font(client
.getDisplay(), font
101 .getFontData()[0].getName(), font
.getFontData()[0]
102 .getHeight(), SWT
.BOLD
));
104 Label noteTextLabel
= new Label(client
, SWT
.WRAP
);
105 noteTextLabel
.setText(Messages
.TraceLibraryPath_Message
);
106 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
108 gd
.horizontalSpan
= 2;
109 noteTextLabel
.setLayoutData(gd
);
115 public boolean validateInputs() {
116 String path
= traceLibraryPath
.getText();
117 if (path
!= null && !path
.trim().isEmpty()) {
118 File file
= new File(path
);
119 if (file
.exists() && file
.isDirectory()) {
120 File loaderLib
= new File(path
,
121 System
.mapLibraryName(LTTVTRACEREAD_LOADER_LIBNAME
));
122 if (!loaderLib
.exists()) {
123 setErrorMessage(Messages
.TraceLibraryPathWizardPage_TraceLoaderLibrary_notExists
);
127 setErrorMessage(Messages
.TraceLibraryPathWizardPage_SpecifiedTraceLibraryLocation_notExists
);
131 setErrorMessage(null);
136 protected void performDefaults() {
137 IResource resource
= (IResource
) getElement().getAdapter(
139 IProject project
= resource
.getProject();
140 if (project
!= null) {
141 String traceLibDir
= TraceHelper
.getTraceLibDirFromProject(project
);
142 if (traceLibDir
!= null) {
143 traceLibraryPath
.setText(traceLibDir
);
146 super.performDefaults();
150 public boolean performOk() {
151 IResource resource
= (IResource
) getElement().getAdapter(
153 IProject project
= resource
.getProject();
155 if (project
!= null) {
156 String libPath
= traceLibraryPath
.getText();
157 if (libPath
== null || libPath
.trim().isEmpty())
158 ok
= TraceHelper
.removeProjectPreference(project
, "traceLibraryPath"); //$NON-NLS-1$
160 ok
= TraceHelper
.setProjectPreference(project
, "traceLibraryPath", traceLibraryPath
.getText()); //$NON-NLS-1$
162 return ok
&& super.performOk();