Search in sources :

Example 1 with WSMenuMenuEntriesDescriptions

use of com.amalto.workbench.webservices.WSMenuMenuEntriesDescriptions in project tmdm-studio-se by Talend.

the class MenuMainPage method createCharacteristicsContent.

@Override
protected void createCharacteristicsContent(FormToolkit toolkit, Composite mainComposite) {
    try {
        // description
        Label descriptionLabel = toolkit.createLabel(mainComposite, Messages.MenuMainPage_Description, SWT.NULL);
        descriptionLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1));
        // $NON-NLS-1$
        descriptionText = toolkit.createText(mainComposite, "", SWT.BORDER);
        descriptionText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
        ((GridData) descriptionText.getLayoutData()).minimumHeight = 30;
        descriptionText.addModifyListener(new ModifyListener() {

            public void modifyText(ModifyEvent e) {
                if (refreshing) {
                    return;
                }
                markDirtyWithoutCommit();
            }
        });
        // Util.createCompDropTarget(descriptionText);
        // make the Page window a DropTarget - we need to dispose it
        windowTarget = new DropTarget(this.getPartControl(), DND.DROP_MOVE);
        windowTarget.setTransfer(new Transfer[] { TextTransfer.getInstance() });
        windowTarget.addDropListener(new DCDropTargetListener());
        Composite composite = toolkit.createComposite(mainComposite, SWT.BORDER);
        composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
        composite.setLayout(new GridLayout(1, false));
        menuTree = new TreeViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
        menuTree.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
        ((GridData) menuTree.getControl().getLayoutData()).heightHint = 150;
        menuTree.setContentProvider(new ITreeContentProvider() {

            public void dispose() {
            }

            public Object[] getChildren(Object parentElement) {
                if (parentElement instanceof TreeEntry) {
                    WSMenuEntry wsEntry = ((TreeEntry) parentElement).getWSMenuEntry();
                    if (wsEntry.getSubMenus() != null) {
                        TreeEntry[] children = new TreeEntry[wsEntry.getSubMenus().size()];
                        for (int i = 0; i < wsEntry.getSubMenus().size(); i++) {
                            children[i] = new TreeEntry((TreeEntry) parentElement, wsEntry.getSubMenus().get(i));
                        }
                        return children;
                    }
                    return null;
                }
                if (parentElement instanceof WSMenu) {
                    // the root
                    java.util.List<WSMenuEntry> menuEntries = ((WSMenu) parentElement).getMenuEntries();
                    if (menuEntries != null) {
                        TreeEntry[] children = new TreeEntry[menuEntries.size()];
                        for (int i = 0; i < menuEntries.size(); i++) {
                            children[i] = new TreeEntry(null, menuEntries.get(i));
                        }
                        return children;
                    }
                    return null;
                }
                // ??!!?
                return null;
            }

            public Object[] getElements(Object inputElement) {
                return getChildren(inputElement);
            }

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

            public boolean hasChildren(Object element) {
                return ((getChildren(element) == null) || (getChildren(element).length > 0));
            }

            public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
            }
        });
        menuTree.setLabelProvider(new LabelProvider() {

            @Override
            public String getText(Object element) {
                WSMenuEntry wsMenuEntry = ((TreeEntry) element).getWSMenuEntry();
                // $NON-NLS-1$
                StringBuffer label = new StringBuffer(wsMenuEntry.getId() + " - ");
                for (WSMenuMenuEntriesDescriptions description : wsMenuEntry.getDescriptions()) {
                    // $NON-NLS-1$//$NON-NLS-2$
                    label.append("[").append(description.getLanguage()).append(": ").append(description.getLabel()).append(// $NON-NLS-1$
                    "] ");
                }
                if (label.length() > 200) {
                    // $NON-NLS-1$
                    return label.substring(0, 197) + "...";
                }
                return label.toString();
            }

            @Override
            public Image getImage(Object element) {
                return ImageCache.getCreatedImage(EImage.MENU.getPath());
            }
        });
        menuTreeMgr = new MenuManager();
        menuTreeMgr.setRemoveAllWhenShown(true);
        menuTreeMgr.addMenuListener(new IMenuListener() {

            public void menuAboutToShow(IMenuManager manager) {
                IStructuredSelection selection = ((IStructuredSelection) menuTree.getSelection());
                if ((selection == null) || (selection.getFirstElement() == null)) {
                    manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
                    return;
                }
                // TreeEntry entry = (TreeEntry)selection.getFirstElement();
                menuTreeMgr.add(new TreeEntryEditAction(menuTree));
                menuTreeMgr.add(new TreeEntryAddAction(menuTree, LOCATION_BEFORE));
                menuTreeMgr.add(new TreeEntryAddAction(menuTree, LOCATION_AFTER));
                menuTreeMgr.add(new TreeEntryAddAction(menuTree, LOCATION_UNDER));
                menuTreeMgr.add(new TreeEntryDeleteAction(menuTree));
                menuTreeMgr.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
            }
        });
        menuTree.addDoubleClickListener(new IDoubleClickListener() {

            public void doubleClick(DoubleClickEvent event) {
                (new TreeEntryEditAction(menuTree)).run();
            }
        });
        Menu menu = menuTreeMgr.createContextMenu(menuTree.getControl());
        menuTree.getControl().setMenu(menu);
        getSite().registerContextMenu(menuTreeMgr, menuTree);
        refreshData();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ModifyListener(org.eclipse.swt.events.ModifyListener) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Label(org.eclipse.swt.widgets.Label) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) EImage(com.amalto.workbench.image.EImage) Image(org.eclipse.swt.graphics.Image) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) List(org.eclipse.swt.widgets.List) ArrayList(java.util.ArrayList) WSMenu(com.amalto.workbench.webservices.WSMenu) Menu(org.eclipse.swt.widgets.Menu) WSMenuEntry(com.amalto.workbench.webservices.WSMenuEntry) Composite(org.eclipse.swt.widgets.Composite) WSMenuMenuEntriesDescriptions(com.amalto.workbench.webservices.WSMenuMenuEntriesDescriptions) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IMenuListener(org.eclipse.jface.action.IMenuListener) WSMenu(com.amalto.workbench.webservices.WSMenu) GridData(org.eclipse.swt.layout.GridData) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) TreeObject(com.amalto.workbench.models.TreeObject) DropTarget(org.eclipse.swt.dnd.DropTarget) IMenuManager(org.eclipse.jface.action.IMenuManager) LabelProvider(org.eclipse.jface.viewers.LabelProvider) Separator(org.eclipse.jface.action.Separator)

