Example usage for org.eclipse.jface.window ToolTip ToolTip

List of usage examples for org.eclipse.jface.window ToolTip ToolTip

Introduction

In this page you can find the example usage for org.eclipse.jface.window ToolTip ToolTip.

Prototype

public ToolTip(Control control) 

Source Link

Document

Create new instance which add TooltipSupport to the widget

Usage

From source file:org.bonitasoft.studio.properties.sections.resources.SelectLocalTemplateWizardPage.java

License:Open Source License

private void createGallery(Composite composite) {
    final Gallery gallery = new Gallery(composite, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER);

    viewer = new GalleryTreeViewer(gallery);

    viewer.setContentProvider(new ITreeContentProvider() {

        @Override/*from w  w w. ja va 2  s.com*/
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {

        }

        @Override
        public void dispose() {

        }

        @Override
        public Object[] getElements(Object inputElement) {
            return new String[] { Messages.webTemplates };
        }

        @Override
        public boolean hasChildren(Object element) {
            return element instanceof String;
        }

        @Override
        public Object getParent(Object element) {
            return null;
        }

        @Override
        public Object[] getChildren(Object parentElement) {
            if (parentElement instanceof String && parentElement.equals(Messages.webTemplates)) {
                List<ApplicationLookNFeelFileStore> applicationThemes = looknfeelStore
                        .getApplicationLookNFeels();
                return applicationThemes.toArray();
            } else {
                return new Object[] {};
            }

        }
    });

    viewer.setLabelProvider(new LabelProvider() {

        @Override
        public Image getImage(Object element) {
            if (element instanceof ApplicationLookNFeelFileStore) {
                Image res = null;
                try {
                    res = ((ApplicationLookNFeelFileStore) element).getPreviewImage();
                } catch (IOException e) {
                    BonitaStudioLog.error(e);
                }
                /*Store image to dispose them at the close*/
                if (res != null) {
                    images.add(res);
                }
                if (res == null) {
                    return Pics.getImage(PicsConstants.noPreview);
                }
                return res;
            }
            return super.getImage(element);
        }

        @Override
        public String getText(Object element) {
            if (element instanceof ApplicationLookNFeelFileStore) {
                return ((ApplicationLookNFeelFileStore) element).getDisplayName();
            }
            return super.getText(element);
        }

    });

    GridDataFactory.fillDefaults().grab(true, true).applyTo(viewer.getGallery());

    AbstractGalleryItemRenderer ir = new DefaultGalleryItemRenderer();

    ir.setGallery(gallery);
    gallery.setItemRenderer(ir);
    DefaultGalleryGroupRenderer groupRenderer = new DefaultGalleryGroupRenderer();
    groupRenderer.setItemSize(200, 100);
    groupRenderer.setAnimation(true);
    groupRenderer.setTitleForeground(GALLERY_HEADER_FOREGROUND_COLOR);
    groupRenderer.setTitleBackground(GALLERY_HEADER_BACKGROUND_COLOR);
    gallery.setBackground(GALLERY_BACKGROUND_COLOR);
    gallery.setGroupRenderer(groupRenderer);

    viewer.setInput(new Object());
    /*Add a tool tip to display the image of the form in better size :)*/
    new ToolTip(gallery) {
        @Override
        protected boolean shouldCreateToolTip(Event event) {
            GalleryItem gi = gallery.getItem(new Point(event.x, event.y));
            if (gi == null || gi.getParentItem() == null) {//avoid tooltip on Group
                return false;
            }
            return super.shouldCreateToolTip(event);
        }

        @Override
        protected Composite createToolTipContentArea(Event event, Composite parent) {
            //TODO : manage size of the tooltip for gallery
            //TODO : create a better UI for the tooltip of the gallery
            GalleryItem gi = gallery.getItem(new Point(event.x, event.y));
            if (gi != null) { //check that the item already exist
                Label testLabel = new Label(parent, SWT.BORDER);
                testLabel.setImage(gi.getImage());
                return parent;
            } else {
                return null;
            }
        }
    };

    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            if (((StructuredSelection) event.getSelection())
                    .getFirstElement() instanceof ApplicationLookNFeelFileStore) {
                selectedTheme = (ApplicationLookNFeelFileStore) ((StructuredSelection) event.getSelection())
                        .getFirstElement();
                setPageComplete(selectedTheme != null);
                updateButtons(selectedTheme);
            }
        }
    });
    Composite buttonComposite = new Composite(composite, SWT.NONE);
    buttonComposite.setLayout(new RowLayout(SWT.HORIZONTAL));
    remove = new Button(buttonComposite, SWT.FLAT);
    remove.setText(Messages.Remove);
    remove.addSelectionListener(new SelectionAdapter() {
        /* (non-Javadoc)
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            Iterator<?> it = selection.iterator();
            while (it.hasNext()) {
                ApplicationLookNFeelFileStore artifact = (ApplicationLookNFeelFileStore) it.next();
                artifact.delete();
                if (!looknfeelStore.getChildren().contains(artifact)) {
                    viewer.remove(artifact);
                }
            }
        }
    });
    export = new Button(buttonComposite, SWT.FLAT);
    export.setText(Messages.ResourceSection_export);
    export.addSelectionListener(new SelectionAdapter() {
        /* (non-Javadoc)
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (!viewer.getSelection().isEmpty()) {
                final DirectoryDialog dialog = new DirectoryDialog(Display.getDefault().getActiveShell());
                final String path = dialog.open();
                if (path != null) {
                    try {
                        getContainer().run(false, false, new IRunnableWithProgress() {
                            @Override
                            public void run(IProgressMonitor monitor)
                                    throws InvocationTargetException, InterruptedException {
                                monitor.beginTask(Messages.exporting, IProgressMonitor.UNKNOWN);
                                IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
                                Iterator<?> it = selection.iterator();
                                while (it.hasNext()) {
                                    final ApplicationLookNFeelFileStore artifact = (ApplicationLookNFeelFileStore) it
                                            .next();
                                    artifact.export(path);
                                }
                                Display.getDefault().syncExec(new Runnable() {
                                    @Override
                                    public void run() {
                                        MessageDialog.openInformation(Display.getDefault().getActiveShell(),
                                                Messages.exportSuccessfullTitle, Messages.exportSuccessfullMsg);
                                    }
                                });
                            }
                        });
                    } catch (InvocationTargetException e1) {
                        BonitaStudioLog.error(e1);
                    } catch (InterruptedException e1) {
                        BonitaStudioLog.error(e1);
                    }
                }

            }
        }
    });
    Button importAction = new Button(buttonComposite, SWT.FLAT);
    importAction.setText(Messages.ResourceSection_importTemplate);
    importAction.addSelectionListener(new SelectionAdapter() {
        /* (non-Javadoc)
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
            dialog.setFilterPath(System.getProperty("user.home"));
            dialog.setFilterExtensions(new String[] { "*." + LookNFeelRepositoryStore.LF_EXTENSION });
            String path = dialog.open();
            if (path != null) {
                FileInputStream fis = null;
                try {
                    File file = new File(path);
                    fis = new FileInputStream(file);
                    IRepositoryFileStore artifact = looknfeelStore.importInputStream(file.getName(), fis);
                    if (artifact != null) {
                        MessageDialog.openInformation(Display.getDefault().getActiveShell(),
                                Messages.importResultTitle, Messages.importSuccessMsg);
                    }
                    if (artifact instanceof ApplicationLookNFeelFileStore) {
                        viewer.add(Messages.webTemplates, artifact);
                    }
                } catch (Exception ee) {
                    new BonitaErrorDialog(getShell(), Messages.Error, Messages.saveAsTemplate_import_error, ee)
                            .open();
                    BonitaStudioLog.error(ee);
                } finally {
                    try {
                        fis.close();
                    } catch (IOException e1) {
                        BonitaStudioLog.error(e1);
                    }
                }
            }
        }
    });
}

From source file:org.eclipse.nebula.widgets.gallery.Gallery.java

License:Open Source License

protected ToolTip createTooltipForItems(final Gallery gal) {
    return new ToolTip(gal) {
        @Override//from  w ww  .j a  va  2 s  .  c o m
        protected boolean shouldCreateToolTip(Event event) {
            GalleryItem gi = gal.getItem(new Point(event.x, event.y));
            if (gi == null || gi.getParentItem() == null) {
                //avoid tooltip on Group
                return false;
            }
            return super.shouldCreateToolTip(event);
        }

        @Override
        protected Composite createToolTipContentArea(Event event, Composite parent) {
            GalleryItem gi = gal.getItem(new Point(event.x, event.y));
            if (gi != null && !gi.getText().isEmpty()) {
                Display display = UIUtils.getDisplay();
                Label nameLabel = new Label(parent, SWT.NONE);
                nameLabel.setText(gi.getText());
                nameLabel.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
                nameLabel.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
                // Shift a bit the tooltip position
                Point[] cursorSizes = display.getCursorSizes();
                if (cursorSizes.length > 0) {
                    this.setShift(new Point(cursorSizes[0].x / 2, cursorSizes[0].y / 2));
                }
                return parent;
            } else {
                return null;
            }
        }
    };
}