Search in sources :

Example 1 with Label

use of org.jboss.tools.openshift.internal.ui.wizard.common.IResourceLabelsPageModel.Label in project jbosstools-openshift by jbosstools.

the class ResourceLabelsPage method createTable.

protected TableViewer createTable(Composite tableContainer) {
    Table table = new Table(tableContainer, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL);
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    this.viewer = new TableViewerBuilder(table, tableContainer).contentProvider(new ArrayContentProvider()).<Label>column(new DelegatingStyledCellLabelProvider(new LabelTextProvider() {

        @Override
        public String getValue(Label label) {
            return label.getName();
        }
    })).name(LABEL_KEY).align(SWT.LEFT).weight(2).minWidth(100).buildColumn().<Label>column(new DelegatingStyledCellLabelProvider(new LabelTextProvider() {

        @Override
        public String getValue(Label label) {
            return label.getValue();
        }
    })).name("Value").align(SWT.LEFT).weight(2).minWidth(100).buildColumn().buildViewer();
    viewer.addDoubleClickListener(e -> editLabel((Label) ((IStructuredSelection) e.getSelection()).getFirstElement()));
    viewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            Label first = (Label) e1;
            Label other = (Label) e2;
            return first.getName().compareTo(other.getName());
        }
    });
    return viewer;
}
Also used : Table(org.eclipse.swt.widgets.Table) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) Label(org.jboss.tools.openshift.internal.ui.wizard.common.IResourceLabelsPageModel.Label) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) DelegatingStyledCellLabelProvider(org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider) StyledString(org.eclipse.jface.viewers.StyledString) TableViewerBuilder(org.jboss.tools.openshift.internal.common.ui.utils.TableViewerBuilder)

Example 2 with Label

use of org.jboss.tools.openshift.internal.ui.wizard.common.IResourceLabelsPageModel.Label in project jbosstools-openshift by jbosstools.

the class DeployImageJob method stubDeploymentConfig.

protected IResource stubDeploymentConfig(IResourceFactory factory, final String name, DockerImageURI imageUri, IImageStream is) {
    IDeploymentConfig dc = factory.stub(ResourceKind.DEPLOYMENT_CONFIG, name, parameters.getProject().getName());
    dc.addLabel(SELECTOR_KEY, name);
    dc.addTemplateLabel(SELECTOR_KEY, name);
    for (Label label : parameters.getLabels()) {
        dc.addTemplateLabel(label.getName(), label.getValue());
    }
    dc.setReplicas(parameters.getReplicas());
    dc.setReplicaSelector(SELECTOR_KEY, name);
    Map<String, String> envs = getModifiedEnvVars(parameters.getEnvironmentVariables(), parameters.getImageEnvVars());
    dc.addContainer(dc.getName(), imageUri, new HashSet<>(parameters.getPortSpecs()), envs, parameters.getVolumes());
    dc.addTrigger(DeploymentTriggerType.CONFIG_CHANGE);
    if (is != null) {
        IDeploymentImageChangeTrigger imageChangeTrigger = (IDeploymentImageChangeTrigger) dc.addTrigger(DeploymentTriggerType.IMAGE_CHANGE);
        imageChangeTrigger.setAutomatic(true);
        imageChangeTrigger.setContainerName(name);
        imageChangeTrigger.setFrom(new DockerImageURI(null, null, is.getName(), imageUri.getTag()));
        imageChangeTrigger.setKind(ResourceKind.IMAGE_STREAM_TAG);
        imageChangeTrigger.setNamespace(is.getNamespaceName());
    }
    return dc;
}
Also used : DockerImageURI(com.openshift.restclient.images.DockerImageURI) Label(org.jboss.tools.openshift.internal.ui.wizard.common.IResourceLabelsPageModel.Label) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IDeploymentImageChangeTrigger(com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger)

Example 3 with Label

use of org.jboss.tools.openshift.internal.ui.wizard.common.IResourceLabelsPageModel.Label in project jbosstools-openshift by jbosstools.

the class NewApplicationWizardModelTest method setDefaultAppLabelForImageBasedApplications.

