Search in sources :

Example 11 with ObservableTreeItem

use of org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem in project jbosstools-openshift by jbosstools.

the class ServerResourceViewModelWithDeploymentConfigTest method shouldReturnNewServiceItemsIfLoadResourcesWithConnection.

@Test
public void shouldReturnNewServiceItemsIfLoadResourcesWithConnection() {
    // given
    List<ObservableTreeItem> resourceItems = new ArrayList<>(model.getResourceItems());
    Connection connection = ResourceMocks.createConnection("http://localhost:8080", "dev@42.org");
    IProject project = ResourceMocks.createResource(IProject.class, ResourceKind.PROJECT);
    when(connection.getResources(ResourceKind.PROJECT)).thenReturn(Collections.singletonList(project));
    IDeploymentConfig deploymentConfig = ResourceMocks.createResource(IDeploymentConfig.class, ResourceKind.DEPLOYMENT_CONFIG);
    when(project.getResources(ResourceKind.DEPLOYMENT_CONFIG)).thenReturn(Collections.singletonList(deploymentConfig));
    // when
    model.loadResources(connection);
    // then
    List<ObservableTreeItem> newResourceItems = model.getResourceItems();
    assertThat(newResourceItems).isNotEqualTo(resourceItems);
}
Also used : ArrayList(java.util.ArrayList) Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) ObservableTreeItem(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem) IProject(com.openshift.restclient.model.IProject) Test(org.junit.Test)

Example 12 with ObservableTreeItem

use of org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem in project jbosstools-openshift by jbosstools.

the class ServerResourceViewModelWithReplicationControllerTest method shouldReturnNewServiceItemsIfLoadResourcesWithConnection.

@Test
public void shouldReturnNewServiceItemsIfLoadResourcesWithConnection() {
    // given
    List<ObservableTreeItem> resourceItems = new ArrayList<>(model.getResourceItems());
    Connection connection = ResourceMocks.createConnection("http://localhost:8080", "dev@42.org");
    IProject project = ResourceMocks.createResource(IProject.class, ResourceKind.PROJECT);
    when(connection.getResources(ResourceKind.PROJECT)).thenReturn(Collections.singletonList(project));
    IReplicationController replicationController = ResourceMocks.createResource(IReplicationController.class, ResourceKind.REPLICATION_CONTROLLER);
    when(project.getResources(ResourceKind.REPLICATION_CONTROLLER)).thenReturn(Collections.singletonList(replicationController));
    // when
    model.loadResources(connection);
    // then
    List<ObservableTreeItem> newResourceItems = model.getResourceItems();
    assertThat(newResourceItems).isNotEqualTo(resourceItems);
}
Also used : ArrayList(java.util.ArrayList) Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) ObservableTreeItem(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem) IProject(com.openshift.restclient.model.IProject) IReplicationController(com.openshift.restclient.model.IReplicationController) Test(org.junit.Test)

Example 13 with ObservableTreeItem

use of org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem in project jbosstools-openshift by jbosstools.

the class ServerSettingsWizardPage method createResourceTree.

