Search in sources :

Example 1 with ComparableIncrement

use of com.devonfw.cobigen.eclipse.generator.entity.ComparableIncrement in project cobigen by devonfw.

the class SelectIncrementContentProvider method getAllPaths.

/**
 * Returns all paths for the given element
 *
 * @param element for which all paths should be determined
 * @return array of {@link TreePath}s ending on the given element
 */
public TreePath[] getAllPaths(Object element) {
    Set<TreePath> paths = new HashSet<>();
    if (element instanceof ComparableIncrement) {
        for (ComparableIncrement increment : this.rootElements) {
            TreePath path = TreePath.EMPTY.createChildPath(increment);
            if (increment.equals(element)) {
                paths.add(path);
            }
            addTreePaths(element, path, paths, false);
        }
    }
    return paths.toArray(new TreePath[0]);
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) ComparableIncrement(com.devonfw.cobigen.eclipse.generator.entity.ComparableIncrement) HashSet(java.util.HashSet)

Example 2 with ComparableIncrement

use of com.devonfw.cobigen.eclipse.generator.entity.ComparableIncrement in project cobigen by devonfw.

the class CobiGenWrapper method getOverridingFiles.

/**
 * Returns project dependent paths of all resources which are marked to be overridable (just of
 * {@link #getCurrentRepresentingInput()})
 *
 * @param increments to be considered
 * @return The set of all overridable project dependent file paths
 */
public Set<String> getOverridingFiles(Collection<IncrementTo> increments) {
    if (increments.contains(new ComparableIncrement(ALL_INCREMENT_ID, ALL_INCREMENT_NAME, null, Lists.<TemplateTo>newLinkedList(), Lists.<IncrementTo>newLinkedList()))) {
        increments = this.cobiGen.getMatchingIncrements(getCurrentRepresentingInput());
    }
    Set<String> overridablePaths = Sets.newHashSet();
    Map<String, Set<TemplateTo>> templateDestinationPaths = getTemplateDestinationPaths(increments);
    for (Entry<String, Set<TemplateTo>> entry : templateDestinationPaths.entrySet()) {
        if (isOverridableFile(entry.getValue())) {
            overridablePaths.add(entry.getKey());
        }
    }
    return overridablePaths;
}
Also used : IncrementTo(com.devonfw.cobigen.api.to.IncrementTo) HashSet(java.util.HashSet) Set(java.util.Set) ComparableIncrement(com.devonfw.cobigen.eclipse.generator.entity.ComparableIncrement) TemplateTo(com.devonfw.cobigen.api.to.TemplateTo)

Example 3 with ComparableIncrement

use of com.devonfw.cobigen.eclipse.generator.entity.ComparableIncrement in project cobigen by devonfw.

the class CobiGenWrapper method getAllIncrements.

/**
 * @return all available increments
 */
public ComparableIncrement[] getAllIncrements() {
    Set<ComparableIncrement> result = Sets.newHashSet();
    List<IncrementTo> matchingIncrements = Lists.newLinkedList();
    if (this.inputs != null && this.inputs.size() != 0) {
        for (Object input : this.cobiGen.resolveContainers(this.inputs.get(0))) {
            matchingIncrements.addAll(this.cobiGen.getMatchingIncrements(input));
        }
    }
    // convert to comparable increments
    for (IncrementTo increment : matchingIncrements) {
        result.add(new ComparableIncrement(increment.getId(), increment.getDescription(), increment.getTriggerId(), increment.getTemplates(), increment.getDependentIncrements()));
    }
    // add "all" increment, which should include all possible templates
    ComparableIncrement all = new ComparableIncrement(ALL_INCREMENT_ID, ALL_INCREMENT_NAME, null, Lists.<TemplateTo>newLinkedList(), Lists.<IncrementTo>newLinkedList());
    for (TemplateTo t : this.matchingTemplates) {
        all.addTemplate(t);
    }
    result.add(all);
    ComparableIncrement[] array = result.toArray(new ComparableIncrement[0]);
    Arrays.sort(array);
    LOG.debug("Available Increments: {}", result);
    return array;
}
Also used : IncrementTo(com.devonfw.cobigen.api.to.IncrementTo) ComparableIncrement(com.devonfw.cobigen.eclipse.generator.entity.ComparableIncrement) TemplateTo(com.devonfw.cobigen.api.to.TemplateTo)

