Search in sources :

Example 1 with IPaletteItem

use of org.talend.core.ui.component.preference.provider.IPaletteItem in project tdi-studio-se by Talend.

the class PaletteSettingPage method addTreeViewer.

/**
     * qwei Comment method "addViewer".
     * 
     * @param parent
     */
private void addTreeViewer(ThreeCompositesSashForm parent) {
    ViewerSorter sorter = new ViewerSorter() {

        /*
             * (non-Javadoc)
             * 
             * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer,
             * java.lang.Object, java.lang.Object)
             */
        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            if (e1 instanceof ComponentPaletteItem && e2 instanceof ComponentPaletteItem) {
                return super.compare(viewer, ((IPaletteItem) e1).getLabel(), ((IPaletteItem) e2).getLabel());
            } else if (e1 instanceof FolderPaletteItem && e2 instanceof FolderPaletteItem) {
                return super.compare(viewer, ((IPaletteItem) e1).getLabel(), ((IPaletteItem) e2).getLabel());
            } else if (e1 instanceof ComponentPaletteItem && e2 instanceof FolderPaletteItem) {
                return 1;
            } else if (e1 instanceof FolderPaletteItem && e2 instanceof ComponentPaletteItem) {
                return -1;
            } else if (e1 instanceof RootPaletteItem && e2 instanceof RootPaletteItem) {
                if (((IPaletteItem) e1).getPaletteType() == ComponentCategory.CATEGORY_4_DI) {
                    // up
                    return -1;
                } else if (((IPaletteItem) e2).getPaletteType() == ComponentCategory.CATEGORY_4_DI) {
                    // down
                    return 1;
                } else if (((IPaletteItem) e1).getPaletteType() == ComponentCategory.CATEGORY_4_CAMEL && ((IPaletteItem) e2).getPaletteType() == ComponentCategory.CATEGORY_4_MAPREDUCE) {
                    // up
                    return -1;
                } else if (((IPaletteItem) e1).getPaletteType() == ComponentCategory.CATEGORY_4_MAPREDUCE && ((IPaletteItem) e2).getPaletteType() == ComponentCategory.CATEGORY_4_CAMEL) {
                    // down
                    return 1;
                } else if (((IPaletteItem) e1).getPaletteType() == ComponentCategory.CATEGORY_4_MAPREDUCE && ((IPaletteItem) e2).getPaletteType() == ComponentCategory.CATEGORY_4_STORM) {
                    // up
                    return -1;
                } else if (((IPaletteItem) e1).getPaletteType() == ComponentCategory.CATEGORY_4_STORM && ((IPaletteItem) e2).getPaletteType() == ComponentCategory.CATEGORY_4_MAPREDUCE) {
                    // down
                    return 1;
                } else if (((IPaletteItem) e1).getPaletteType() == ComponentCategory.CATEGORY_4_CAMEL && ((IPaletteItem) e2).getPaletteType() == ComponentCategory.CATEGORY_4_STORM) {
                    // up
                    return -1;
                } else if (((IPaletteItem) e1).getPaletteType() == ComponentCategory.CATEGORY_4_STORM && ((IPaletteItem) e2).getPaletteType() == ComponentCategory.CATEGORY_4_CAMEL) {
                    // down
                    return 1;
                }
            }
            return super.compare(viewer, e1, e2);
        }
    };
    List<IPaletteItem> input = getViewerInput();
    Composite leftComposite = parent.getLeftComposite();
    Label label = new Label(leftComposite, SWT.NONE);
    label.setText("Hide");
    hiddenViewer = new TreeViewer(leftComposite);
    hiddenViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
    hiddenViewer.setContentProvider(new TalendPaletteTreeProvider());
    hiddenViewer.setLabelProvider(new TalendPaletteLabelProvider());
    hiddenViewer.addFilter(getFilterForComponent(false));
    hiddenViewer.setSorter(sorter);
    hiddenViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            displayComponentsButton.setEnabled(!event.getSelection().isEmpty());
        }
    });
    createButtons(parent.getMidComposite());
    Composite rightComposite = parent.getRightComposite();
    label = new Label(rightComposite, SWT.NONE);
    label.setText("Show");
    displayViewer = new TreeViewer(rightComposite);
    displayViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
    displayViewer.setContentProvider(new TalendPaletteTreeProvider());
    displayViewer.setLabelProvider(new TalendPaletteLabelProvider());
    displayViewer.addFilter(getFilterForComponent(true));
    displayViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            hideCompnentsButton.setEnabled(!event.getSelection().isEmpty());
        }
    });
    displayViewer.setSorter(sorter);
    getComponentsFromProject(project);
    hiddenViewer.setInput(input);
    displayViewer.setInput(input);
    if (!input.isEmpty()) {
        displayViewer.expandToLevel(input.get(0), 1);
    }
    if (!input.isEmpty()) {
        hiddenViewer.expandToLevel(input.get(0), 1);
    }
}
Also used : ComponentPaletteItem(org.talend.repository.preference.palettesettings.ComponentPaletteItem) Composite(org.eclipse.swt.widgets.Composite) IPaletteItem(org.talend.core.ui.component.preference.provider.IPaletteItem) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ViewerSorter(org.eclipse.jface.viewers.ViewerSorter) Label(org.eclipse.swt.widgets.Label) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FolderPaletteItem(org.talend.repository.preference.palettesettings.FolderPaletteItem) TalendPaletteTreeProvider(org.talend.core.ui.component.preference.provider.TalendPaletteTreeProvider) RootPaletteItem(org.talend.repository.preference.palettesettings.RootPaletteItem) GridData(org.eclipse.swt.layout.GridData) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) TalendPaletteLabelProvider(org.talend.core.ui.component.preference.provider.TalendPaletteLabelProvider)

