Commit aa96aa29 authored by Adam Knapp's avatar Adam Knapp
Browse files

Minor improvements: file extension filters for dialogs



Change-Id: I18e2757aa67d22c2dfd7f3fe2ee286c5f0ff62ca
Signed-off-by: default avatarAdam Knapp <adam.knapp@sigmatechnology.se>
parent 7a932cb4
......@@ -63,6 +63,9 @@ public class TITANResourceLocatorFieldEditor extends StringFieldEditor {
// an optional console that might be used to provide debug information.
private MessageConsole console = null;
private boolean enabled = true;
List<String> filterExtensions = null;
/**
* Creates a string button field editor.
*
......@@ -229,8 +232,7 @@ public class TITANResourceLocatorFieldEditor extends StringFieldEditor {
private void handleVariablesButtonPressed() {
int variableTypes = IResource.FOLDER;
// allow selecting file and folder variables when creating a
// linked file
// allow selecting file and folder variables when creating a linked file
if (type == IResource.FILE) {
variableTypes |= IResource.FILE;
}
......@@ -254,8 +256,9 @@ public class TITANResourceLocatorFieldEditor extends StringFieldEditor {
if (type == IResource.FILE) {
final FileDialog dialog = new FileDialog(getTextControl().getShell());
dialog.setText("Select the target file.");
dialog.setFilterExtensions(getFilterExtensions());
final IPath path = URIUtil.toPath(resolvedPath);
if ( "".equals(getStringValue()) ) {
if ( getStringValue().isBlank() ) {
dialog.setFilterPath(path.toOSString());
} else {
dialog.setFilterPath(path.removeLastSegments(1).toOSString());
......@@ -283,7 +286,7 @@ public class TITANResourceLocatorFieldEditor extends StringFieldEditor {
* the entered value is a variable.
*/
private void resolveVariable() {
if ("".equals(target)) {
if (target.isEmpty() || !isEnabled()) {
resolvedPathLabelText.setVisible(false);
return;
}
......@@ -298,7 +301,6 @@ public class TITANResourceLocatorFieldEditor extends StringFieldEditor {
}
resolvedPathLabelText.setText(message);
if (path.equals(resolvedPath)) {
resolvedPathLabelText.setVisible(false);
} else {
......@@ -340,4 +342,51 @@ public class TITANResourceLocatorFieldEditor extends StringFieldEditor {
return true;
}
@Override
public void setEnabled(boolean enabled, Composite parent) {
this.enabled = enabled;
resolvedPathLabelText.setVisible(enabled);
pathButton.setEnabled(enabled);
envButton.setEnabled(enabled);
browseButton.setEnabled(enabled);
super.setEnabled(enabled, parent);
}
/**
* Returns whether or not the controls in the field editor are enabled.
* @return The enabled state.
*/
public boolean isEnabled() {
return enabled;
}
/**
* Returns the file extensions which the dialog will use to filter the files it shows.
* It is used by the dialog of browse button.
* @return The file extensions filter
* @see org.eclipse.swt.widgets.FileDialog#getFilterExtensions()
*/
public String[] getFilterExtensions() {
return filterExtensions == null ? null : filterExtensions.toArray(new String[filterExtensions.size()]);
}
/**
* Set the file extensions which the dialog will use to filter the files it shows to the argument.
* @param extensions The file extension filter
* @see org.eclipse.swt.widgets.FileDialog#setFilterExtensions
*/
public void setFilterExtensions(String[] extensions) {
if (extensions == null || extensions.length == 0) {
return;
}
if (filterExtensions == null) {
filterExtensions = new ArrayList<String>(extensions.length);
} else {
filterExtensions.clear();
}
for (int i = 0; i < extensions.length; i++) {
filterExtensions.add(extensions[i]);
}
}
}
......@@ -197,6 +197,10 @@ public final class MakefileCreationTab {
+ "This field is optional.\n"
+ " If it is not set, the executable will be generated into the working directory, with the name of the project.");
temporalTargetExecutableFileFieldEditor.setPage(page);
if (Platform.OS_WIN32.equals(Platform.getOS())) {
final String[] extensions = new String[] {"*.exe", "*.*"};
temporalTargetExecutableFileFieldEditor.setFilterExtensions(extensions);
}
creationAttributesTabItem.setControl(automaticBuildPropertiesComposite);
return creationAttributesTabItem;
......
......@@ -31,6 +31,7 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
......@@ -91,14 +92,14 @@ public abstract class BaseMainControllerTab extends AbstractLaunchConfigurationT
private static final String WORKING_DIR_TOOLTIP = "The directory the main controller should be started from.";
private static final String EXECUTABLE = " Executable:";
private static final String EXECUTABLE_TOOLTIP =
"This field is required.\nThe executable file used to make the creation and validation of testsets possible.";
"This field is required.\nThe executable file is used to make the creation and validation of testsets possible.";
private static final String EXECUTABLE_REQUIRED = "Executable (REQUIRED):";
private static final String EXECUTABLE_NOT_REQUIRED = "Executable:";
private static final String EXECUTABLE_REQUIRED_TOOLTIP =
"The executable file used to execute testcases and to make the creation and validation of testsets possible.";
"The executable file is used to execute testcases and to make the creation and validation of testsets possible.";
private static final String CONFIGFILE = " Configuration file:";
private static final String CONFIGFILE_TOOLTIP = "This field is required.\n" +
"The runtime configuration file used to describe the runtime behaviour of the executable test program.";
"The runtime configuration file is used to describe the runtime behaviour of the executable test program.";
private static final String CONFIGFILE_REQUIRED = "Configuration file (REQUIRED):";
private static final String BROWSE_WORKSPACE = "Browse Workspace..";
......@@ -338,6 +339,10 @@ public abstract class BaseMainControllerTab extends AbstractLaunchConfigurationT
executableFileText = new TITANResourceLocator(EXECUTABLE, executableGroup, IResource.FILE, getProject().getLocation().toOSString());
}
executableFileText.getLabelControl(executableGroup).setToolTipText(EXECUTABLE_TOOLTIP);
if (Platform.OS_WIN32.equals(Platform.getOS())) {
final String[] extensions = new String[] {"*.exe", "*.*"};
executableFileText.setFilterExtensions(extensions);
}
}
protected final void createConfigurationEditor(final Composite parent) {
......@@ -359,6 +364,8 @@ public abstract class BaseMainControllerTab extends AbstractLaunchConfigurationT
configurationFileText = new TITANResourceLocator(CONFIGFILE, configFileGroup, IResource.FILE, getProject().getLocation().toOSString());
}
configurationFileText.getLabelControl(configFileGroup).setToolTipText(CONFIGFILE_TOOLTIP);
final String[] extensions = new String[] {"*.cfg", "*.*"};
configurationFileText.setFilterExtensions(extensions);
automaticExecuteSectionExecution = new Button(configFileGroup, SWT.CHECK);
automaticExecuteSectionExecution.setText("Execute automatically");
......
......@@ -297,6 +297,8 @@ public class NativeJavaMainControllerTab extends AbstractLaunchConfigurationTab
configurationFileText = new TITANResourceLocator(CONFIGFILE, configFileGroup, IResource.FILE, getProject().getLocation().toOSString());
}
configurationFileText.getLabelControl(configFileGroup).setToolTipText(CONFIGFILE_TOOLTIP);
final String[] extensions = new String[] {"*.cfg", "*.*"};
configurationFileText.setFilterExtensions(extensions);
automaticExecuteSectionExecution = new Button(configFileGroup, SWT.CHECK);
automaticExecuteSectionExecution.setText("Execute automatically");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment