Search in sources :

Example 1 with ResourceVersionData

use of com.redhat.devtools.intellij.tektoncd.hub.model.ResourceVersionData in project intellij-tekton by redhat-developer.

the class HubDetailsPageComponent method createMetricsPanel.

private void createMetricsPanel(@NotNull JPanel centerPanel) {
    versionsCmb = new ComboBox();
    BasicComboBoxRenderer versionCmbRenderer = new BasicComboBoxRenderer() {

        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (value instanceof ResourceVersionData) {
                ResourceVersionData version = (ResourceVersionData) value;
                setText(version.getVersion());
            }
            return this;
        }
    };
    versionsCmb.setRenderer(versionCmbRenderer);
    versionsCmb.addItemListener(e -> {
        if (e.getStateChange() == ItemEvent.SELECTED) {
            ResourceVersionData versionSelected = (ResourceVersionData) e.getItem();
            loadBottomTabs(versionSelected.getDisplayName(), versionSelected.getRawURL());
        }
    });
    myRating = new JLabel("", AllIcons.Plugins.Rating, SwingConstants.CENTER);
    myRating.setOpaque(false);
    myRating.setIconTextGap(2);
    myRating.setForeground(GRAY_COLOR);
    JPanel metricsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    metricsPanel.setBackground(MAIN_BG_COLOR);
    metricsPanel.add(myRating);
    metricsPanel.add(versionsCmb);
    centerPanel.add(metricsPanel);
}
Also used : BasicComboBoxRenderer(javax.swing.plaf.basic.BasicComboBoxRenderer) JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ResourceVersionData(com.redhat.devtools.intellij.tektoncd.hub.model.ResourceVersionData) JComboBox(javax.swing.JComboBox) ComboBox(com.intellij.openapi.ui.ComboBox) JLabel(javax.swing.JLabel) JList(javax.swing.JList)

Example 2 with ResourceVersionData

use of com.redhat.devtools.intellij.tektoncd.hub.model.ResourceVersionData in project intellij-tekton by redhat-developer.

the class HubDetailsPageComponent method show.

public void show(HubItem item, TriConsumer<HubItem, String, String> doInstallAction) {
    if (item == null) {
        select(1, true);
    } else {
        ResourceData resource = item.getResource();
        ResourceVersionData resourceVersionData = getHubItemResourceVersionData(item);
        if (resourceVersionData == null) {
            return;
        }
        setInstallButtons(item, doInstallAction);
        setNameLabel(resourceVersionData, resource.getName());
        fillVersionsCombo(resource, resourceVersionData);
        myRating.setText(resource.getRating().toString());
        myHomePage.show(resource.getKind() + " Homepage", () -> {
            try {
                Desktop.getDesktop().browse(resourceVersionData.getWebURL());
            } catch (IOException e) {
                logger.warn(e.getLocalizedMessage(), e);
            }
        });
        setDetailsPanel(resource, resourceVersionData);
        loadBottomTabs(resource.getName(), resourceVersionData.getRawURL());
        select(0, true);
    }
}
Also used : ResourceData(com.redhat.devtools.intellij.tektoncd.hub.model.ResourceData) ResourceVersionData(com.redhat.devtools.intellij.tektoncd.hub.model.ResourceVersionData) IOException(java.io.IOException)

Example 3 with ResourceVersionData

use of com.redhat.devtools.intellij.tektoncd.hub.model.ResourceVersionData in project intellij-tekton by redhat-developer.

the class HubItemScoreTest method buildHubItem.

private HubItem buildHubItem(String name, String description, List<Tag> tags) {
    ResourceData resourceData = mock(ResourceData.class);
    ResourceVersionData resourceVersionData = mock(ResourceVersionData.class);
    when(resourceData.getLatestVersion()).thenReturn(resourceVersionData);
    when(resourceVersionData.getVersion()).thenReturn("v1");
    when(resourceVersionData.getDescription()).thenReturn(description);
    when(resourceData.getName()).thenReturn(name);
    when(resourceData.getKind()).thenReturn("kind");
    when(resourceData.getTags()).thenReturn(tags);
    HubItem hubItem = new HubItem(resourceData);
    return hubItem;
}
Also used : ResourceData(com.redhat.devtools.intellij.tektoncd.hub.model.ResourceData) ResourceVersionData(com.redhat.devtools.intellij.tektoncd.hub.model.ResourceVersionData)