Example 2 with WSMenuMenuEntriesDescriptions

use of com.amalto.workbench.webservices.WSMenuMenuEntriesDescriptions in project tmdm-studio-se by Talend.

the class Bean2EObjUtilTest method initBean.

private void initBean(WSMenu menu) {
    // $NON-NLS-1$
    menu.setDescription("this is a description");
    // $NON-NLS-1$
    menu.setName("menuA");
    // 
    List<WSMenuEntry> menuEntries = new ArrayList<WSMenuEntry>();
    WSMenuEntry menuEntry = new WSMenuEntry();
    // $NON-NLS-1$
    menuEntry.setApplication("application A");
    // $NON-NLS-1$
    menuEntry.setContext("contextA");
    // $NON-NLS-1$
    menuEntry.setIcon("icon A");
    // $NON-NLS-1$
    menuEntry.setId("id A");
    WSMenuMenuEntriesDescriptions ds = new WSMenuMenuEntriesDescriptions();
    // $NON-NLS-1$
    ds.setLabel("label A");
    // $NON-NLS-1$
    ds.setLanguage("En");
    menuEntry.getDescriptions().add(ds);
    menuEntries.add(menuEntry);
    // 
    menuEntry = new WSMenuEntry();
    // $NON-NLS-1$
    menuEntry.setApplication("application B");
    // $NON-NLS-1$
    menuEntry.setContext("contextB");
    // $NON-NLS-1$
    menuEntry.setIcon("icon B");
    // $NON-NLS-1$
    menuEntry.setId("id B");
    menuEntries.add(menuEntry);
    // 
    menu.getMenuEntries().add(menuEntry);
}
Also used : WSMenuMenuEntriesDescriptions(com.amalto.workbench.webservices.WSMenuMenuEntriesDescriptions) ArrayList(java.util.ArrayList) WSMenuEntry(com.amalto.workbench.webservices.WSMenuEntry)

Aggregations

WSMenuEntry (com.amalto.workbench.webservices.WSMenuEntry)2 WSMenuMenuEntriesDescriptions (com.amalto.workbench.webservices.WSMenuMenuEntriesDescriptions)2 ArrayList (java.util.ArrayList)2 EImage (com.amalto.workbench.image.EImage)1 TreeObject (com.amalto.workbench.models.TreeObject)1 WSMenu (com.amalto.workbench.webservices.WSMenu)1 IMenuListener (org.eclipse.jface.action.IMenuListener)1 IMenuManager (org.eclipse.jface.action.IMenuManager)1 MenuManager (org.eclipse.jface.action.MenuManager)1 Separator (org.eclipse.jface.action.Separator)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 Viewer (org.eclipse.jface.viewers.Viewer)1 DropTarget (org.eclipse.swt.dnd.DropTarget)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1