Search in sources :

Example 1 with CatalogItemEntry

use of org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.CatalogItemEntry in project epp.mpc by eclipse.

the class MarketplaceWizard method computeNewInstallCatalogItems.

private Set<CatalogItem> computeNewInstallCatalogItems() {
    Set<CatalogItem> items = new HashSet<CatalogItem>();
    Map<CatalogItem, Collection<String>> iusByCatalogItem = new HashMap<CatalogItem, Collection<String>>();
    for (CatalogItemEntry entry : getSelectionModel().getCatalogItemEntries()) {
        List<FeatureEntry> features = entry.getChildren();
        Collection<String> featureIds = new ArrayList<String>(features.size());
        for (FeatureEntry feature : features) {
            if (feature.computeChangeOperation() == Operation.INSTALL) {
                featureIds.add(feature.getFeatureDescriptor().getId());
            }
        }
        if (!featureIds.isEmpty()) {
            iusByCatalogItem.put(entry.getItem(), featureIds);
        }
    }
    for (IInstallableUnit unit : operationIUs) {
        for (Entry<CatalogItem, Collection<String>> entry : iusByCatalogItem.entrySet()) {
            if (entry.getValue().contains(unit.getId())) {
                items.add(entry.getKey());
            }
        }
    }
    return items;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem) FeatureEntry(org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.FeatureEntry) CatalogItemEntry(org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.CatalogItemEntry) Collection(java.util.Collection) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) HashSet(java.util.HashSet)

Example 2 with CatalogItemEntry

use of org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.CatalogItemEntry in project epp.mpc by eclipse.

the class FeatureSelectionWizardPage method computeCheckedViewerState.

public void computeCheckedViewerState() {
    // compute which ones should be checked. (update scenario where only part of a feature is installed)
    List<Object> checkedElements = new ArrayList<Object>();
    List<Object> grayCheckedElements = new ArrayList<Object>();
    for (CatalogItemEntry entry : getWizard().getSelectionModel().getCatalogItemEntries()) {
        int childCheckCount = 0;
        boolean childGrayed = false;
        for (FeatureEntry child : entry.getChildren()) {
            if (child.isChecked()) {
                checkedElements.add(child);
                ++childCheckCount;
            }
        }
        if (childCheckCount > 0) {
            for (FeatureEntry child : entry.getChildren()) {
                if (!child.isChecked() && !child.getInstallableUnitItem().isOptional()) {
                    child.setChecked(true);
                    checkedElements.add(child);
                    ++childCheckCount;
                }
            }
        }
        for (FeatureEntry child : entry.getChildren()) {
            if (child.isGrayed()) {
                checkedElements.add(child);
                grayCheckedElements.add(child);
                childGrayed = true;
            }
        }
        if (childCheckCount == entry.getChildren().size()) {
            checkedElements.add(entry);
        } else if (childCheckCount > 0 || childGrayed) {
            grayCheckedElements.add(entry);
            checkedElements.add(entry);
        }
    }
    viewer.setCheckedElements(checkedElements.toArray());
    viewer.setGrayedElements(grayCheckedElements.toArray());
    viewer.refresh(true);
}
Also used : FeatureEntry(org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.FeatureEntry) ArrayList(java.util.ArrayList) CatalogItemEntry(org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.CatalogItemEntry)

Example 3 with CatalogItemEntry

use of org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.CatalogItemEntry in project epp.mpc by eclipse.

the class FeatureSelectionWizardPage method updateSelectionModel.

private void updateSelectionModel(Set<FeatureDescriptor> featureDescriptors) {
    Map<String, FeatureDescriptor> descriptorById = new HashMap<String, FeatureDescriptor>();
    for (FeatureDescriptor fd : featureDescriptors) {
        descriptorById.put(fd.getId(), fd);
    }
    SelectionModel selectionModel = getWizard().getSelectionModel();
    for (CatalogItemEntry entry : selectionModel.getCatalogItemEntries()) {
        for (FeatureEntry child : entry.getChildren()) {
            FeatureDescriptor descriptor = descriptorById.get(child.getFeatureDescriptor().getId());
            if (descriptor != null) {
                child.setFeatureDescriptor(descriptor);
            }
        }
    }
}
Also used : FeatureEntry(org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.FeatureEntry) FeatureDescriptor(org.eclipse.epp.internal.mpc.ui.operations.FeatureDescriptor) HashMap(java.util.HashMap) CatalogItemEntry(org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.CatalogItemEntry) StyledString(org.eclipse.jface.viewers.StyledString)

Example 4 with CatalogItemEntry

use of org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.CatalogItemEntry in project epp.mpc by eclipse.

the class FeatureSelectionWizardPage method createControl.

