use of org.csstudio.opibuilder.persistence.URLPath in project yamcs-studio by yamcs.
the class FilePathDialogWithFilter method createDialogArea.
/**
* {@inheritDoc}
*/
@Override
protected Control createDialogArea(final Composite parent) {
Composite composite = (Composite) super.createDialogArea(parent);
composite.setLayout(new GridLayout(1, false));
if (message != null) {
Label label = new Label(composite, SWT.WRAP);
label.setText(message);
GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
data.horizontalSpan = 2;
data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
label.setLayoutData(data);
}
// The New Project and New Folder actions will be shown if there are
// no file extensions, i.e. if the dialog is opened to select a folder.
boolean showNewContainerActions = (filters == null || filters.length == 0);
resourceSelectionGroup = new ResourceSelectionGroup(composite, this, filters, showNewContainerActions);
Group wrapper = new Group(composite, SWT.NONE);
wrapper.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
GridLayout gridLayout = new GridLayout(2, false);
wrapper.setLayout(gridLayout);
Label text = new Label(wrapper, SWT.NONE);
text.setText("Resource Path:");
// Image overview
imgOverview = new Label(wrapper, SWT.NONE);
GridData gridData = new GridData();
gridData.widthHint = MAX_ICON_WIDTH;
gridData.verticalSpan = 4;
gridData.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER;
gridData.grabExcessVerticalSpace = false;
gridData.horizontalAlignment = GridData.HORIZONTAL_ALIGN_CENTER;
gridData.grabExcessHorizontalSpace = false;
imgOverview.setLayoutData(gridData);
resourcePathText = new Text(wrapper, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
resourcePathText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
if (path != null && !path.isEmpty()) {
resourcePathText.setText(path.toString());
if (!(path instanceof URLPath)) {
if (relative) {
resourceSelectionGroup.setSelectedResource(refPath.append(path));
} else {
resourceSelectionGroup.setSelectedResource(path);
}
}
}
// the check box for relative path
final Button checkBox = new Button(wrapper, SWT.CHECK);
checkBox.setSelection(relative);
checkBox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
checkBox.setText("Return relative path");
checkBox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
relative = checkBox.getSelection();
if (relative && path != null) {
resourcePathText.setText(ResourceUtil.buildRelativePath(refPath, path).toString());
} else {
resourcePathText.setText(path.toString());
}
}
});
// the check box for name filter
final Button filterCheckBox = new Button(wrapper, SWT.CHECK);
filterCheckBox.setSelection(filtered);
filterCheckBox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
filterCheckBox.setText("Filter file name with PV name");
filterCheckBox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
filtered = filterCheckBox.getSelection();
if (filtered) {
resourceSelectionGroup.refreshTreeWithFilter(filters);
} else {
resourceSelectionGroup.refreshTreeWithFilter(IMAGE_EXTENSIONS);
}
}
});
return composite;
}
use of org.csstudio.opibuilder.persistence.URLPath in project yamcs-studio by yamcs.
the class RelativePathSelectionDialog method createDialogArea.
/**
* {@inheritDoc}
*/
@Override
protected Control createDialogArea(final Composite parent) {
Composite composite = (Composite) super.createDialogArea(parent);
composite.setLayout(new GridLayout(1, false));
if (_message != null) {
Label label = new Label(composite, SWT.WRAP);
label.setText(_message);
GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
data.horizontalSpan = 2;
data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
label.setLayoutData(data);
}
// The New Project and New Folder actions will be shown if there are
// no file extensions, i.e. if the dialog is opened to select a folder.
boolean showNewContainerActions = (_fileExtensions == null || _fileExtensions.length == 0);
_resourceSelectionGroup = new ResourceSelectionGroup(composite, this, _fileExtensions, showNewContainerActions);
new Label(composite, SWT.NONE).setText("Resource Path:");
_resourcePathText = new Text(composite, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
_resourcePathText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
if (_path != null && !_path.isEmpty()) {
_resourcePathText.setText(_path.toString());
if (!(_path instanceof URLPath)) {
if (relative)
_resourceSelectionGroup.setSelectedResource(refPath.append(_path));
else
_resourceSelectionGroup.setSelectedResource(_path);
}
}
// the check box for relative path
final Button checkBox = new Button(composite, SWT.CHECK);
checkBox.setSelection(relative);
checkBox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
checkBox.setText("Return relative path");
checkBox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
relative = checkBox.getSelection();
if (relative)
_resourcePathText.setText(ResourceUtil.buildRelativePath(refPath, _path).toString());
else
_resourcePathText.setText(_path.toString());
}
});
return composite;
}
use of org.csstudio.opibuilder.persistence.URLPath in project yamcs-studio by yamcs.
the class ResourceUtil method openURLStream.
private static InputStream openURLStream(final URL url) throws IOException {
File tempFilePath = URL_CACHE.getValue(url);
if (tempFilePath != null) {
OPIBuilderPlugin.getLogger().log(Level.FINE, "Found cached file for URL '" + url + "'");
return new FileInputStream(tempFilePath);
} else {
InputStream inputStream = openRawURLStream(url);
if (inputStream != null) {
try {
IPath urlPath = new URLPath(url.toString());
// createTempFile(), at least with jdk1.7.0_45,
// requires at least 3 chars for the 'prefix', so add "opicache"
// to assert a minimum length
final String cache_file_prefix = "opicache" + urlPath.removeFileExtension().lastSegment();
final String cache_file_suffix = "." + urlPath.getFileExtension();
final File file = File.createTempFile(cache_file_prefix, cache_file_suffix);
file.deleteOnExit();
if (!file.canWrite())
throw new Exception("Unable to write temporary file.");
FileOutputStream outputStream = new FileOutputStream(file);
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
outputStream.close();
URL_CACHE.remember(url, file);
inputStream.close();
ExecutionService.getInstance().getScheduledExecutorService().schedule(new Runnable() {
@Override
public void run() {
file.delete();
}
}, CACHE_TIMEOUT_SECONDS * 2, TimeUnit.SECONDS);
return new FileInputStream(file);
} catch (Exception e) {
OPIBuilderPlugin.getLogger().log(Level.WARNING, "Error to cache file from URL '" + url + "'", e);
}
}
return inputStream;
}
}
use of org.csstudio.opibuilder.persistence.URLPath in project yamcs-studio by yamcs.
the class RunnerInputFactory method createInput.
public static IAdaptable createInput(IMemento memento) {
// Get the file name.
String pathString = memento.getString(TAG_PATH);
if (pathString == null) {
return null;
}
// Get a handle to the IFile...which can be a handle
// to a resource that does not exist in workspace
IPath path;
if (ResourceUtil.isURL(pathString))
path = new URLPath(pathString);
else
path = new Path(pathString);
MacrosInput macrosInput = null;
String macroString = memento.getString(TAG_MACRO);
if (macroString != null)
try {
macrosInput = MacrosInput.recoverFromString(macroString);
} catch (Exception e) {
OPIBuilderPlugin.getLogger().log(Level.WARNING, "Failed to recover macro", // $NON-NLS-1$
e);
}
return new RunnerInput(path, null, macrosInput);
}
Aggregations