Example 4 with ResourceVersionData

use of com.redhat.devtools.intellij.tektoncd.hub.model.ResourceVersionData in project intellij-tekton by redhat-developer.

the class HubModel method getVersionsById.

public List<ResourceVersionData> getVersionsById(int id) {
    List<ResourceVersionData> versions = new ArrayList<>();
    Optional<HubItem> itemSelected = getAllHubItems().stream().filter(item -> item.getResource().getId() == id).findFirst();
    if (itemSelected.isPresent()) {
        versions = itemSelected.get().getResource().getVersions();
    }
    if (versions.isEmpty()) {
        ResourceApi res = new ResourceApi();
        try {
            versions = res.resourceVersionsByID(id).getData().getVersions();
            if (itemSelected.isPresent()) {
                itemSelected.get().getResource().setVersions(versions);
            }
        } catch (ApiException e) {
            logger.warn(e.getLocalizedMessage());
        }
    }
    return versions;
}
Also used : ResourceVersionData(com.redhat.devtools.intellij.tektoncd.hub.model.ResourceVersionData) HUB_CATALOG_TAG(com.redhat.devtools.intellij.tektoncd.Constants.HUB_CATALOG_TAG) URL(java.net.URL) RecognizerFactory(com.redhat.devtools.alizer.api.RecognizerFactory) LoggerFactory(org.slf4j.LoggerFactory) Watcher(io.fabric8.kubernetes.client.Watcher) APP_K8S_IO_VERSION(com.redhat.devtools.intellij.tektoncd.Constants.APP_K8S_IO_VERSION) ConfigWatcher(com.redhat.devtools.intellij.common.utils.ConfigWatcher) YAMLBuilder(com.redhat.devtools.intellij.tektoncd.utils.YAMLBuilder) Language(com.redhat.devtools.alizer.api.Language) Constants(com.redhat.devtools.intellij.tektoncd.Constants) KIND_TASKS(com.redhat.devtools.intellij.tektoncd.Constants.KIND_TASKS) ExecHelper(com.redhat.devtools.intellij.common.utils.ExecHelper) Map(java.util.Map) ApiCallback(com.redhat.devtools.intellij.tektoncd.hub.invoker.ApiCallback) Config(io.fabric8.kubernetes.api.model.Config) DeployHelper(com.redhat.devtools.intellij.tektoncd.utils.DeployHelper) KIND_CLUSTERTASK(com.redhat.devtools.intellij.tektoncd.Constants.KIND_CLUSTERTASK) Predicate(java.util.function.Predicate) Resources(com.redhat.devtools.intellij.tektoncd.hub.model.Resources) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Collectors(java.util.stream.Collectors) ClusterTask(io.fabric8.tekton.pipeline.v1beta1.ClusterTask) List(java.util.List) ClusterTasksNode(com.redhat.devtools.intellij.tektoncd.tree.ClusterTasksNode) Optional(java.util.Optional) ApiException(com.redhat.devtools.intellij.tektoncd.hub.invoker.ApiException) KIND_PIPELINE(com.redhat.devtools.intellij.tektoncd.Constants.KIND_PIPELINE) YAMLHelper(com.redhat.devtools.intellij.common.utils.YAMLHelper) KIND_TASK(com.redhat.devtools.intellij.tektoncd.Constants.KIND_TASK) HashMap(java.util.HashMap) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) KIND_PIPELINES(com.redhat.devtools.intellij.tektoncd.Constants.KIND_PIPELINES) Tkn(com.redhat.devtools.intellij.tektoncd.tkn.Tkn) TknCliFactory(com.redhat.devtools.intellij.tektoncd.tkn.TknCliFactory) WatcherException(io.fabric8.kubernetes.client.WatcherException) Project(com.intellij.openapi.project.Project) ResourceData(com.redhat.devtools.intellij.tektoncd.hub.model.ResourceData) ConfigHelper(com.redhat.devtools.intellij.common.utils.ConfigHelper) Pipeline(io.fabric8.tekton.pipeline.v1beta1.Pipeline) Logger(org.slf4j.Logger) PipelinesNode(com.redhat.devtools.intellij.tektoncd.tree.PipelinesNode) IOException(java.io.IOException) ParentableNode(com.redhat.devtools.intellij.tektoncd.tree.ParentableNode) InputStreamReader(java.io.InputStreamReader) ResourceApi(com.redhat.devtools.intellij.tektoncd.hub.api.ResourceApi) KIND_CLUSTERTASKS(com.redhat.devtools.intellij.tektoncd.Constants.KIND_CLUSTERTASKS) Paths(java.nio.file.Paths) BufferedReader(java.io.BufferedReader) Collections(java.util.Collections) Task(io.fabric8.tekton.pipeline.v1beta1.Task) ResourceApi(com.redhat.devtools.intellij.tektoncd.hub.api.ResourceApi) ResourceVersionData(com.redhat.devtools.intellij.tektoncd.hub.model.ResourceVersionData) ArrayList(java.util.ArrayList) ApiException(com.redhat.devtools.intellij.tektoncd.hub.invoker.ApiException)

