Search in sources :

Example 81 with ISelectionChangedListener

use of org.eclipse.jface.viewers.ISelectionChangedListener in project xtext-eclipse by eclipse.

the class TraceEditor method createPageContainer.

@Override
protected Composite createPageContainer(final Composite parent) {
    Composite tree = new Composite(parent, SWT.NONE);
    final Sash sash = new Sash(parent, SWT.HORIZONTAL);
    text = new StyledText(parent, SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL);
    text.setFont(JFaceResources.getTextFont());
    final FormLayout form = new FormLayout();
    parent.setLayout(form);
    FormData treeData = new FormData();
    treeData.left = new FormAttachment(0, 0);
    treeData.right = new FormAttachment(100, 0);
    treeData.top = new FormAttachment(0, 0);
    treeData.bottom = new FormAttachment(sash, 0);
    tree.setLayoutData(treeData);
    final int limit = 20, percent = 50;
    final FormData sashData = new FormData();
    sashData.left = new FormAttachment(0, 0);
    sashData.top = new FormAttachment(percent, 0);
    sashData.right = new FormAttachment(100, 0);
    sash.setLayoutData(sashData);
    sash.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            Rectangle sashRect = sash.getBounds();
            Rectangle parentRect = parent.getClientArea();
            int bottom = parentRect.height - sashRect.height - limit;
            e.y = Math.max(Math.min(e.y, bottom), limit);
            if (e.y != sashRect.y) {
                sashData.top = new FormAttachment(0, e.y);
                parent.layout();
            }
        }
    });
    FormData textData = new FormData();
    textData.left = new FormAttachment(0, 0);
    textData.right = new FormAttachment(100, 0);
    textData.top = new FormAttachment(sash, 0);
    textData.bottom = new FormAttachment(100, 0);
    text.setLayoutData(textData);
    addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            if (selection instanceof IStructuredSelection) {
                try {
                    Object x = ((IStructuredSelection) selection).getFirstElement();
                    if (x instanceof EObject)
                        updateText((EObject) x);
                    if (x instanceof Resource)
                        updateText(((Resource) x).getContents().get(0));
                } catch (Exception e) {
                    text.setText(Throwables.getStackTraceAsString(e));
                }
            }
        }
    });
    return tree;
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) StyledText(org.eclipse.swt.custom.StyledText) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Listener(org.eclipse.swt.widgets.Listener) Composite(org.eclipse.swt.widgets.Composite) Sash(org.eclipse.swt.widgets.Sash) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Rectangle(org.eclipse.swt.graphics.Rectangle) Resource(org.eclipse.emf.ecore.resource.Resource) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TraceNotFoundException(org.eclipse.xtext.generator.trace.TraceNotFoundException) EObject(org.eclipse.emf.ecore.EObject) ISelection(org.eclipse.jface.viewers.ISelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Event(org.eclipse.swt.widgets.Event) EObject(org.eclipse.emf.ecore.EObject) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 82 with ISelectionChangedListener

use of org.eclipse.jface.viewers.ISelectionChangedListener in project archi by archimatetool.

the class ColoursFontsPreferencePage method createColoursTab.

private void createColoursTab() {
    // Reset everything
    resetColorsCache(false);
    fImageRegistry = new ImageRegistry();
    Composite client = new Composite(fTabfolder, SWT.NULL);
    client.setLayout(new GridLayout(2, false));
    TabItem item = new TabItem(fTabfolder, SWT.NONE);
    item.setText(Messages.ColoursFontsPreferencePage_23);
    item.setControl(client);
    Label label = new Label(client, SWT.NULL);
    label.setText(Messages.ColoursFontsPreferencePage_0);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    label.setLayoutData(gd);
    // Tree
    fTreeViewer = new TreeViewer(client);
    gd = new GridData(GridData.FILL_BOTH);
    // need this to set a smaller height
    gd.heightHint = 80;
    fTreeViewer.getTree().setLayoutData(gd);
    // Tree Double-click listener
    fTreeViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            Object[] selected = ((IStructuredSelection) fTreeViewer.getSelection()).toArray();
            if (isValidTreeSelection(selected)) {
                RGB newRGB = openColorDialog(selected[0]);
                if (newRGB != null) {
                    for (Object object : selected) {
                        setColor(object, newRGB);
                    }
                }
            }
        }
    });
    // Tree Selection Changed Listener
    fTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            Object[] selected = ((IStructuredSelection) event.getSelection()).toArray();
            fEditFillColorButton.setEnabled(isValidTreeSelection(selected));
            fResetFillColorButton.setEnabled(isValidTreeSelection(selected));
        }
    });
    // Tree Content Provider
    fTreeViewer.setContentProvider(new ITreeContentProvider() {

        @Override
        public void dispose() {
        }

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        @Override
        public Object[] getElements(Object inputElement) {
            if (inputElement instanceof String) {
                return new Object[] { new TreeGrouping(Messages.ColoursFontsPreferencePage_32, ArchimateModelUtils.getStrategyClasses()), new TreeGrouping(Messages.ColoursFontsPreferencePage_7, ArchimateModelUtils.getBusinessClasses()), new TreeGrouping(Messages.ColoursFontsPreferencePage_8, ArchimateModelUtils.getApplicationClasses()), new TreeGrouping(Messages.ColoursFontsPreferencePage_9, ArchimateModelUtils.getTechnologyClasses()), new TreeGrouping(Messages.ColoursFontsPreferencePage_33, ArchimateModelUtils.getPhysicalClasses()), new TreeGrouping(Messages.ColoursFontsPreferencePage_10, ArchimateModelUtils.getMotivationClasses()), new TreeGrouping(Messages.ColoursFontsPreferencePage_11, ArchimateModelUtils.getImplementationMigrationClasses()), new TreeGrouping(Messages.ColoursFontsPreferencePage_17, ArchimateModelUtils.getOtherClasses()), new TreeGrouping(Messages.ColoursFontsPreferencePage_34, new Object[] { IArchimatePackage.eINSTANCE.getDiagramModelNote(), IArchimatePackage.eINSTANCE.getDiagramModelGroup() }), DEFAULT_ELEMENT_LINE_COLOR, DEFAULT_CONNECTION_LINE_COLOR };
            }
            return null;
        }

        @Override
        public Object[] getChildren(Object parentElement) {
            if (parentElement instanceof TreeGrouping) {
                return ((TreeGrouping) parentElement).children;
            }
            return null;
        }

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

        @Override
        public boolean hasChildren(Object element) {
            return element instanceof TreeGrouping;
        }
    });
    // Tree Label Provider
    fTreeViewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof EClass) {
                return ArchiLabelProvider.INSTANCE.getDefaultName((EClass) element);
            }
            if (element instanceof TreeGrouping) {
                return ((TreeGrouping) element).title;
            }
            if (element instanceof String) {
                String s = (String) element;
                if (s.equals(DEFAULT_ELEMENT_LINE_COLOR)) {
                    return Messages.ColoursFontsPreferencePage_12;
                }
                if (s.equals(DEFAULT_CONNECTION_LINE_COLOR)) {
                    return Messages.ColoursFontsPreferencePage_18;
                }
            }
            return null;
        }

        @Override
        public Image getImage(Object element) {
            if (element instanceof TreeGrouping) {
                return IArchiImages.ImageFactory.getImage(IArchiImages.ECLIPSE_IMAGE_FOLDER);
            }
            return getColorSwatch(element);
        }

        // Create a coloured image based on colour and add to the image registry
        private Image getColorSwatch(Object object) {
            String key = getColorKey(object);
            Image image = fImageRegistry.get(key);
            if (image == null) {
                image = new Image(Display.getCurrent(), 16, 16);
                GC gc = new GC(image);
                SWTGraphics graphics = new SWTGraphics(gc);
                graphics.setBackgroundColor(fColorsCache.get(object));
                graphics.fillRectangle(0, 0, 15, 15);
                graphics.drawRectangle(0, 0, 15, 15);
                gc.dispose();
                graphics.dispose();
                fImageRegistry.put(key, image);
            }
            return image;
        }
    });
    // fTreeViewer.setAutoExpandLevel(2);
    // Set Content in Tree
    // $NON-NLS-1$
    fTreeViewer.setInput("");
    // Buttons
    Composite buttonClient = new Composite(client, SWT.NULL);
    gd = new GridData(SWT.TOP, SWT.TOP, false, false);
    buttonClient.setLayoutData(gd);
    buttonClient.setLayout(new GridLayout());
    // Edit...
    fEditFillColorButton = new Button(buttonClient, SWT.PUSH);
    fEditFillColorButton.setText(Messages.ColoursFontsPreferencePage_13);
    fEditFillColorButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fEditFillColorButton.setEnabled(false);
    fEditFillColorButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            Object[] selected = ((IStructuredSelection) fTreeViewer.getSelection()).toArray();
            if (isValidTreeSelection(selected)) {
                RGB newRGB = openColorDialog(selected[0]);
                if (newRGB != null) {
                    for (Object object : selected) {
                        setColor(object, newRGB);
                    }
                }
            }
        }
    });
    // Reset
    fResetFillColorButton = new Button(buttonClient, SWT.PUSH);
    fResetFillColorButton.setText(Messages.ColoursFontsPreferencePage_14);
    fResetFillColorButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fResetFillColorButton.setEnabled(false);
    fResetFillColorButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            Object[] selected = ((IStructuredSelection) fTreeViewer.getSelection()).toArray();
            if (isValidTreeSelection(selected)) {
                for (Object object : selected) {
                    resetColorToInbuiltDefault(object);
                }
            }
        }
    });
    // Import Scheme
    Button importButton = new Button(buttonClient, SWT.PUSH);
    importButton.setText(Messages.ColoursFontsPreferencePage_2);
    importButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    importButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            try {
                importUserColors();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    });
    // Export Scheme
    Button exportButton = new Button(buttonClient, SWT.PUSH);
    exportButton.setText(Messages.ColoursFontsPreferencePage_3);
    exportButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    exportButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            try {
                exportUserColors();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    });
    Group elementColorGroup = new Group(client, SWT.NULL);
    elementColorGroup.setLayout(new GridLayout(2, false));
    elementColorGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    elementColorGroup.setText(Messages.ColoursFontsPreferencePage_20);
    // Derive element line colours
    fDeriveElementLineColorsButton = new Button(elementColorGroup, SWT.CHECK);
    fDeriveElementLineColorsButton.setText(Messages.ColoursFontsPreferencePage_19);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    fDeriveElementLineColorsButton.setLayoutData(gd);
    fDeriveElementLineColorsButton.setSelection(getPreferenceStore().getBoolean(DERIVE_ELEMENT_LINE_COLOR));
    fDeriveElementLineColorsButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            fElementLineColorContrastSpinner.setEnabled(fDeriveElementLineColorsButton.getSelection());
            fContrastFactorLabel.setEnabled(fDeriveElementLineColorsButton.getSelection());
        }
    });
    fContrastFactorLabel = new Label(elementColorGroup, SWT.NULL);
    fContrastFactorLabel.setText(Messages.ColoursFontsPreferencePage_21);
    fElementLineColorContrastSpinner = new Spinner(elementColorGroup, SWT.BORDER);
    fElementLineColorContrastSpinner.setMinimum(1);
    fElementLineColorContrastSpinner.setMaximum(10);
    fElementLineColorContrastSpinner.setSelection(getPreferenceStore().getInt(DERIVE_ELEMENT_LINE_COLOR_FACTOR));
    label = new Label(elementColorGroup, SWT.NULL);
    label.setText(Messages.ColoursFontsPreferencePage_22);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    // Persist user default colours
    fPersistUserDefaultColors = new Button(client, SWT.CHECK);
    fPersistUserDefaultColors.setText(Messages.ColoursFontsPreferencePage_1);
    fPersistUserDefaultColors.setLayoutData(gd);
    fPersistUserDefaultColors.setSelection(getPreferenceStore().getBoolean(SAVE_USER_DEFAULT_COLOR));
    // Use colours in application
    fShowUserDefaultFillColorsInApplication = new Button(client, SWT.CHECK);
    fShowUserDefaultFillColorsInApplication.setText(Messages.ColoursFontsPreferencePage_6);
    fShowUserDefaultFillColorsInApplication.setLayoutData(gd);
    fShowUserDefaultFillColorsInApplication.setSelection(getPreferenceStore().getBoolean(SHOW_FILL_COLORS_IN_GUI));
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) Group(org.eclipse.swt.widgets.Group) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Spinner(org.eclipse.swt.widgets.Spinner) CLabel(org.eclipse.swt.custom.CLabel) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) Image(org.eclipse.swt.graphics.Image) GridLayout(org.eclipse.swt.layout.GridLayout) EClass(org.eclipse.emf.ecore.EClass) Button(org.eclipse.swt.widgets.Button) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GC(org.eclipse.swt.graphics.GC) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IOException(java.io.IOException) RGB(org.eclipse.swt.graphics.RGB) TabItem(org.eclipse.swt.widgets.TabItem) SWTGraphics(org.eclipse.draw2d.SWTGraphics) ImageRegistry(org.eclipse.jface.resource.ImageRegistry) GridData(org.eclipse.swt.layout.GridData) ArchiLabelProvider(com.archimatetool.editor.ui.ArchiLabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 83 with ISelectionChangedListener

use of org.eclipse.jface.viewers.ISelectionChangedListener in project archi by archimatetool.

the class GeneralPreferencePage method createContents.

@Override
protected Control createContents(Composite parent) {
    // Help
    PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
    Composite client = new Composite(parent, SWT.NULL);
    client.setLayout(new GridLayout());
    GridData gd;
    Group fileGroup = new Group(client, SWT.NULL);
    fileGroup.setText(Messages.GeneralPreferencePage_0);
    fileGroup.setLayout(new GridLayout(2, false));
    fileGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    // Automatically open views when opening a model file
    fOpenDiagramsOnLoadButton = new Button(fileGroup, SWT.CHECK);
    fOpenDiagramsOnLoadButton.setText(Messages.GeneralPreferencePage_1);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    fOpenDiagramsOnLoadButton.setLayoutData(gd);
    // Backup file on save
    fBackupOnSaveButton = new Button(fileGroup, SWT.CHECK);
    fBackupOnSaveButton.setText(Messages.GeneralPreferencePage_5);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    fBackupOnSaveButton.setLayoutData(gd);
    // Size of recently opened file list
    Label label = new Label(fileGroup, SWT.NULL);
    label.setText(Messages.GeneralPreferencePage_2);
    fMRUSizeSpinner = new Spinner(fileGroup, SWT.BORDER);
    fMRUSizeSpinner.setMinimum(3);
    fMRUSizeSpinner.setMaximum(15);
    // Appearance
    Group appearanceGroup = new Group(client, SWT.NULL);
    appearanceGroup.setText(Messages.GeneralPreferencePage_3);
    appearanceGroup.setLayout(new GridLayout(2, false));
    appearanceGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    // Themes
    label = new Label(appearanceGroup, SWT.NULL);
    label.setText(Messages.GeneralPreferencePage_4);
    fThemeComboViewer = new ComboViewer(appearanceGroup, SWT.READ_ONLY);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    fThemeComboViewer.getCombo().setLayoutData(gd);
    fThemeComboViewer.setContentProvider(new IStructuredContentProvider() {

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        public void dispose() {
        }

        public Object[] getElements(Object inputElement) {
            return (Object[]) inputElement;
        }
    });
    fThemeComboViewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return ((ITheme) element).getLabel();
        }
    });
    fThemeComboViewer.setComparator(new ViewerComparator());
    // Show Status Line
    fShowStatusLineButton = new Button(appearanceGroup, SWT.CHECK);
    fShowStatusLineButton.setText(Messages.GeneralPreferencePage_9);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    fShowStatusLineButton.setLayoutData(gd);
    label = new Label(appearanceGroup, SWT.NULL);
    label.setText(Messages.GeneralPreferencePage_8);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    label.setLayoutData(gd);
    // Model Tree
    Group modelTreeGroup = new Group(client, SWT.NULL);
    modelTreeGroup.setText(Messages.GeneralPreferencePage_10);
    modelTreeGroup.setLayout(new GridLayout(2, false));
    modelTreeGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fShowUnusedElementsInModelTreeButton = new Button(modelTreeGroup, SWT.CHECK);
    fShowUnusedElementsInModelTreeButton.setText(Messages.GeneralPreferencePage_11);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    fShowUnusedElementsInModelTreeButton.setLayoutData(gd);
    // Visualiser
    Group visualiserGroup = new Group(client, SWT.NULL);
    visualiserGroup.setText(Messages.GeneralPreferencePage_6);
    visualiserGroup.setLayout(new GridLayout(2, false));
    visualiserGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fAnimateVisualiserNodesButton = new Button(visualiserGroup, SWT.CHECK);
    fAnimateVisualiserNodesButton.setText(Messages.GeneralPreferencePage_7);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    fAnimateVisualiserNodesButton.setLayoutData(gd);
    fAnimateVisualiserNodesButton.setEnabled(AnimationUtil.supportsAnimation());
    setValues();
    fThemeComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            ITheme theme = (ITheme) ((IStructuredSelection) fThemeComboViewer.getSelection()).getFirstElement();
            if (theme != null && theme != fThemeEngine.getActiveTheme()) {
                setTheme(theme, false);
            }
        }
    });
    return client;
}
Also used : Group(org.eclipse.swt.widgets.Group) ITheme(org.eclipse.e4.ui.css.swt.theme.ITheme) Composite(org.eclipse.swt.widgets.Composite) Spinner(org.eclipse.swt.widgets.Spinner) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) ComboViewer(org.eclipse.jface.viewers.ComboViewer) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 84 with ISelectionChangedListener