Example 2 with IPaletteItem

use of org.talend.core.ui.component.preference.provider.IPaletteItem in project tdi-studio-se by Talend.

the class PaletteItemHelper method getRootPaletteItem.

/**
     * DOC nrousseau Comment method "getRootPaletteItem".
     * 
     * @param valueOf
     * @param paletteItems
     * @return
     */
private static IPaletteItem getRootPaletteItem(ComponentCategory category, List<IPaletteItem> paletteItems) {
    for (IPaletteItem paletteItem : paletteItems) {
        if (paletteItem.getPaletteType() == category) {
            return paletteItem;
        }
    }
    try {
        IPaletteItem rootPaletteItem = new RootPaletteItem(category);
        paletteItems.add(rootPaletteItem);
        return rootPaletteItem;
    } catch (AssertionFailedException e) {
        // if go here,means can not get the paletteItem for the componentCatgory,just return null
        return null;
    }
}
Also used : IPaletteItem(org.talend.core.ui.component.preference.provider.IPaletteItem) AssertionFailedException(org.eclipse.core.runtime.AssertionFailedException)

Example 3 with IPaletteItem

use of org.talend.core.ui.component.preference.provider.IPaletteItem in project tdi-studio-se by Talend.

the class PaletteItemHelper method createPaletteItems.

/**
     * DOC nrousseau Comment method "createPaletteItems".
     * 
     * @param component
     * @param paletteItems
     */
private static void createPaletteItems(IComponent component, List<IPaletteItem> paletteItems) {
    String[] originalFamilies = component.getOriginalFamilyName().split(ComponentsFactoryProvider.FAMILY_SEPARATOR_REGEX);
    String[] translatedFamilies = component.getTranslatedFamilyName().split(ComponentsFactoryProvider.FAMILY_SEPARATOR_REGEX);
    if (originalFamilies.length != translatedFamilies.length) {
        // this case should not happen, but in this case we just don't care about the translated one.
        translatedFamilies = originalFamilies;
    }
    IPaletteItem rootPaletteItem = getRootPaletteItem(ComponentCategory.getComponentCategoryFromName(component.getPaletteType()), paletteItems);
    if (rootPaletteItem != null) {
        for (int i = 0; i < originalFamilies.length; i++) {
            String origFamily = originalFamilies[i];
            String translFamily = translatedFamilies[i];
            IPaletteItem parentPaletteItem = getFamilyItem(translFamily, rootPaletteItem);
            IPaletteItem componentItem = new ComponentPaletteItem(component, origFamily);
            parentPaletteItem.getChildren().add(componentItem);
            componentItem.setParent(parentPaletteItem);
        }
    }
}
Also used : IPaletteItem(org.talend.core.ui.component.preference.provider.IPaletteItem)