@SuppressWarnings("unchecked")
private IViewerObservableValue createResourceTree(ServerSettingsWizardPageModel model, SashForm resourceControlsContainer, DataBindingContext dbc) {
    Composite resourceTreeContainer = new Composite(resourceControlsContainer, SWT.None);
    GridLayoutFactory.fillDefaults().applyTo(resourceTreeContainer);
    // filter
    Text selectorText = UIUtils.createSearchText(resourceTreeContainer);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(selectorText);
    // resource tree
    final TreeViewer resourcesViewer = createResourcesTreeViewer(resourceTreeContainer, model, selectorText);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).hint(RESOURCE_TREE_WIDTH, RESOURCE_TREE_HEIGHT).applyTo(resourcesViewer.getControl());
    resourcesViewer.addDoubleClickListener(onDoubleClickService());
    IObservableList<ObservableTreeItem> resourceItemsObservable = BeanProperties.list(ServerSettingsWizardPageModel.PROPERTY_RESOURCE_ITEMS).observe(model);
    DataBindingUtils.addDisposableListChangeListener(onResourceItemsChanged(resourcesViewer), resourceItemsObservable, resourcesViewer.getTree());
    selectorText.addModifyListener(onFilterTextModified(resourcesViewer));
    IViewerObservableValue selectedResourceTreeItem = ViewerProperties.singleSelection().observe(resourcesViewer);
    ValueBindingBuilder.bind(selectedResourceTreeItem).converting(new ObservableTreeItem2ModelConverter(IResource.class)).validatingAfterConvert(value -> {
        if ((value instanceof IResource) && OpenShiftServerUtils.isAllowedForServerAdapter((IResource) value)) {
            return ValidationStatus.ok();
        }
        return ValidationStatus.cancel("Please select a resource that this adapter will be bound to.");
    }).to(BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_RESOURCE).observe(model)).converting(new Model2ObservableTreeItemConverter(new ServerSettingsWizardPageModel.ResourceTreeItemsFactory())).in(dbc);
    return selectedResourceTreeItem;
}
Also used : SashForm(org.eclipse.swt.custom.SashForm) SelectProjectComponentBuilder(org.jboss.tools.openshift.internal.common.ui.SelectProjectComponentBuilder) CoreException(org.eclipse.core.runtime.CoreException) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) IObservableList(org.eclipse.core.databinding.observable.list.IObservableList) BooleanUtils(org.apache.commons.lang.BooleanUtils) ValidationStatus(org.eclipse.core.databinding.validation.ValidationStatus) OpenShiftIdentifierValidator(org.jboss.tools.openshift.internal.ui.validator.OpenShiftIdentifierValidator) Composite(org.eclipse.swt.widgets.Composite) Map(java.util.Map) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) DialogAdvancedPart(org.jboss.tools.openshift.internal.common.ui.utils.DialogAdvancedPart) BrowserUtility(org.jboss.tools.foundation.ui.util.BrowserUtility) Status(org.eclipse.core.runtime.Status) ValidationStatusProvider(org.eclipse.core.databinding.ValidationStatusProvider) ProjectViewerComparator(org.jboss.tools.openshift.internal.ui.comparators.ProjectViewerComparator) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) InvocationTargetException(java.lang.reflect.InvocationTargetException) ICompletable(org.jboss.ide.eclipse.as.ui.editor.DeploymentTypeUIUtil.ICompletable) OCBinary(org.jboss.tools.openshift.internal.core.preferences.OCBinary) Path(org.eclipse.core.runtime.Path) SWT(org.eclipse.swt.SWT) SelectExistingProjectDialog(org.jboss.tools.openshift.internal.common.ui.SelectExistingProjectDialog) SelectionListener(org.eclipse.swt.events.SelectionListener) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ImportApplicationWizard(org.jboss.tools.openshift.internal.ui.wizard.importapp.ImportApplicationWizard) IListProperty(org.eclipse.core.databinding.property.list.IListProperty) Converter(org.eclipse.core.databinding.conversion.Converter) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) NumericValidator(org.jboss.tools.openshift.internal.common.ui.databinding.NumericValidator) IBuildConfig(com.openshift.restclient.model.IBuildConfig) IWizard(org.eclipse.jface.wizard.IWizard) ProjectUtils(org.jboss.tools.openshift.common.core.utils.ProjectUtils) IValidator(org.eclipse.core.databinding.validation.IValidator) JFaceResources(org.eclipse.jface.resource.JFaceResources) DataBindingContext(org.eclipse.core.databinding.DataBindingContext) IContainer(org.eclipse.core.resources.IContainer) WidgetProperties(org.eclipse.jface.databinding.swt.WidgetProperties) ExpansionEvent(org.eclipse.ui.forms.events.ExpansionEvent) OpenShiftCommonUIMessages(org.jboss.tools.openshift.internal.common.ui.OpenShiftCommonUIMessages) IProject(org.eclipse.core.resources.IProject) VariablesHelper(org.jboss.tools.openshift.common.core.utils.VariablesHelper) Link(org.eclipse.swt.widgets.Link) RsyncStatus(org.jboss.tools.openshift.internal.core.util.RSyncValidator.RsyncStatus) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) Shell(org.eclipse.swt.widgets.Shell) IResource(com.openshift.restclient.model.IResource) MultiListProperty(org.eclipse.core.databinding.property.list.MultiListProperty) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) IServer(org.eclipse.wst.server.core.IServer) OpenShiftServerUtils(org.jboss.tools.openshift.core.server.OpenShiftServerUtils) File(java.io.File) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator) DOWNLOAD_INSTRUCTIONS_URL(org.jboss.tools.openshift.core.preferences.IOpenShiftCoreConstants.DOWNLOAD_INSTRUCTIONS_URL) Dialog(org.eclipse.jface.dialogs.Dialog) ModifyListener(org.eclipse.swt.events.ModifyListener) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) IServerWorkingCopy(org.eclipse.wst.server.core.IServerWorkingCopy) FormPresenterSupport(org.jboss.tools.openshift.internal.common.ui.databinding.FormPresenterSupport) StringUtils(org.jboss.tools.openshift.common.core.utils.StringUtils) RouteLabelProvider(org.jboss.tools.openshift.internal.ui.dialog.SelectRouteDialog.RouteLabelProvider) ControlDecorationSupport(org.eclipse.jface.databinding.fieldassist.ControlDecorationSupport) IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) ValueBindingBuilder(org.jboss.tools.common.ui.databinding.ValueBindingBuilder) AbstractOpenShiftWizardPage(org.jboss.tools.openshift.internal.common.ui.wizard.AbstractOpenShiftWizardPage) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) Model2ObservableTreeItemConverter(org.jboss.tools.openshift.internal.ui.treeitem.Model2ObservableTreeItemConverter) Button(org.eclipse.swt.widgets.Button) Collection(java.util.Collection) IViewerObservableValue(org.eclipse.jface.databinding.viewers.IViewerObservableValue) PreferencesUtil(org.eclipse.ui.dialogs.PreferencesUtil) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ExpansionAdapter(org.eclipse.ui.forms.events.ExpansionAdapter) Binding(org.eclipse.core.databinding.Binding) BeanProperties(org.eclipse.core.databinding.beans.BeanProperties) IRoute(com.openshift.restclient.model.route.IRoute) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) TreeViewer(org.eclipse.jface.viewers.TreeViewer) IWizardContainer(org.eclipse.jface.wizard.IWizardContainer) Label(org.eclipse.swt.widgets.Label) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) RSyncValidator(org.jboss.tools.openshift.internal.core.util.RSyncValidator) Image(org.eclipse.swt.graphics.Image) HashMap(java.util.HashMap) ISWTObservableValue(org.eclipse.jface.databinding.swt.ISWTObservableValue) ObservableTreeItem2ModelConverter(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter) ObservableListContentProvider(org.eclipse.jface.databinding.viewers.ObservableListContentProvider) ComboViewer(org.eclipse.jface.viewers.ComboViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) ObservableTreeItem(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue) DataBindingUtils(org.jboss.tools.openshift.internal.common.ui.utils.DataBindingUtils) OPEN_SHIFT_PREFERENCE_PAGE_ID(org.jboss.tools.openshift.core.preferences.IOpenShiftCoreConstants.OPEN_SHIFT_PREFERENCE_PAGE_ID) UIUtils(org.jboss.tools.openshift.internal.common.ui.utils.UIUtils) ObservableListTreeContentProvider(org.eclipse.jface.databinding.viewers.ObservableListTreeContentProvider) InvertingBooleanConverter(org.jboss.tools.common.ui.databinding.InvertingBooleanConverter) FillLayout(org.eclipse.swt.layout.FillLayout) OpenShiftUIActivator(org.jboss.tools.openshift.internal.ui.OpenShiftUIActivator) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) Viewer(org.eclipse.jface.viewers.Viewer) Job(org.eclipse.core.runtime.jobs.Job) IFormPresenter(org.jboss.tools.openshift.internal.common.ui.databinding.FormPresenterSupport.IFormPresenter) ViewerProperties(org.eclipse.jface.databinding.viewers.ViewerProperties) Group(org.eclipse.swt.widgets.Group) Connection(org.jboss.tools.openshift.core.connection.Connection) WritableValue(org.eclipse.core.databinding.observable.value.WritableValue) WizardUtils(org.jboss.tools.common.ui.WizardUtils) DisableableMultiValitdator(org.jboss.tools.openshift.internal.common.ui.databinding.DisableableMultiValitdator) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) OpenShiftCoreException(org.jboss.tools.openshift.common.core.OpenShiftCoreException) OpenShiftUIMessages(org.jboss.tools.openshift.internal.ui.OpenShiftUIMessages) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IListChangeListener(org.eclipse.core.databinding.observable.list.IListChangeListener) Collections(java.util.Collections) Control(org.eclipse.swt.widgets.Control) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) Model2ObservableTreeItemConverter(org.jboss.tools.openshift.internal.ui.treeitem.Model2ObservableTreeItemConverter) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ObservableTreeItem2ModelConverter(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter) Text(org.eclipse.swt.widgets.Text) ObservableTreeItem(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem) IViewerObservableValue(org.eclipse.jface.databinding.viewers.IViewerObservableValue) IResource(com.openshift.restclient.model.IResource)

