Search in sources :

Example 6 with PaletteEntry

use of org.eclipse.gef.palette.PaletteEntry in project tdi-studio-se by Talend.

the class TalendPaletteContextMenuProvider method addListNotes.

public void addListNotes(List eleList, Project project, PaletteViewer paletteViewer) {
    for (int i = 0; i < eleList.size(); i++) {
        PaletteEntry elementLi = (PaletteEntry) eleList.get(i);
        if (elementLi instanceof TalendPaletteDrawer) {
            List list = ((TalendPaletteDrawer) elementLi).getChildren();
            addListNotes(list, project, paletteViewer);
        } else if (elementLi instanceof CombinedTemplateCreationEntry) {
            addNotes((CombinedTemplateCreationEntry) elementLi, project, paletteViewer);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) PaletteEntry(org.eclipse.gef.palette.PaletteEntry) CombinedTemplateCreationEntry(org.eclipse.gef.palette.CombinedTemplateCreationEntry)

Example 7 with PaletteEntry

use of org.eclipse.gef.palette.PaletteEntry in project core by jcryptool.

the class AlgorithmPaletteViewer method makeAndAssignActions.

/**
 * Constructs the actions according to the algorithm extension point and
 * assigns the actions to the doubleclick listener of the viewer
 */
private void makeAndAssignActions() {
    doubleClickHandler = new AbstractHandler() {

        public Object execute(ExecutionEvent event) {
            Object selection = ((IStructuredSelection) viewer.getSelection()).getFirstElement();
            if (selection instanceof PaletteEditPart) {
                PaletteEditPart paletteEditPart = (PaletteEditPart) selection;
                Object model = paletteEditPart.getModel();
                IEditorReference[] editorReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
                if (editorReferences.length == 0 && (!((PaletteEntry) model).getParent().getLabel().equals(org.jcryptool.core.Messages.applicationActionBarAdvisor_Menu_Algorithms_PRNG))) {
                    AlgorithmView.showMessage(Messages.AlgorithmPaletteViewer_0);
                } else {
                    final ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
                    Iterator<CommandInfo> it9 = algorithmList.iterator();
                    CommandInfo commandInfo = null;
                    while (it9.hasNext()) {
                        commandInfo = it9.next();
                        ShadowAlgorithmHandler handler = (ShadowAlgorithmHandler) commandInfo.getHandler();
                        String commandId = commandInfo.getCommandId();
                        if (commandId != null && model.toString().equals("Palette Entry (" + handler.getText() + ")")) {
                            // $NON-NLS-1$ //$NON-NLS-2$
                            Command command = commandService.getCommand(commandId);
                            try {
                                return command.executeWithChecks(event);
                            } catch (Exception ex) {
                                LogUtil.logError(ViewsPlugin.PLUGIN_ID, ex);
                                return (null);
                            }
                        }
                    }
                }
            }
            return (null);
        }
    };
    viewer.getControl().addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(final MouseEvent e) {
            if (e.button == 1) {
                // only left button double clicks
                final IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
                IEvaluationContext evaluationContext = handlerService.createContextSnapshot(true);
                ExecutionEvent event = new ExecutionEvent(null, Collections.EMPTY_MAP, null, evaluationContext);
                try {
                    // run assigned action
                    doubleClickHandler.execute(event);
                } catch (ExecutionException ex) {
                    LogUtil.logError(ViewsPlugin.PLUGIN_ID, ex);
                }
            }
        }

        @Override
        public void mouseDown(final MouseEvent e) {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            Object obj = selection.getFirstElement();
            if (obj instanceof PaletteEditPart) {
                AlgorithmView.showContextHelp(extensionPointId, ((PaletteEntry) ((PaletteEditPart) obj).getModel()).getLabel());
                viewer.getControl().setFocus();
                viewer.setSelection(selection);
            }
        }
    });
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) ShadowAlgorithmHandler(org.jcryptool.core.operations.algorithm.ShadowAlgorithmHandler) MouseAdapter(org.eclipse.swt.events.MouseAdapter) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PaletteEntry(org.eclipse.gef.palette.PaletteEntry) PaletteEditPart(org.eclipse.gef.ui.palette.editparts.PaletteEditPart) AbstractHandler(org.eclipse.core.commands.AbstractHandler) ICommandService(org.eclipse.ui.commands.ICommandService) ExecutionException(org.eclipse.core.commands.ExecutionException) CommandInfo(org.jcryptool.core.operations.CommandInfo) IHandlerService(org.eclipse.ui.handlers.IHandlerService) Command(org.eclipse.core.commands.Command) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) Iterator(java.util.Iterator) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 8 with PaletteEntry