public void createControl(Composite parent) {
    container = new Composite(parent, SWT.NONE);
    switchResultLayout = new StackLayout();
    container.setLayout(switchResultLayout);
    GridData data = new GridData(GridData.FILL_BOTH);
    container.setLayoutData(data);
    defaultComposite = new Composite(container, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(1).applyTo(defaultComposite);
    Composite treeContainer = new Composite(defaultComposite, SWT.NULL);
    GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(treeContainer);
    TreeColumnLayout columnLayout = new TreeColumnLayout();
    treeContainer.setLayout(columnLayout);
    viewer = new CheckboxTreeViewer(treeContainer, SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    viewer.setUseHashlookup(true);
    viewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            if (e1 == e2) {
                return 0;
            }
            String s1;
            String s2;
            if (e1 instanceof CatalogItemEntry) {
                s1 = ((CatalogItemEntry) e1).getItem().getName();
                s2 = ((CatalogItemEntry) e2).getItem().getName();
            } else {
                FeatureEntry fe1 = (FeatureEntry) e1;
                FeatureEntry fe2 = (FeatureEntry) e2;
                if (fe1.getInstallableUnitItem().isOptional() != fe2.getInstallableUnitItem().isOptional()) {
                    // required items first
                    return fe1.getInstallableUnitItem().isOptional() ? 1 : -1;
                }
                s1 = fe1.getFeatureDescriptor().getName();
                s2 = fe2.getFeatureDescriptor().getName();
            }
            int i = s1.compareToIgnoreCase(s2);
            if (i == 0) {
                i = s1.compareTo(s2);
                if (i == 0) {
                    i = new Integer(System.identityHashCode(e1)).compareTo(System.identityHashCode(e2));
                }
            }
            return i;
        }
    });
    viewer.setContentProvider(new ContentProvider());
    viewer.setInput(getWizard().getSelectionModel());
    viewer.addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(CheckStateChangedEvent event) {
            boolean checked = event.getChecked();
            if (event.getElement() instanceof CatalogItemEntry) {
                CatalogItemEntry entry = (CatalogItemEntry) event.getElement();
                for (FeatureEntry child : entry.getChildren()) {
                    child.setChecked(checked);
                }
            } else if (event.getElement() instanceof FeatureEntry) {
                FeatureEntry featureEntry = (FeatureEntry) event.getElement();
                featureEntry.setChecked(checked);
            }
            refreshState();
        }
    });
    column = new TreeViewerColumn(viewer, SWT.NONE);
    column.setLabelProvider(new DelegatingStyledCellLabelProvider(new LabelProvider()));
    columnLayout.setColumnData(column.getColumn(), new ColumnWeightData(100, 100, true));
    detailsControl = new Group(defaultComposite, SWT.SHADOW_IN);
    detailsControl.setText(Messages.FeatureSelectionWizardPage_details);
    GridDataFactory.fillDefaults().grab(true, false).hint(SWT.DEFAULT, 300).exclude(true).applyTo(detailsControl);
    GridLayoutFactory.fillDefaults().applyTo(detailsControl);
    detailStatusText = new Text(detailsControl, SWT.MULTI | SWT.READ_ONLY | SWT.WRAP | SWT.V_SCROLL);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(detailStatusText);
    setControl(container);
    Dialog.applyDialogFont(container);
    MarketplaceClientUi.setDefaultHelp(getControl());
    flipToDefaultComposite();
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) RemediationGroup(org.eclipse.equinox.internal.p2.ui.dialogs.RemediationGroup) Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) Viewer(org.eclipse.jface.viewers.Viewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) Text(org.eclipse.swt.widgets.Text) StyledString(org.eclipse.jface.viewers.StyledString) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) FeatureEntry(org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.FeatureEntry) StackLayout(org.eclipse.swt.custom.StackLayout) GridData(org.eclipse.swt.layout.GridData) CatalogItemEntry(org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.CatalogItemEntry) DelegatingStyledCellLabelProvider(org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) DelegatingStyledCellLabelProvider(org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider) IStyledLabelProvider(org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider)

Aggregations

CatalogItemEntry (org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.CatalogItemEntry)4 FeatureEntry (org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.FeatureEntry)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 StyledString (org.eclipse.jface.viewers.StyledString)2 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 FeatureDescriptor (org.eclipse.epp.internal.mpc.ui.operations.FeatureDescriptor)1 CatalogItem (org.eclipse.equinox.internal.p2.discovery.model.CatalogItem)1 RemediationGroup (org.eclipse.equinox.internal.p2.ui.dialogs.RemediationGroup)1 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)1 TreeColumnLayout (org.eclipse.jface.layout.TreeColumnLayout)1 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)1 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)1 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)1 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)1 DelegatingStyledCellLabelProvider (org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider)1 IStyledLabelProvider (org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider)1 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)1 ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)1