Search in sources :

Example 6 with NLS

use of org.eclipse.osgi.util.NLS in project rt.equinox.framework by eclipse.

the class ServiceFactoryUse method getService.

/**
 * Get a service's service object and increment the use count.
 *
 * <p>The following steps are followed to get the service object:
 * <ol>
 * <li>The use count is incremented by one.
 * <li>If the use count is now one,
 * the {@link ServiceFactory#getService(Bundle, ServiceRegistration)} method
 * is called to create a service object for the context bundle.
 * This service object is cached.
 * While the use count is greater than zero,
 * subsequent calls to get the service object
 * will return the cached service object.
 * <br>If the service object returned by the {@link ServiceFactory}
 * is not an <code>instanceof</code>
 * all the classes named when the service was registered or
 * the {@link ServiceFactory} throws an exception,
 * <code>null</code> is returned and a
 * {@link FrameworkEvent} of type {@link FrameworkEvent#ERROR} is broadcast.
 * <li>The service object is returned.
 * </ol>
 *
 * @return The service object.
 */
/* @GuardedBy("this") */
@Override
S getService() {
    assert Thread.holdsLock(this);
    if (inUse()) {
        incrementUse();
        return cachedService;
    }
    if (debug.DEBUG_SERVICES) {
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        Debug.println("getService[factory=" + registration.getBundle() + "](" + context.getBundleImpl() + "," + registration + ")");
    }
    // check for recursive call on this thread
    if (factoryInUse) {
        if (debug.DEBUG_SERVICES) {
            // $NON-NLS-1$
            Debug.println(factory + ".getService() recursively called.");
        }
        // $NON-NLS-1$
        ServiceException se = new ServiceException(NLS.bind(Msg.SERVICE_FACTORY_RECURSION, factory.getClass().getName(), "getService"), ServiceException.FACTORY_RECURSION);
        context.getContainer().getEventPublisher().publishFrameworkEvent(FrameworkEvent.WARNING, registration.getBundle(), se);
        return null;
    }
    factoryInUse = true;
    final S service;
    try {
        service = factoryGetService();
        if (service == null) {
            return null;
        }
    } finally {
        factoryInUse = false;
    }
    this.cachedService = service;
    incrementUse();
    return service;
}
Also used : NLS(org.eclipse.osgi.util.NLS)

Example 7 with NLS

use of org.eclipse.osgi.util.NLS in project rt.equinox.framework by eclipse.

the class ServiceFactoryUse method factoryGetService.

/**
 *  Call the service factory to get the service.
 *
 * @return The service returned by the factory or null if there was an error.
 */
/* @GuardedBy("this") */
S factoryGetService() {
    final S service;
    try {
        service = AccessController.doPrivileged(new PrivilegedAction<S>() {

            public S run() {
                return factory.getService(context.getBundleImpl(), registration);
            }
        });
    } catch (Throwable t) {
        if (debug.DEBUG_SERVICES) {
            // $NON-NLS-1$
            Debug.println(factory + ".getService() exception: " + t.getMessage());
            Debug.printStackTrace(t);
        }
        // allow the adaptor to handle this unexpected error
        context.getContainer().handleRuntimeError(t);
        // $NON-NLS-1$
        ServiceException se = new ServiceException(NLS.bind(Msg.SERVICE_FACTORY_EXCEPTION, factory.getClass().getName(), "getService"), ServiceException.FACTORY_EXCEPTION, t);
        context.getContainer().getEventPublisher().publishFrameworkEvent(FrameworkEvent.ERROR, registration.getBundle(), se);
        return null;
    }
    if (service == null) {
        if (debug.DEBUG_SERVICES) {
            // $NON-NLS-1$
            Debug.println(factory + ".getService() returned null.");
        }
        ServiceException se = new ServiceException(NLS.bind(Msg.SERVICE_OBJECT_NULL_EXCEPTION, factory.getClass().getName()), ServiceException.FACTORY_ERROR);
        context.getContainer().getEventPublisher().publishFrameworkEvent(FrameworkEvent.WARNING, registration.getBundle(), se);
        return null;
    }
    String[] clazzes = registration.getClasses();
    String invalidService = ServiceRegistry.checkServiceClass(clazzes, service);
    if (invalidService != null) {
        if (debug.DEBUG_SERVICES) {
            // $NON-NLS-1$
            Debug.println("Service object is not an instanceof " + invalidService);
        }
        ServiceException se = new ServiceException(NLS.bind(Msg.SERVICE_FACTORY_NOT_INSTANCEOF_CLASS_EXCEPTION, factory.getClass().getName(), invalidService), ServiceException.FACTORY_ERROR);
        context.getContainer().getEventPublisher().publishFrameworkEvent(FrameworkEvent.ERROR, registration.getBundle(), se);
        return null;
    }
    return service;
}
Also used : NLS(org.eclipse.osgi.util.NLS) PrivilegedAction(java.security.PrivilegedAction)

