public StereotypeImageEditor(Composite parent, int style) { TabbedPropertySheetWidgetFactory factory = AbstractEditor.factory; composite = factory.createFlatFormComposite(parent); FormData data; browseButton = factory.createButton(composite, "", SWT.PUSH); // $NON-NLS-1$ browseButton.setImage(Activator.getDefault().getImage(addImagePath)); removeButton = factory.createButton(composite, "", SWT.PUSH); // $NON-NLS-1$ removeButton.setImage(Activator.getDefault().getImage("/icons/delete.gif")); // $NON-NLS-1$ CLabel iconLabel = factory.createCLabel(composite, "Content: "); // browseButton layout data = new FormData(); data.left = new FormAttachment(0, 85); data.top = new FormAttachment(0, ITabbedPropertyConstants.HSPACE); browseButton.setLayoutData(data); // removeButton layout data = new FormData(); data.left = new FormAttachment(browseButton, ITabbedPropertyConstants.HSPACE); data.top = new FormAttachment(browseButton, 0, SWT.CENTER); removeButton.setLayoutData(data); // iconLabel layout data = new FormData(); data.left = new FormAttachment(0, 0); data.top = new FormAttachment(browseButton, 0, SWT.CENTER); iconLabel.setLayoutData(data); browseButton.addSelectionListener(this); removeButton.addSelectionListener(this); }
public void refresh() { if (!browseButton.isDisposed()) { /* initialization of buttons enabling */ if (!(getElement() instanceof Image)) { return; } // Get Image content org.eclipse.swt.graphics.Image image = null; try { image = ImageUtil.getContent((Image) getElement()); } catch (Exception e) { Activator.log.error(e); } // Refresh text if (image != null) { // Resize icon to 32x32 org.eclipse.swt.graphics.Image resizedIcon = new org.eclipse.swt.graphics.Image( image.getDevice(), image.getImageData().scaledTo(32, 32)); browseButton.setImage(resizedIcon); removeButton.setEnabled(true); } else { browseButton.setImage(Activator.getDefault().getImage(addImagePath)); removeButton.setEnabled(false); } } }