Fix for Bug354541 - TraceLibPath handling + JUnits
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / project / dialogs / TraceLibraryPathPropertyPage.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
13 package org.eclipse.linuxtools.lttng.ui.views.project.dialogs;
14
15 import java.io.File;
16
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;
35
36 public class TraceLibraryPathPropertyPage extends PropertyPage {
37
38 private static final String LTTVTRACEREAD_LOADER_LIBNAME = "lttvtraceread_loader";
39 private Button browsePathButton;
40 private Text traceLibraryPath;
41
42 @Override
43 protected Control createContents(Composite parent) {
44 Composite client = new Composite(parent, SWT.NONE);
45 client.setLayoutData(new GridData(GridData.FILL_BOTH));
46
47 GridLayout layout = new GridLayout(3, false);
48 layout.marginHeight = 0;
49 layout.marginWidth = 0;
50 client.setLayout(layout);
51
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,
56 false));
57 traceLibraryPath.addModifyListener(new ModifyListener() {
58
59 @Override
60 public void modifyText(ModifyEvent e) {
61 setValid(validateInputs());
62 }
63
64 });
65 browsePathButton = new Button(client, SWT.PUSH);
66 browsePathButton.setLayoutData(new GridData(SWT.END, SWT.CENTER, false,
67 false));
68 browsePathButton.setText(Messages.TraceLibraryPath_browseBtn);
69 browsePathButton.addSelectionListener(new SelectionAdapter() {
70
71 @Override
72 public void widgetSelected(SelectionEvent e) {
73 String dir = new DirectoryDialog(Display.getDefault()
74 .getActiveShell()).open();
75 if (dir != null) {
76 traceLibraryPath.setText(dir);
77 }
78
79 }
80
81 });
82 performDefaults();
83 return client;
84 }
85
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);
95 return false;
96 }
97 } else {
98 setErrorMessage(Messages.TraceLibraryPathWizardPage_SpecifiedTraceLibraryLocation_notExists);
99 return false;
100 }
101 }
102 setErrorMessage(null);
103 return true;
104 }
105
106 @Override
107 protected void performDefaults() {
108 IResource resource = (IResource) getElement().getAdapter(
109 IResource.class);
110 IProject project = resource.getProject();
111 if (project != null) {
112 String traceLibDir = TraceHelper.getTraceLibDirFromProject(project);
113 if (traceLibDir != null) {
114 traceLibraryPath.setText(traceLibDir);
115 }
116 }
117 super.performDefaults();
118 }
119
120 @Override
121 public boolean performOk() {
122 IResource resource = (IResource) getElement().getAdapter(
123 IResource.class);
124 IProject project = resource.getProject();
125 boolean ok = false;
126 if (project != null) {
127 String libPath = traceLibraryPath.getText();
128 if (libPath == null || libPath.trim().isEmpty())
129 ok = TraceHelper.removeProjectPreference(project,
130 "traceLibraryPath");
131 else
132 ok = TraceHelper.setProjectPreference(project,
133 "traceLibraryPath", traceLibraryPath.getText());
134 }
135 return ok && super.performOk();
136 }
137
138 }
This page took 0.035366 seconds and 6 git commands to generate.