private void createLabel(Composite c, int span, String content, Image image, LabelAttributes la) { if (content == null && image == null) return; Label l = new Label(c, la.getFontStyle()); GridData gd = new GridData(); gd.verticalSpan = span; gd.horizontalIndent = 5; if (content != null) l.setText(content); if (image != null) l.setImage(image); if (la.getForegroundColor() != null) l.setForeground(new Color(DisplayManager.getDefaultDisplay(), la.getForegroundColor())); Font initialFont = l.getFont(); FontData[] fontData = initialFont.getFontData(); for (int i = 0; i < fontData.length; i++) { fontData[i].setHeight(la.getFontSize()); fontData[i].setStyle(la.getFontStyle()); } Font newFont = new Font(DisplayManager.getDefaultDisplay(), fontData[0]); l.setFont(newFont); l.pack(); l.setBackground(c.getBackground()); l.setLayoutData(gd); }
@Override protected Control createMessageArea(Composite composite) { // create composite // create image Image image = getImage(); if (image != null) { imageLabel = new Label(composite, SWT.NULL); image.setBackground(imageLabel.getBackground()); imageLabel.setImage(image); addAccessibleListeners(imageLabel, image); GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.BEGINNING).applyTo(imageLabel); } // create message if (message != null) { FormToolkit toolkit = new FormToolkit(Display.getDefault()); Composite toolkitComp = toolkit.createComposite(composite); toolkitComp.setLayout(new FillLayout(SWT.HORIZONTAL | SWT.VERTICAL)); FormText text = toolkit.createFormText(toolkitComp, false); text.setText(message, true, true); text.setBackground(composite.getBackground()); GridDataFactory.fillDefaults() .align(SWT.FILL, SWT.BEGINNING) .grab(true, false) .hint( convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH), SWT.DEFAULT) .applyTo(toolkitComp); text.addHyperlinkListener( new HyperlinkAdapter() { public void linkActivated(HyperlinkEvent event) { try { URI uri = URI.create((String) event.data); if ("pref".equals(uri.getScheme())) { // $NON-NLS-1$ Map<String, String> para = new HashMap<String, String>(); para.put( IWorkbenchCommandConstants.WINDOW_PREFERENCES_PARM_PAGEID, uri.getAuthority()); Command prefCommand = PlatformUI.getWorkbench() .getActiveWorkbenchWindow() .getService(ICommandService.class) .getCommand(IWorkbenchCommandConstants.WINDOW_PREFERENCES); prefCommand.executeWithChecks(new ExecutionEvent(prefCommand, para, null, null)); } } catch (ExecutionException e) { Platform.getLog(Platform.getBundle(Constants.Bundle_ID)) .log(new Status(IStatus.ERROR, Constants.Bundle_ID, e.getMessage(), e)); } catch (NotDefinedException e) { Platform.getLog(Platform.getBundle(Constants.Bundle_ID)) .log(new Status(IStatus.ERROR, Constants.Bundle_ID, e.getMessage(), e)); } catch (NotEnabledException e) { Platform.getLog(Platform.getBundle(Constants.Bundle_ID)) .log(new Status(IStatus.ERROR, Constants.Bundle_ID, e.getMessage(), e)); } catch (NotHandledException e) { Platform.getLog(Platform.getBundle(Constants.Bundle_ID)) .log(new Status(IStatus.ERROR, Constants.Bundle_ID, e.getMessage(), e)); } } }); } return composite; }