Example 5 with ResourceVersionData

use of com.redhat.devtools.intellij.tektoncd.hub.model.ResourceVersionData in project intellij-tekton by redhat-developer.

the class HubItemScore method computeScore.

private int computeScore(HubItem hubItem) {
    int score = 0;
    ResourceData resourceData = hubItem.getResource();
    ResourceVersionData resourceVersionData = resourceData.getLatestVersion();
    for (int i = 0; i < languages.size(); i++) {
        Language language = languages.get(i);
        int multiplier = i >= LANGUAGES_MULTIPLIER.length ? LANGUAGES_MULTIPLIER[LANGUAGES_MULTIPLIER.length - 1] : LANGUAGES_MULTIPLIER[i];
        if (matches(resourceData.getName(), language)) {
            score += NAME_WEIGHT * multiplier;
        }
        if (resourceVersionData != null && matches(resourceVersionData.getDescription(), language)) {
            score += DESCRIPTION_WEIGHT * multiplier;
        }
        List<String> tags = resourceData.getTags().stream().map(c -> c.getName()).collect(Collectors.toList());
        if (resourceData.getTags().contains(language.getName()) || matches(tags, language)) {
            score += TAG_WEIGHT * multiplier;
        }
    }
    return score;
}
Also used : ResourceVersionData(com.redhat.devtools.intellij.tektoncd.hub.model.ResourceVersionData) Strings(com.google.common.base.Strings) Language(com.redhat.devtools.alizer.api.Language) List(java.util.List) ResourceData(com.redhat.devtools.intellij.tektoncd.hub.model.ResourceData) Comparator(java.util.Comparator) Collectors(java.util.stream.Collectors) ResourceData(com.redhat.devtools.intellij.tektoncd.hub.model.ResourceData) Language(com.redhat.devtools.alizer.api.Language) ResourceVersionData(com.redhat.devtools.intellij.tektoncd.hub.model.ResourceVersionData)

Aggregations

ResourceVersionData (com.redhat.devtools.intellij.tektoncd.hub.model.ResourceVersionData)5 ResourceData (com.redhat.devtools.intellij.tektoncd.hub.model.ResourceData)4 Language (com.redhat.devtools.alizer.api.Language)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Strings (com.google.common.base.Strings)1 Project (com.intellij.openapi.project.Project)1 ComboBox (com.intellij.openapi.ui.ComboBox)1 RecognizerFactory (com.redhat.devtools.alizer.api.RecognizerFactory)1 ConfigHelper (com.redhat.devtools.intellij.common.utils.ConfigHelper)1 ConfigWatcher (com.redhat.devtools.intellij.common.utils.ConfigWatcher)1 ExecHelper (com.redhat.devtools.intellij.common.utils.ExecHelper)1 YAMLHelper (com.redhat.devtools.intellij.common.utils.YAMLHelper)1 Constants (com.redhat.devtools.intellij.tektoncd.Constants)1 APP_K8S_IO_VERSION (com.redhat.devtools.intellij.tektoncd.Constants.APP_K8S_IO_VERSION)1 HUB_CATALOG_TAG (com.redhat.devtools.intellij.tektoncd.Constants.HUB_CATALOG_TAG)1 KIND_CLUSTERTASK (com.redhat.devtools.intellij.tektoncd.Constants.KIND_CLUSTERTASK)1 KIND_CLUSTERTASKS (com.redhat.devtools.intellij.tektoncd.Constants.KIND_CLUSTERTASKS)1 KIND_PIPELINE (com.redhat.devtools.intellij.tektoncd.Constants.KIND_PIPELINE)1