Search in sources :

Example 1 with URLPath

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;
}
Also used : Group(org.eclipse.swt.widgets.Group) ResourceSelectionGroup(org.csstudio.platform.ui.composites.resourcefilter.ResourceSelectionGroup) Composite(org.eclipse.swt.widgets.Composite) URLPath(org.csstudio.opibuilder.persistence.URLPath) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ResourceSelectionGroup(org.csstudio.platform.ui.composites.resourcefilter.ResourceSelectionGroup)

Example 2 with URLPath

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;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) URLPath(org.csstudio.opibuilder.persistence.URLPath) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Text(org.eclipse.swt.widgets.Text) ResourceSelectionGroup(org.csstudio.ui.util.composites.ResourceSelectionGroup)

Example 3 with URLPath

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;
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) URLPath(org.csstudio.opibuilder.persistence.URLPath) FileOutputStream(java.io.FileOutputStream) IFile(org.eclipse.core.resources.IFile) File(java.io.File) FileInputStream(java.io.FileInputStream) CoreException(org.eclipse.core.runtime.CoreException) KeyManagementException(java.security.KeyManagementException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException)

Example 4 with URLPath

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);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) URLPath(org.csstudio.opibuilder.persistence.URLPath) MacrosInput(org.csstudio.opibuilder.util.MacrosInput) IPath(org.eclipse.core.runtime.IPath) URLPath(org.csstudio.opibuilder.persistence.URLPath)

Aggregations

URLPath (org.csstudio.opibuilder.persistence.URLPath)4 IPath (org.eclipse.core.runtime.IPath)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Button (org.eclipse.swt.widgets.Button)2 Composite (org.eclipse.swt.widgets.Composite)2 Label (org.eclipse.swt.widgets.Label)2 Text (org.eclipse.swt.widgets.Text)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 KeyManagementException (java.security.KeyManagementException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 MacrosInput (org.csstudio.opibuilder.util.MacrosInput)1 ResourceSelectionGroup (org.csstudio.platform.ui.composites.resourcefilter.ResourceSelectionGroup)1