use of org.eclipse.gef.palette.PaletteEntry in project core by jcryptool.

the class ViewProviderPaletteViewer method makeAndAssignActions.

/**
 * Creates the actions and assigns them to the viewers double click listener.
 */
private void makeAndAssignActions() {
    doubleClickHandler = new AbstractHandler() {

        public Object execute(ExecutionEvent event) {
            final ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
            Object obj = ((IStructuredSelection) viewer.getSelection()).getFirstElement();
            if (obj instanceof PaletteEditPart) {
                PaletteEditPart part = (PaletteEditPart) obj;
                IConfigurationElement[] elements = Platform.getExtensionRegistry().getExtensionPoint(extensionPointId).getConfigurationElements();
                for (IConfigurationElement element : elements) {
                    if (element.getAttribute("name").equals((// $NON-NLS-1$
                    (PaletteEntry) part.getModel()).getLabel())) {
                        // $NON-NLS-1$
                        Command command = commandService.getCommand(element.getAttribute("viewId"));
                        try {
                            return command.executeWithChecks(event);
                        } catch (Exception ex) {
                            LogUtil.logError(ViewsPlugin.PLUGIN_ID, ex);
                            return (null);
                        }
                    }
                }
            }
            return (null);
        }
    };
    viewer.getControl().addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(final MouseEvent e) {
            if (e.button == 1) {
                // only left button double clicks
                final IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
                IEvaluationContext evaluationContext = handlerService.createContextSnapshot(true);
                ExecutionEvent event = new ExecutionEvent(null, Collections.EMPTY_MAP, null, evaluationContext);
                try {
                    // run assigned action
                    doubleClickHandler.execute(event);
                } catch (ExecutionException ex) {
                    LogUtil.logError(ViewsPlugin.PLUGIN_ID, ex);
                }
            }
        }

        @Override
        public void mouseDown(final MouseEvent e) {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            Object obj = selection.getFirstElement();
            if (obj instanceof PaletteEditPart) {
                AlgorithmView.showContextHelp(extensionPointId, ((PaletteEntry) ((PaletteEditPart) obj).getModel()).getLabel());
                viewer.getControl().setFocus();
                viewer.setSelection(selection);
            }
        }
    });
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) MouseAdapter(org.eclipse.swt.events.MouseAdapter) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PaletteEntry(org.eclipse.gef.palette.PaletteEntry) PaletteEditPart(org.eclipse.gef.ui.palette.editparts.PaletteEditPart) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) AbstractHandler(org.eclipse.core.commands.AbstractHandler) ICommandService(org.eclipse.ui.commands.ICommandService) ExecutionException(org.eclipse.core.commands.ExecutionException) IHandlerService(org.eclipse.ui.handlers.IHandlerService) Command(org.eclipse.core.commands.Command) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 9 with PaletteEntry

use of org.eclipse.gef.palette.PaletteEntry in project core by jcryptool.

the class ViewProviderPaletteViewer method createTree.

/**
 * Creates a tree from the extension point structure.
 *
 * @param needles the search string to filter the elements
 */