use of org.eclipse.jface.viewers.ISelectionChangedListener in project archi by archimatetool.

the class ExportAsImagePage method createFormatComboViewer.

/**
 * Create tghe Format Combo Viewer
 */
private ComboViewer createFormatComboViewer(Composite parent) {
    ComboViewer viewer = new ComboViewer(new Combo(parent, SWT.READ_ONLY | SWT.BORDER));
    viewer.setContentProvider(new IStructuredContentProvider() {

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(Object inputElement) {
            return fImageProviders.toArray();
        }
    });
    viewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return ((ImageExportProviderInfo) element).getLabel();
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ImageExportProviderInfo provider = (ImageExportProviderInfo) ((IStructuredSelection) event.getSelection()).getFirstElement();
            providerChanged(provider);
        }
    });
    // $NON-NLS-1$
    viewer.setInput("");
    return viewer;
}
Also used : ComboViewer(org.eclipse.jface.viewers.ComboViewer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) Combo(org.eclipse.swt.widgets.Combo) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ImageExportProviderInfo(com.archimatetool.editor.diagram.ImageExportProviderManager.ImageExportProviderInfo) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 85 with ISelectionChangedListener

use of org.eclipse.jface.viewers.ISelectionChangedListener in project xtext-eclipse by eclipse.

the class NewProjectWizardTemplateSelectionPage method createControl.