Example 14 with ObservableTreeItem

use of org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem in project jbosstools-openshift by jbosstools.

the class ServerSettingsWizardPage method createResourcesTreeViewer.

@SuppressWarnings("unchecked")
private TreeViewer createResourcesTreeViewer(Composite parent, ServerSettingsWizardPageModel model, Text selectorText) {
    TreeViewer applicationTemplatesViewer = new TreeViewer(parent, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL);
    IListProperty<ServerSettingsWizardPageModel, ObservableTreeItem> childrenProperty = new MultiListProperty<>(new IListProperty[] { BeanProperties.list(ServerSettingsWizardPageModel.PROPERTY_RESOURCE_ITEMS), BeanProperties.list(ObservableTreeItem.PROPERTY_CHILDREN) });
    ObservableListTreeContentProvider contentProvider = new ObservableListTreeContentProvider(childrenProperty.listFactory(), null);
    applicationTemplatesViewer.setContentProvider(contentProvider);
    applicationTemplatesViewer.setLabelProvider(new ResourcesViewLabelProvider());
    applicationTemplatesViewer.addFilter(new ServiceViewerFilter(selectorText));
    applicationTemplatesViewer.setComparator(ProjectViewerComparator.createProjectTreeSorter());
    applicationTemplatesViewer.setAutoExpandLevel(TreeViewer.ALL_LEVELS);
    applicationTemplatesViewer.setInput(model);
    return applicationTemplatesViewer;
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) ObservableListTreeContentProvider(org.eclipse.jface.databinding.viewers.ObservableListTreeContentProvider) ObservableTreeItem(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem) MultiListProperty(org.eclipse.core.databinding.property.list.MultiListProperty)