private void createTree(String[] needles) {
    invisibleRoot = new PaletteRoot();
    TreeMap<String, PaletteEntry> sortList = new TreeMap<String, PaletteEntry>();
    IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(extensionPointId);
    // $NON-NLS-1$
    String label = "";
    if (extensionPoint.getLabel().equals("analysis")) {
        // $NON-NLS-1$
        label = AlgorithmView.MENU_TEXT_ANALYSIS;
    } else if (extensionPoint.getLabel().equals("games")) {
        // $NON-NLS-1$
        label = AlgorithmView.MENU_TEXT_GAMES;
    } else if (extensionPoint.getLabel().equals("visuals")) {
        // $NON-NLS-1$
        label = AlgorithmView.MENU_TEXT_VISUALS;
    }
    PaletteDrawer category = new PaletteDrawer(label);
    category.setSmallIcon(ViewsPlugin.getImageDescriptor(TreeView.ICON_FOLDER));
    category.setLargeIcon(ViewsPlugin.getImageDescriptor(TreeView.ICON_FOLDER));
    invisibleRoot.add(category);
    IConfigurationElement[] elements = extensionPoint.getConfigurationElements();
    for (IConfigurationElement element : elements) {
        // $NON-NLS-1$
        String name = element.getAttribute("name");
        // filter
        boolean show = true;
        for (String needle : needles) {
            if (// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            !needle.equals("") && !name.toLowerCase().matches(".*" + needle.toLowerCase() + ".*"))
                show = false;
        }
        if (show) {
            SelectionToolEntry paletteEntry = new SelectionToolEntry(element.getAttribute("name"), // $NON-NLS-1$ //$NON-NLS-2$
            "");
            paletteEntry.setSmallIcon(ViewsPlugin.getImageDescriptor(TreeView.ICON_ITEM_JCT));
            paletteEntry.setLargeIcon(ViewsPlugin.getImageDescriptor(TreeView.ICON_ITEM_JCT));
            paletteEntry.setUserModificationPermission(PaletteEntry.PERMISSION_NO_MODIFICATION);
            // $NON-NLS-1$
            paletteEntry.setType("");
            sortList.put(paletteEntry.getLabel(), paletteEntry);
        }
    }
    // attach items to the category
    for (PaletteEntry entry : sortList.values()) {
        category.add(entry);
    }
}
Also used : PaletteRoot(org.eclipse.gef.palette.PaletteRoot) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) SelectionToolEntry(org.eclipse.gef.palette.SelectionToolEntry) PaletteDrawer(org.eclipse.gef.palette.PaletteDrawer) PaletteEntry(org.eclipse.gef.palette.PaletteEntry) TreeMap(java.util.TreeMap) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 10 with PaletteEntry

use of org.eclipse.gef.palette.PaletteEntry in project tdi-studio-se by Talend.

the class TalendEntryEditPart method refreshVisuals.

@Override
protected void refreshVisuals() {
    applyChange();
    PaletteEntry entry = getPaletteEntry();
    talendCustomLabel.setName(entry.getLabel());
    talendCustomLabel.setDescription(entry.getDescription());
    if (getPreferenceSource().useLargeIcons()) {
        setImageDescriptor(entry.getLargeIcon());
    } else {
        setImageDescriptor(entry.getSmallIcon());
    }
    int layoutMode = getLayoutSetting();
    talendCustomLabel.setLayoutMode(layoutMode);
    if (layoutMode == PaletteViewerPreferences.LAYOUT_COLUMNS) {
        talendCustomLabel.setBorder(entryCSSStyleSetting.getIconBorder());
    } else if (layoutMode == PaletteViewerPreferences.LAYOUT_LIST || layoutMode == PaletteViewerPreferences.LAYOUT_DETAILS) {
        talendCustomLabel.setBorder(entryCSSStyleSetting.getListBorder());
    } else if (layoutMode == PaletteViewerPreferences.LAYOUT_ICONS && !isToolbarItem()) {
        talendCustomLabel.setBorder(entryCSSStyleSetting.getIconBorder());
    } else {
        talendCustomLabel.setBorder(null);
    }
}
Also used : PaletteEntry(org.eclipse.gef.palette.PaletteEntry)

Aggregations

PaletteEntry (org.eclipse.gef.palette.PaletteEntry)15 List (java.util.List)4 CombinedTemplateCreationEntry (org.eclipse.gef.palette.CombinedTemplateCreationEntry)4 PaletteContainer (org.eclipse.gef.palette.PaletteContainer)4 ArrayList (java.util.ArrayList)3 Iterator (java.util.Iterator)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 AbstractHandler (org.eclipse.core.commands.AbstractHandler)2 Command (org.eclipse.core.commands.Command)2 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)2 ExecutionException (org.eclipse.core.commands.ExecutionException)2 IEvaluationContext (org.eclipse.core.expressions.IEvaluationContext)2 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)2 PaletteGroup (org.eclipse.gef.palette.PaletteGroup)2 PaletteRoot (org.eclipse.gef.palette.PaletteRoot)2 PaletteEditPart (org.eclipse.gef.ui.palette.editparts.PaletteEditPart)2 MouseAdapter (org.eclipse.swt.events.MouseAdapter)2 MouseEvent (org.eclipse.swt.events.MouseEvent)2 ICommandService (org.eclipse.ui.commands.ICommandService)2 IHandlerService (org.eclipse.ui.handlers.IHandlerService)2