Example 8 with NLS

use of org.eclipse.osgi.util.NLS in project linuxtools by eclipse.

the class OpenGCDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    this.getShell().setText(Messages.OpenGCDialog_open_results);
    Composite composite = (Composite) super.createDialogArea(parent);
    /* first line */
    Group c = new Group(composite, SWT.NONE);
    c.setText(Messages.OpenGCDialog_bin_group_header);
    c.setToolTipText(Messages.OpenGCDialog_bin_group_tooltip);
    GridLayout layout = new GridLayout(2, false);
    c.setLayout(layout);
    GridData data = new GridData(GridData.FILL_BOTH);
    c.setLayoutData(data);
    Label binLabel = new Label(c, SWT.NONE);
    binLabel.setText(Messages.OpenGCDialog_bin_group_label);
    data = new GridData();
    data.horizontalSpan = 2;
    binLabel.setLayoutData(data);
    binText = new Text(c, SWT.BORDER);
    binText.setText(this.defaultValue);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
    binText.setLayoutData(data);
    binText.addModifyListener(new BinaryModifyListener());
    Composite cbBin = new Composite(c, SWT.NONE);
    data = new GridData(GridData.HORIZONTAL_ALIGN_END);
    cbBin.setLayoutData(data);
    cbBin.setLayout(new GridLayout(2, true));
    Button binBrowseWorkspaceButton = new Button(cbBin, SWT.PUSH);
    binBrowseWorkspaceButton.setText(Messages.OpenGCDialog_bin_browser_button_text);
    binBrowseWorkspaceButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> handleBrowseWorkspace(Messages.OpenGCDialog_bin_browser_handler_text, binText)));
    Button binBrowseFileSystemButton = new Button(cbBin, SWT.PUSH);
    binBrowseFileSystemButton.setText(Messages.OpenGCDialog_bin_browser_fs_button_text);
    binBrowseFileSystemButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> handleBrowse(Messages.OpenGCDialog_bin_browser_handler_text, binText)));
    Group covMode = new Group(composite, SWT.NONE);
    covMode.setText(Messages.OpenGCDialog_coverage_mode_header);
    covMode.setToolTipText(Messages.OpenGCDialog_coverage_mode_tooltip);
    GridData covModeData = new GridData(GridData.FILL_BOTH);
    covMode.setLayoutData(covModeData);
    covMode.setLayout(new GridLayout());
    Button openThisFileOnlyButton = new Button(covMode, SWT.RADIO);
    openThisFileOnlyButton.setLayoutData(new GridData());
    final Button openCoverageSummaryButton = new Button(covMode, SWT.RADIO);
    openCoverageSummaryButton.setLayoutData(new GridData());
    // $NON-NLS-1$
    String cFile = gcFile.removeFileExtension().lastSegment() + ".c";
    openThisFileOnlyButton.setText(NLS.bind(Messages.OpenGCDialog_open_file_button_text, cFile));
    openCoverageSummaryButton.setText(Messages.OpenGCDialog_summ_button_text);
    openCoverageSummaryButton.setSelection(true);
    SelectionListener sa = SelectionListener.widgetSelectedAdapter(e -> openCoverageSummary = openCoverageSummaryButton.getSelection());
    openCoverageSummaryButton.addSelectionListener(sa);
    openThisFileOnlyButton.addSelectionListener(sa);
    /* 2sd line */
    errorLabel = new Label(composite, SWT.NONE);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 3;
    errorLabel.setLayoutData(data);
    errorLabel.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_RED));
    c.layout();
    return composite;
}
Also used : WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) STSymbolManager(org.eclipse.linuxtools.binutils.utils.STSymbolManager) CoreException(org.eclipse.core.runtime.CoreException) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) IContainer(org.eclipse.core.resources.IContainer) IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) VariablesPlugin(org.eclipse.core.variables.VariablesPlugin) Composite(org.eclipse.swt.widgets.Composite) IFile(org.eclipse.core.resources.IFile) Activator(org.eclipse.linuxtools.internal.gcov.Activator) GridData(org.eclipse.swt.layout.GridData) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) Text(org.eclipse.swt.widgets.Text) Shell(org.eclipse.swt.widgets.Shell) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) NLS(org.eclipse.osgi.util.NLS) PlatformUI(org.eclipse.ui.PlatformUI) FileDialog(org.eclipse.swt.widgets.FileDialog) ResourceComparator(org.eclipse.ui.views.navigator.ResourceComparator) Status(org.eclipse.core.runtime.Status) IBinaryObject(org.eclipse.cdt.core.IBinaryParser.IBinaryObject) Group(org.eclipse.swt.widgets.Group) File(java.io.File) Dialog(org.eclipse.jface.dialogs.Dialog) ModifyListener(org.eclipse.swt.events.ModifyListener) IResource(org.eclipse.core.resources.IResource) Path(org.eclipse.core.runtime.Path) SWT(org.eclipse.swt.SWT) Label(org.eclipse.swt.widgets.Label) IStringVariableManager(org.eclipse.core.variables.IStringVariableManager) Control(org.eclipse.swt.widgets.Control) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) SelectionListener(org.eclipse.swt.events.SelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) Group(org.eclipse.swt.widgets.Group) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 9 with NLS