@Override
public void createControl(Composite parent) {
    Composite main = new Composite(parent, SWT.NONE);
    main.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    main.setLayout(new GridLayout(1, false));
    Label availableTemplatesLabel = new Label(main, SWT.NONE);
    availableTemplatesLabel.setText(Messages.NewProjectWizardTemplateSelectionPage_available_templates);
    availableTemplatesLabel.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, true, false));
    SashForm sash = new SashForm(main, SWT.HORIZONTAL);
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
    data.widthHint = 400;
    sash.setLayoutData(data);
    TableViewer templateTable = new TableViewer(sash, SWT.BORDER);
    templateTable.setContentProvider(new ArrayContentProvider());
    templateTable.setLabelProvider(labelProvider);
    templateTable.setInput(loadTemplatesFromExtensionPoint());
    FormText text = new FormText(sash, SWT.BORDER);
    // $NON-NLS-1$
    text.setText("", false, false);
    text.setBackground(templateTable.getTable().getBackground());
    templateTable.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            if (selection instanceof IStructuredSelection) {
                IStructuredSelection structuredSelection = (IStructuredSelection) selection;
                Object element = structuredSelection.getFirstElement();
                if (element instanceof AbstractProjectTemplate) {
                    selectedTemplate = (AbstractProjectTemplate) element;
                    setPageComplete(true);
                    // $NON-NLS-1$ //$NON-NLS-2$
                    String content = "<form>" + selectedTemplate.getDescription() + "</form>";
                    try {
                        text.setText(content, true, true);
                    } catch (Exception e) {
                        text.setText(e.getMessage(), false, false);
                    }
                } else {
                    selectedTemplate = null;
                    // $NON-NLS-1$
                    text.setText("", false, false);
                    setPageComplete(false);
                }
            } else {
                selectedTemplate = null;
                // $NON-NLS-1$
                text.setText("", false, false);
                setPageComplete(false);
            }
        }
    });
    templateTable.setSelection(new StructuredSelection(templateTable.getElementAt(0)));
    setControl(main);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) FormText(org.eclipse.ui.forms.widgets.FormText) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) CoreException(org.eclipse.core.runtime.CoreException) SashForm(org.eclipse.swt.custom.SashForm) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ISelection(org.eclipse.jface.viewers.ISelection) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)774 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)755 GridData (org.eclipse.swt.layout.GridData)419 Composite (org.eclipse.swt.widgets.Composite)333 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)302 GridLayout (org.eclipse.swt.layout.GridLayout)247 SelectionEvent (org.eclipse.swt.events.SelectionEvent)187 Label (org.eclipse.swt.widgets.Label)157 TableViewer (org.eclipse.jface.viewers.TableViewer)151 AdapterFactoryLabelProvider (org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider)147 Button (org.eclipse.swt.widgets.Button)141 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)139 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)131 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)121 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)120 IPropertiesEditionEvent (org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)116 PropertiesEditionEvent (org.eclipse.emf.eef.runtime.impl.notify.PropertiesEditionEvent)116 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)116 Table (org.eclipse.swt.widgets.Table)93 ISelection (org.eclipse.jface.viewers.ISelection)87