Example 15 with ObservableTreeItem

use of org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem in project jbosstools-openshift by jbosstools.

the class ServerResourceViewModel method loadServices.

protected List<ObservableTreeItem> loadServices(Connection connection) {
    if (connection == null) {
        return null;
    }
    ObservableTreeItem connectionItem = ResourceTreeItemsFactory.INSTANCE.create(connection);
    connectionItem.load();
    return connectionItem.getChildren();
}
Also used : ObservableTreeItem(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem)

Aggregations

ObservableTreeItem (org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem)16 Test (org.junit.Test)10 IProject (com.openshift.restclient.model.IProject)5 Connection (org.jboss.tools.openshift.core.connection.Connection)4 ProjectViewerComparator (org.jboss.tools.openshift.internal.ui.comparators.ProjectViewerComparator)4 ArrayList (java.util.ArrayList)3 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)3 IConnection (org.jboss.tools.openshift.common.core.connection.IConnection)3 IReplicationController (com.openshift.restclient.model.IReplicationController)2 IResource (com.openshift.restclient.model.IResource)2 IService (com.openshift.restclient.model.IService)2 MultiListProperty (org.eclipse.core.databinding.property.list.MultiListProperty)2 ObservableListTreeContentProvider (org.eclipse.jface.databinding.viewers.ObservableListTreeContentProvider)2 TreeViewer (org.eclipse.jface.viewers.TreeViewer)2 OpenShiftExplorerLabelProvider (org.jboss.tools.openshift.internal.ui.explorer.OpenShiftExplorerLabelProvider)2 IBuildConfig (com.openshift.restclient.model.IBuildConfig)1 IDeploymentConfig (com.openshift.restclient.model.IDeploymentConfig)1 IRoute (com.openshift.restclient.model.route.IRoute)1 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1