Example 4 with IPaletteItem

use of org.talend.core.ui.component.preference.provider.IPaletteItem in project tdi-studio-se by Talend.

the class PaletteItemHelper method buildFullPaletteItemList.

public static List<IPaletteItem> buildFullPaletteItemList() {
    List<IPaletteItem> paletteItems = new ArrayList<IPaletteItem>();
    Set<IComponent> components = ComponentsFactoryProvider.getInstance().getComponents();
    // for family folders
    for (IComponent component : components) {
        if (component.isTechnical() || component.getComponentType() == EComponentType.JOBLET) {
            continue;
        }
        createPaletteItems(component, paletteItems);
    }
    return paletteItems;
}
Also used : IPaletteItem(org.talend.core.ui.component.preference.provider.IPaletteItem) IComponent(org.talend.core.model.components.IComponent) ArrayList(java.util.ArrayList)

Example 5 with IPaletteItem

use of org.talend.core.ui.component.preference.provider.IPaletteItem in project tdi-studio-se by Talend.

the class PaletteSettingPage method setComponentVisible.

/**
     * set the selected component as visible or not
     * 
     * @param selection
     * @param b
     */
protected void setComponentVisible(ISelection selection, boolean visible) {
    IStructuredSelection sel = (IStructuredSelection) selection;
    Set<IPaletteItem> items = new HashSet<IPaletteItem>();
    for (Iterator iterator = sel.iterator(); iterator.hasNext(); ) {
        IPaletteItem entry = (IPaletteItem) iterator.next();
        retrieveAllEntry(items, entry);
    }
    Set<IComponent> usedComponents = getComponentsUsedInProject(ProjectManager.getInstance().getCurrentProject());
    boolean isUsed = false;
    for (IPaletteItem item : items) {
        if (!visible && item instanceof ComponentPaletteItem) {
            if (usedComponents.contains(((ComponentPaletteItem) item).getComponent())) {
                isUsed = true;
                continue;
            }
        }
        setComponentVisible(item, visible);
    }
    if (isUsed) {
        MessageDialog messageDialog = new MessageDialog(getShell(), //$NON-NLS-1$
        Messages.getString("PaletteSettingPage.paletteSettings"), //$NON-NLS-1$
        null, //$NON-NLS-1$ //$NON-NLS-2$
        Messages.getString("PaletteSettingPage.selection1") + "\n" + //$NON-NLS-1$
        Messages.getString("PaletteSettingPage.selection2"), //$NON-NLS-1$
        MessageDialog.INFORMATION, new String[] { "OK" }, //$NON-NLS-1$
        0);
        messageDialog.open();
    }
    refreshViewer();
}
Also used : ComponentPaletteItem(org.talend.repository.preference.palettesettings.ComponentPaletteItem) IPaletteItem(org.talend.core.ui.component.preference.provider.IPaletteItem) IComponent(org.talend.core.model.components.IComponent) Iterator(java.util.Iterator) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) HashSet(java.util.HashSet)

Aggregations

IPaletteItem (org.talend.core.ui.component.preference.provider.IPaletteItem)7 ComponentPaletteItem (org.talend.repository.preference.palettesettings.ComponentPaletteItem)3 IComponent (org.talend.core.model.components.IComponent)2 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 AssertionFailedException (org.eclipse.core.runtime.AssertionFailedException)1 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerSorter (org.eclipse.jface.viewers.ViewerSorter)1 GridData (org.eclipse.swt.layout.GridData)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 TalendPaletteLabelProvider (org.talend.core.ui.component.preference.provider.TalendPaletteLabelProvider)1 TalendPaletteTreeProvider (org.talend.core.ui.component.preference.provider.TalendPaletteTreeProvider)1