@Test
public void setDefaultAppLabelForImageBasedApplications() {
    // pre-conditions
    IApplicationSource source = mock(IApplicationSource.class);
    when(source.getKind()).thenReturn(ResourceKind.IMAGE_STREAM);
    IImageStream imageStream = mock(IImageStream.class);
    when(source.getSource()).thenReturn(imageStream);
    when(imageStream.getName()).thenReturn("my-image-stream");
    // operations
    model.setServerAppSource(source);
    // verification
    verify(model, Mockito.times(1)).setLabels(Arrays.asList(new Label("app", "my-image-stream")));
}
Also used : IApplicationSource(org.jboss.tools.openshift.internal.ui.wizard.newapp.IApplicationSource) Label(org.jboss.tools.openshift.internal.ui.wizard.common.IResourceLabelsPageModel.Label) IImageStream(com.openshift.restclient.model.IImageStream) Test(org.junit.Test)

Example 4 with Label

use of org.jboss.tools.openshift.internal.ui.wizard.common.IResourceLabelsPageModel.Label in project jbosstools-openshift by jbosstools.

the class CreateApplicationFromTemplateJob method doRun.

@Override
protected IStatus doRun(IProgressMonitor monitor) {
    template.updateParameterValues(parameters);
    for (Label label : labels) {
        template.addObjectLabel(label.getName(), label.getValue());
    }
    IStatus status = project.accept(new CapabilityVisitor<IProjectTemplateProcessing, IStatus>() {

        @Override
        public IStatus visit(IProjectTemplateProcessing capability) {
            try {
                ITemplate processed = capability.process(template);
                Collection<IResource> existing = findExistingResources(project, processed);
                if (!existing.isEmpty()) {
                    return createErrorStatusForExistingResources(existing);
                }
                parameters = processed.getParameters().values();
                resources = capability.apply(processed);
                return handleResponse(resources);
            } catch (OpenShiftException e) {
                String message = e.getMessage();
                if (e.getStatus() != null) {
                    message = e.getStatus().getMessage();
                }
                return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID, -1, message, e);
            }
        }
    }, new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID, "Template processing is unsupported for this client and server combination.", null));
    return status;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IStatus(org.eclipse.core.runtime.IStatus) IProjectTemplateProcessing(com.openshift.restclient.capability.resources.IProjectTemplateProcessing) OpenShiftException(com.openshift.restclient.OpenShiftException) Label(org.jboss.tools.openshift.internal.ui.wizard.common.IResourceLabelsPageModel.Label) Collection(java.util.Collection) ITemplate(com.openshift.restclient.model.template.ITemplate)

Example 5 with Label

use of org.jboss.tools.openshift.internal.ui.wizard.common.IResourceLabelsPageModel.Label in project jbosstools-openshift by jbosstools.

the class ResourceLabelsPage method onRemove.

private SelectionListener onRemove() {
    return new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            Label label = UIUtils.getFirstElement(viewer.getSelection(), Label.class);
            if (MessageDialog.openQuestion(getShell(), "Remove Label", NLS.bind("Are you sure you want to delete the label {0} ", label.getName()))) {
                model.removeLabel(label);
                viewer.refresh();
            }
        }
    };
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Label(org.jboss.tools.openshift.internal.ui.wizard.common.IResourceLabelsPageModel.Label)

Aggregations

Label (org.jboss.tools.openshift.internal.ui.wizard.common.IResourceLabelsPageModel.Label)9 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 IProjectTemplateProcessing (com.openshift.restclient.capability.resources.IProjectTemplateProcessing)2 Collection (java.util.Collection)2 IStatus (org.eclipse.core.runtime.IStatus)2 StyledString (org.eclipse.jface.viewers.StyledString)2 KeyValueWizardModelBuilder (org.jboss.tools.openshift.internal.common.ui.wizard.KeyValueWizardModelBuilder)2 OkCancelButtonWizardDialog (org.jboss.tools.openshift.internal.common.ui.wizard.OkCancelButtonWizardDialog)2 LabelKeyValidator (org.jboss.tools.openshift.internal.ui.validator.LabelKeyValidator)2 LabelValueValidator (org.jboss.tools.openshift.internal.ui.validator.LabelValueValidator)2 OpenShiftException (com.openshift.restclient.OpenShiftException)1 CapabilityVisitor (com.openshift.restclient.capability.CapabilityVisitor)1 IClientCapability (com.openshift.restclient.capability.resources.IClientCapability)1 DockerImageURI (com.openshift.restclient.images.DockerImageURI)1 IDeploymentConfig (com.openshift.restclient.model.IDeploymentConfig)1 IImageStream (com.openshift.restclient.model.IImageStream)1 IDeploymentImageChangeTrigger (com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger)1 ITemplate (com.openshift.restclient.model.template.ITemplate)1 Status (org.eclipse.core.runtime.Status)1