Search in sources :

Example 1 with DefaultGalleryItemRenderer

use of org.eclipse.nebula.widgets.gallery.DefaultGalleryItemRenderer in project archi by archimatetool.

the class NewModelFromTemplateWizardPage method createControl.

@Override
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    container.setLayout(new GridLayout());
    setControl(container);
    // Help
    PlatformUI.getWorkbench().getHelpSystem().setHelp(container, getHelpID());
    GridData gd;
    SashForm sash1 = new SashForm(container, SWT.HORIZONTAL);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.widthHint = 800;
    gd.heightHint = 500;
    sash1.setLayoutData(gd);
    Composite tableComposite = new Composite(sash1, SWT.BORDER);
    GridLayout layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.verticalSpacing = 0;
    tableComposite.setLayout(layout);
    // Inbuilt Templates
    gd = new GridData(SWT.FILL, SWT.FILL, true, false);
    fInbuiltTableViewer = createGroupsTableViewer(tableComposite, Messages.NewModelFromTemplateWizardPage_2, gd);
    fInbuiltTableViewer.setInput(new Object[] { fTemplateManager.getInbuiltTemplateGroup(), OPEN, MANAGE });
    // Mouse UP actions...
    fInbuiltTableViewer.getControl().addMouseListener(new MouseAdapter() {

        @Override
        public void mouseUp(MouseEvent e) {
            Object o = ((IStructuredSelection) fInbuiltTableViewer.getSelection()).getFirstElement();
            // Open...
            if (o == OPEN) {
                handleOpenAction();
            } else // Manage...
            if (o == MANAGE) {
                handleManageTemplatesAction();
            }
        }
    });
    // My Templates
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    fUserTableViewer = createGroupsTableViewer(tableComposite, Messages.NewModelFromTemplateWizardPage_3, gd);
    fUserTableViewer.setComparator(new ViewerComparator() {

        @Override
        public int category(Object element) {
            if (element == fTemplateManager.AllUserTemplatesGroup) {
                return 0;
            }
            return 1;
        }
    });
    fUserTableViewer.setInput(fTemplateManager);
    SashForm sash2 = new SashForm(sash1, SWT.VERTICAL);
    Composite galleryComposite = new Composite(sash2, SWT.NULL);
    layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.verticalSpacing = 0;
    galleryComposite.setLayout(layout);
    fGallery = new Gallery(galleryComposite, SWT.V_SCROLL | SWT.BORDER);
    fGallery.setLayoutData(new GridData(GridData.FILL_BOTH));
    // Renderers
    final NoGroupRenderer groupRenderer = new NoGroupRenderer();
    groupRenderer.setItemSize(DEFAULT_GALLERY_ITEM_SIZE, DEFAULT_GALLERY_ITEM_SIZE);
    groupRenderer.setAutoMargin(true);
    groupRenderer.setMinMargin(10);
    fGallery.setGroupRenderer(groupRenderer);
    final DefaultGalleryItemRenderer itemRenderer = new DefaultGalleryItemRenderer();
    itemRenderer.setDropShadows(true);
    itemRenderer.setDropShadowsSize(7);
    itemRenderer.setShowRoundedSelectionCorners(false);
    fGallery.setItemRenderer(itemRenderer);
    // Root Group
    fGalleryRoot = new GalleryItem(fGallery, SWT.NONE);
    // Slider
    final Scale scale = new Scale(galleryComposite, SWT.HORIZONTAL);
    gd = new GridData(SWT.END, SWT.NONE, false, false);
    gd.widthHint = 120;
    if (PlatformUtils.isMac()) {
        // Mac clips height of slider
        gd.heightHint = 20;
    }
    scale.setLayoutData(gd);
    scale.setMaximum(480);
    scale.setMinimum(64);
    scale.setIncrement(8);
    scale.setPageIncrement(64);
    scale.setSelection(DEFAULT_GALLERY_ITEM_SIZE);
    scale.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int inc = scale.getSelection();
            itemRenderer.setDropShadows(inc >= DEFAULT_GALLERY_ITEM_SIZE);
            groupRenderer.setItemSize(inc, inc);
        }
    });
    // Description
    fDescriptionText = new StyledText(sash2, SWT.V_SCROLL | SWT.READ_ONLY | SWT.WRAP | SWT.BORDER);
    fGallery.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (e.item instanceof GalleryItem) {
                ITemplate template = (ITemplate) ((GalleryItem) e.item).getData();
                updateWizard(template);
            } else {
                updateWizard(null);
            }
        }
    });
    // Double-clicks
    fGallery.addListener(SWT.MouseDoubleClick, new Listener() {

        public void handleEvent(Event event) {
            GalleryItem item = fGallery.getItem(new Point(event.x, event.y));
            if (item != null) {
                ((ExtendedWizardDialog) getContainer()).finishPressed();
            }
        }
    });
    // Dispose of the images in TemplateManager here not in the main dispose() method because if the help system is showing then
    // the TrayDialog is resized and this control is asked to relayout.
    fGallery.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            fTemplateManager.dispose();
        }
    });
    // Mouse move shows thumbnails
    registerMouseMoveHandler();
    // Select first group on table
    selectFirstTableItem();
    sash1.setWeights(new int[] { 30, 70 });
    sash2.setWeights(new int[] { 70, 30 });
    // Yes it's OK
    setPageComplete(true);
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) MouseEvent(org.eclipse.swt.events.MouseEvent) StyledText(org.eclipse.swt.custom.StyledText) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) DisposeListener(org.eclipse.swt.events.DisposeListener) Listener(org.eclipse.swt.widgets.Listener) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Scale(org.eclipse.swt.widgets.Scale) DefaultGalleryItemRenderer(org.eclipse.nebula.widgets.gallery.DefaultGalleryItemRenderer) Point(org.eclipse.swt.graphics.Point) GalleryItem(org.eclipse.nebula.widgets.gallery.GalleryItem) DisposeEvent(org.eclipse.swt.events.DisposeEvent) SashForm(org.eclipse.swt.custom.SashForm) GridLayout(org.eclipse.swt.layout.GridLayout) Gallery(org.eclipse.nebula.widgets.gallery.Gallery) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Event(org.eclipse.swt.widgets.Event) MouseEvent(org.eclipse.swt.events.MouseEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ITemplate(com.archimatetool.templates.model.ITemplate) NoGroupRenderer(org.eclipse.nebula.widgets.gallery.NoGroupRenderer)

Example 2 with DefaultGalleryItemRenderer

use of org.eclipse.nebula.widgets.gallery.DefaultGalleryItemRenderer in project archi by archimatetool.

the class ImageManagerDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    // Help
    PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
    setTitle(Messages.ImageManagerDialog_1);
    setMessage(Messages.ImageManagerDialog_2);
    Composite composite = (Composite) super.createDialogArea(parent);
    Composite client = new Composite(composite, SWT.NULL);
    GridLayout layout = new GridLayout(2, false);
    client.setLayout(layout);
    client.setLayoutData(new GridData(GridData.FILL_BOTH));
    SashForm sash = new SashForm(client, SWT.HORIZONTAL);
    sash.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 580;
    gd.heightHint = 300;
    sash.setLayoutData(gd);
    // Table
    Composite tableComp = new Composite(sash, SWT.BORDER);
    layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    tableComp.setLayout(layout);
    CLabel label = new CLabel(tableComp, SWT.NULL);
    label.setText(Messages.ImageManagerDialog_3);
    Composite tableComp2 = new Composite(tableComp, SWT.NULL);
    tableComp2.setLayout(new TableColumnLayout());
    tableComp2.setLayoutData(new GridData(GridData.FILL_BOTH));
    fModelsViewer = new ModelsViewer(tableComp2);
    fModelsViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
    // $NON-NLS-1$
    fModelsViewer.setInput("");
    fModelsViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            Object o = ((IStructuredSelection) event.getSelection()).getFirstElement();
            if (o instanceof IArchimateModel) {
                fScale.setEnabled(true);
                clearGallery();
                updateGallery((IArchimateModel) o);
            }
        }
    });
    // Mouse Up action...
    fModelsViewer.getControl().addMouseListener(new MouseAdapter() {

        @Override
        public void mouseUp(MouseEvent e) {
            Object o = ((IStructuredSelection) fModelsViewer.getSelection()).getFirstElement();
            // Open...
            if (o == OPEN) {
                handleOpenAction();
            }
        }
    });
    Composite galleryComposite = new Composite(sash, SWT.NULL);
    layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    galleryComposite.setLayout(layout);
    fGallery = new Gallery(galleryComposite, SWT.V_SCROLL | SWT.BORDER);
    fGallery.setLayoutData(new GridData(GridData.FILL_BOTH));
    // Renderers
    final NoGroupRenderer groupRenderer = new NoGroupRenderer();
    groupRenderer.setItemSize(DEFAULT_GALLERY_ITEM_SIZE, DEFAULT_GALLERY_ITEM_SIZE);
    groupRenderer.setAutoMargin(true);
    groupRenderer.setMinMargin(10);
    fGallery.setGroupRenderer(groupRenderer);
    final DefaultGalleryItemRenderer itemRenderer = new DefaultGalleryItemRenderer();
    itemRenderer.setDropShadows(true);
    itemRenderer.setDropShadowsSize(7);
    itemRenderer.setShowRoundedSelectionCorners(false);
    fGallery.setItemRenderer(itemRenderer);
    // Root Group
    fGalleryRoot = new GalleryItem(fGallery, SWT.NONE);
    // Slider
    fScale = new Scale(galleryComposite, SWT.HORIZONTAL);
    gd = new GridData(SWT.END, SWT.NONE, false, false);
    gd.widthHint = 120;
    if (PlatformUtils.isMac()) {
        // Mac clips height of slider
        gd.heightHint = 18;
    }
    fScale.setLayoutData(gd);
    fScale.setMinimum(MIN_GALLERY_ITEM_SIZE);
    fScale.setMaximum(MAX_GALLERY_ITEM_SIZE);
    fScale.setIncrement(8);
    fScale.setPageIncrement(32);
    fScale.setSelection(DEFAULT_GALLERY_ITEM_SIZE);
    fScale.setEnabled(false);
    fScale.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int inc = fScale.getSelection();
            itemRenderer.setDropShadows(inc >= 96);
            groupRenderer.setItemSize(inc, inc);
        }
    });
    // Gallery selections
    fGallery.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (e.item instanceof GalleryItem) {
                fSelectedObject = ((GalleryItem) e.item).getData();
            } else {
                fSelectedObject = null;
            }
        }
    });
    // Double-clicks
    fGallery.addListener(SWT.MouseDoubleClick, new Listener() {

        public void handleEvent(Event event) {
            GalleryItem item = fGallery.getItem(new Point(event.x, event.y));
            if (item != null) {
                okPressed();
            }
        }
    });
    // Dispose of the images here not in the main dispose() method because if the help system is showing then
    // the TrayDialog is resized and this control is asked to relayout.
    fGallery.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            disposeImages();
        }
    });
    sash.setWeights(new int[] { 30, 70 });
    /*
         * Select the given model and image
         * Better to put this on a thread as selection sometimes doesn't happen
         */
    Display.getCurrent().asyncExec(new Runnable() {

        @Override
        public void run() {
            // Make selection of model in table if it has images
            if (fSelectedModel != null) {
                IArchiveManager archiveManager = (IArchiveManager) fSelectedModel.getAdapter(IArchiveManager.class);
                if (archiveManager.hasImages()) {
                    // Select model
                    fModelsViewer.setSelection(new StructuredSelection(fSelectedModel));
                    // Make selection of image if set
                    if (fSelectedImagePath != null) {
                        for (GalleryItem item : fGalleryRoot.getItems()) {
                            String imagePath = (String) item.getData();
                            if (imagePath != null && fSelectedImagePath.equals(imagePath)) {
                                fGallery.setSelection(new GalleryItem[] { item });
                                // we need to do this here because this is on a thread
                                fSelectedObject = imagePath;
                                break;
                            }
                        }
                    }
                } else // Else select the first valid model that's open
                {
                    for (IArchimateModel model : IEditorModelManager.INSTANCE.getModels()) {
                        archiveManager = (IArchiveManager) model.getAdapter(IArchiveManager.class);
                        if (archiveManager.hasImages()) {
                            fModelsViewer.setSelection(new StructuredSelection(model));
                            break;
                        }
                    }
                }
            }
        }
    });
    return composite;
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) DisposeListener(org.eclipse.swt.events.DisposeListener) DisposeListener(org.eclipse.swt.events.DisposeListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Listener(org.eclipse.swt.widgets.Listener) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) GridLayout(org.eclipse.swt.layout.GridLayout) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IArchimateModel(com.archimatetool.model.IArchimateModel) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Scale(org.eclipse.swt.widgets.Scale) DefaultGalleryItemRenderer(org.eclipse.nebula.widgets.gallery.DefaultGalleryItemRenderer) Point(org.eclipse.swt.graphics.Point) GalleryItem(org.eclipse.nebula.widgets.gallery.GalleryItem) IArchiveManager(com.archimatetool.editor.model.IArchiveManager) SashForm(org.eclipse.swt.custom.SashForm) Gallery(org.eclipse.nebula.widgets.gallery.Gallery) GridData(org.eclipse.swt.layout.GridData) DisposeEvent(org.eclipse.swt.events.DisposeEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) NoGroupRenderer(org.eclipse.nebula.widgets.gallery.NoGroupRenderer)

Aggregations

ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)2 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)2 DefaultGalleryItemRenderer (org.eclipse.nebula.widgets.gallery.DefaultGalleryItemRenderer)2 Gallery (org.eclipse.nebula.widgets.gallery.Gallery)2 GalleryItem (org.eclipse.nebula.widgets.gallery.GalleryItem)2 NoGroupRenderer (org.eclipse.nebula.widgets.gallery.NoGroupRenderer)2 SashForm (org.eclipse.swt.custom.SashForm)2 DisposeEvent (org.eclipse.swt.events.DisposeEvent)2 DisposeListener (org.eclipse.swt.events.DisposeListener)2 MouseAdapter (org.eclipse.swt.events.MouseAdapter)2 MouseEvent (org.eclipse.swt.events.MouseEvent)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 Point (org.eclipse.swt.graphics.Point)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 Event (org.eclipse.swt.widgets.Event)2 Listener (org.eclipse.swt.widgets.Listener)2 Scale (org.eclipse.swt.widgets.Scale)2