Example 4 with ComparableIncrement

use of com.devonfw.cobigen.eclipse.generator.entity.ComparableIncrement in project cobigen by devonfw.

the class CobiGenWrapper method getMergeableFiles.

/**
 * Returns project dependent paths of all resources which are marked to be mergeable (just of
 * {@link #getCurrentRepresentingInput()})
 *
 * @param increments to be considered
 * @return The set of all mergeable project dependent file paths
 */
public Set<String> getMergeableFiles(Collection<IncrementTo> increments) {
    if (increments.contains(new ComparableIncrement(ALL_INCREMENT_ID, ALL_INCREMENT_NAME, null, Lists.<TemplateTo>newLinkedList(), Lists.<IncrementTo>newLinkedList()))) {
        increments = this.cobiGen.getMatchingIncrements(getCurrentRepresentingInput());
    }
    Set<String> mergeablePaths = Sets.newHashSet();
    Map<String, Set<TemplateTo>> templateDestinationPaths = getTemplateDestinationPaths(increments);
    for (Entry<String, Set<TemplateTo>> entry : templateDestinationPaths.entrySet()) {
        if (isMergableFile(entry.getValue())) {
            mergeablePaths.add(entry.getKey());
        }
    }
    return mergeablePaths;
}
Also used : IncrementTo(com.devonfw.cobigen.api.to.IncrementTo) HashSet(java.util.HashSet) Set(java.util.Set) ComparableIncrement(com.devonfw.cobigen.eclipse.generator.entity.ComparableIncrement) TemplateTo(com.devonfw.cobigen.api.to.TemplateTo)

Example 5 with ComparableIncrement

use of com.devonfw.cobigen.eclipse.generator.entity.ComparableIncrement in project cobigen by devonfw.

the class SelectFilesPage method saveSelection.

/**
 * Saves the current package selection
 */
public void saveSelection() {
    if (!this.rememberSelection.getSelection()) {
        return;
    }
    IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(Activator.PLUGIN_ID);
    Preferences selection = preferences.node("selection");
    TreeItem[] items = this.incrementSelector.getTree().getItems();
    for (int i = 0; i < items.length; i++) {
        ComparableIncrement element = (ComparableIncrement) items[i].getData();
        if (element.getTriggerId() != null) {
            if (items[i].getChecked()) {
                selection.node(element.getTriggerId()).put(element.getId(), CHECK_STATE.CHECKED.name());
            } else {
                selection.node(element.getTriggerId()).put(element.getId(), CHECK_STATE.UNCHECKED.name());
            }
        } else if (element.getId().equals(CobiGenWrapper.ALL_INCREMENT_ID)) {
            if (items[i].getChecked()) {
                selection.node(CobiGenWrapper.ALL_INCREMENT_NAME).put(element.getId(), CHECK_STATE.CHECKED.name());
            } else {
                selection.node(CobiGenWrapper.ALL_INCREMENT_NAME).put(element.getId(), CHECK_STATE.UNCHECKED.name());
            }
        }
    }
    try {
        preferences.flush();
    } catch (BackingStoreException e) {
        LOG.error("Error while flushing last selection into preferences.", e);
    }
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) TreeItem(org.eclipse.swt.widgets.TreeItem) BackingStoreException(org.osgi.service.prefs.BackingStoreException) Preferences(org.osgi.service.prefs.Preferences) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) ComparableIncrement(com.devonfw.cobigen.eclipse.generator.entity.ComparableIncrement)

Aggregations

ComparableIncrement (com.devonfw.cobigen.eclipse.generator.entity.ComparableIncrement)8 HashSet (java.util.HashSet)4 IncrementTo (com.devonfw.cobigen.api.to.IncrementTo)3 TemplateTo (com.devonfw.cobigen.api.to.TemplateTo)3 Set (java.util.Set)2 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)2 TreeItem (org.eclipse.swt.widgets.TreeItem)2 Preferences (org.osgi.service.prefs.Preferences)2 TreePath (org.eclipse.jface.viewers.TreePath)1 BackingStoreException (org.osgi.service.prefs.BackingStoreException)1