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;
}
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;
}
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;
}
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();
}));
}
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);
}
Aggregations