use of org.eclipse.osgi.util.NLS in project linuxtools by eclipse.

the class RemoteProxyCMainTab method createProjectGroup.

/**
 * @since 6.0
 */
@Override
protected void createProjectGroup(Composite parent, int colSpan) {
    Composite projComp = new Composite(parent, SWT.NONE);
    GridLayout projLayout = new GridLayout();
    projLayout.numColumns = 2;
    projLayout.marginHeight = 0;
    projLayout.marginWidth = 0;
    projComp.setLayout(projLayout);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = colSpan;
    projComp.setLayoutData(gd);
    fProjLabel = new Label(projComp, SWT.NONE);
    fProjLabel.setText(LaunchMessages.CMainTab_ProjectColon);
    gd = new GridData();
    gd.horizontalSpan = 2;
    fProjLabel.setLayoutData(gd);
    fProjText = new Text(projComp, SWT.SINGLE | SWT.BORDER);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    fProjText.setLayoutData(gd);
    fProjText.addModifyListener(evt -> {
        // if project changes, invalidate program name cache
        fPreviouslyCheckedProgram = null;
        // $NON-NLS-1$
        updateBuildConfigCombo("");
        updateLaunchConfigurationDialog();
    });
    fProjButton = createPushButton(projComp, LaunchMessages.Launch_common_Browse_1, null);
    fProjButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        handleProjectButtonSelected();
        updateLaunchConfigurationDialog();
    }));
}
Also used : ICDTLaunchHelpContextIds(org.eclipse.cdt.launch.ui.ICDTLaunchHelpContextIds) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) URISyntaxException(java.net.URISyntaxException) LaunchImages(org.eclipse.cdt.launch.internal.ui.LaunchImages) CAbstractMainTab(org.eclipse.cdt.launch.ui.CAbstractMainTab) Image(org.eclipse.swt.graphics.Image) CoreException(org.eclipse.core.runtime.CoreException) ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) DebugUITools(org.eclipse.debug.ui.DebugUITools) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) TwoPaneElementSelector(org.eclipse.ui.dialogs.TwoPaneElementSelector) CCorePlugin(org.eclipse.cdt.core.CCorePlugin) IProject(org.eclipse.core.resources.IProject) IPath(org.eclipse.core.runtime.IPath) Composite(org.eclipse.swt.widgets.Composite) URI(java.net.URI) GridData(org.eclipse.swt.layout.GridData) ICProject(org.eclipse.cdt.core.model.ICProject) EFS(org.eclipse.core.filesystem.EFS) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) IFileStore(org.eclipse.core.filesystem.IFileStore) Text(org.eclipse.swt.widgets.Text) Button(org.eclipse.swt.widgets.Button) ProfileLaunchPlugin(org.eclipse.linuxtools.internal.profiling.launch.ProfileLaunchPlugin) NLS(org.eclipse.osgi.util.NLS) ICElement(org.eclipse.cdt.core.model.ICElement) IFileInfo(org.eclipse.core.filesystem.IFileInfo) PTY(org.eclipse.cdt.utils.pty.PTY) ResourceSelectorWidget(org.eclipse.linuxtools.profiling.launch.ui.ResourceSelectorWidget) IBinary(org.eclipse.cdt.core.model.IBinary) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) LaunchMessages(org.eclipse.cdt.launch.internal.ui.LaunchMessages) IDebugUIConstants(org.eclipse.debug.ui.IDebugUIConstants) CElementLabelProvider(org.eclipse.cdt.ui.CElementLabelProvider) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) Window(org.eclipse.jface.window.Window) ICDTLaunchConfigurationConstants(org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants) IResource(org.eclipse.core.resources.IResource) Path(org.eclipse.core.runtime.Path) SWT(org.eclipse.swt.SWT) Label(org.eclipse.swt.widgets.Label) SelectionListener(org.eclipse.swt.events.SelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text)

Example 10 with NLS

use of org.eclipse.osgi.util.NLS in project linuxtools by eclipse.

the class ValgrindExportWizardPage method createControl.

@Override
public void createControl(Composite parent) {
    Composite top = new Composite(parent, SWT.NONE);
    top.setLayout(new GridLayout());
    top.setLayoutData(new GridData(GridData.FILL_BOTH));
    IPath logPath = null;
    // Retrieve location of Valgrind logs from launch configuration
    ILaunchConfiguration config = getPlugin().getCurrentLaunchConfiguration();
    if (config != null && config.exists()) {
        String strpath;
        try {
            strpath = config.getAttribute(LaunchConfigurationConstants.ATTR_INTERNAL_OUTPUT_DIR, (String) null);
            if (strpath != null) {
                logPath = Path.fromPortableString(strpath);
            }
        } catch (CoreException e) {
            setErrorMessage(e.getLocalizedMessage());
            e.printStackTrace();
        }
    }
    Label selectFilesLabel = new Label(top, SWT.NONE);
    // $NON-NLS-1$
    selectFilesLabel.setText(Messages.getString("ValgrindExportWizardPage.Viewer_label"));
    viewer = CheckboxTableViewer.newCheckList(top, SWT.BORDER);
    viewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return ((File) element).getName();
        }

        @Override
        public Image getImage(Object element) {
            return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FILE);
        }
    });
    Composite selectAllNoneTop = new Composite(top, SWT.NONE);
    selectAllNoneTop.setLayout(new GridLayout(2, true));
    selectAllNoneTop.setLayoutData(new GridData(SWT.TRAIL, SWT.DEFAULT, false, false));
    Button selectAllButton = new Button(selectAllNoneTop, SWT.NONE);
    selectAllButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    // $NON-NLS-1$
    selectAllButton.setText(Messages.getString("ValgrindExportWizardPage.Select_all"));
    selectAllButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> viewer.setAllChecked(true)));
    Button deselectAllButton = new Button(selectAllNoneTop, SWT.NONE);
    deselectAllButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    // $NON-NLS-1$
    deselectAllButton.setText(Messages.getString("ValgrindExportWizardPage.Deselect_all"));
    deselectAllButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> viewer.setAllChecked(false)));
    createDestinationGroup(top);
    if (logPath != null) {
        // List all output files in our output directory from the recent launch
        File[] logs = logPath.toFile().listFiles((FileFilter) pathname -> pathname.isFile());
        viewer.setInput(logs);
        viewer.setAllChecked(true);
    }
    // catch any errors so far
    setPageComplete(isValid());
    setControl(top);
}
Also used : CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) Image(org.eclipse.swt.graphics.Image) CoreException(org.eclipse.core.runtime.CoreException) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) IPath(org.eclipse.core.runtime.IPath) Composite(org.eclipse.swt.widgets.Composite) WizardPage(org.eclipse.jface.wizard.WizardPage) GridData(org.eclipse.swt.layout.GridData) Text(org.eclipse.swt.widgets.Text) Shell(org.eclipse.swt.widgets.Shell) Button(org.eclipse.swt.widgets.Button) NLS(org.eclipse.osgi.util.NLS) PlatformUI(org.eclipse.ui.PlatformUI) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) Group(org.eclipse.swt.widgets.Group) File(java.io.File) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) ISharedImages(org.eclipse.ui.ISharedImages) FileFilter(java.io.FileFilter) Path(org.eclipse.core.runtime.Path) SWT(org.eclipse.swt.SWT) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) Label(org.eclipse.swt.widgets.Label) LabelProvider(org.eclipse.jface.viewers.LabelProvider) SelectionListener(org.eclipse.swt.events.SelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) Composite(org.eclipse.swt.widgets.Composite) IPath(org.eclipse.core.runtime.IPath) Label(org.eclipse.swt.widgets.Label) Image(org.eclipse.swt.graphics.Image) GridLayout(org.eclipse.swt.layout.GridLayout) CoreException(org.eclipse.core.runtime.CoreException) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider) File(java.io.File)

Aggregations

NLS (org.eclipse.osgi.util.NLS)17 CoreException (org.eclipse.core.runtime.CoreException)10 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)8 IPath (org.eclipse.core.runtime.IPath)7 SWT (org.eclipse.swt.SWT)7 SelectionListener (org.eclipse.swt.events.SelectionListener)7 GridData (org.eclipse.swt.layout.GridData)7 GridLayout (org.eclipse.swt.layout.GridLayout)7 Button (org.eclipse.swt.widgets.Button)7 Composite (org.eclipse.swt.widgets.Composite)7 Label (org.eclipse.swt.widgets.Label)7 Text (org.eclipse.swt.widgets.Text)7 IResource (org.eclipse.core.resources.IResource)6 ResourcesPlugin (org.eclipse.core.resources.ResourcesPlugin)6 ILaunchConfigurationWorkingCopy (org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)6 IStatus (org.eclipse.core.runtime.IStatus)5 Path (org.eclipse.core.runtime.Path)5 Status (org.eclipse.core.runtime.Status)5 File (java.io.File)4 IProject (org.eclipse.core.resources.IProject)4