Search in sources :

Example 6 with ObservableTreeItem2ModelConverter

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

the class AbstractProjectPage method getLoadResourcesJobBuilder.

/**
 * Create and configure the list of jobs that need to be performed during
 * resource loading. The base behavior is to load the projects and force project
 * creation if no project exists.
 *
 * @param closeAfter
 *            return parameter if wizard needs to be closed (may be updated)
 * @param closeOnCancel
 *            true if the wizard need to be closed
 * @return the job builder
 */
protected JobChainBuilder getLoadResourcesJobBuilder(final boolean[] closeAfter, final boolean closeOnCancel) {
    JobChainBuilder builder = new JobChainBuilder(new AbstractDelegatingMonitorJob("Loading projects...") {

        @Override
        protected IStatus doRun(IProgressMonitor monitor) {
            try {
                model.loadResources();
            } catch (OpenShiftException e) {
                closeAfter[0] = closeOnCancel;
                String problem = e.getStatus() == null ? e.getMessage() : e.getStatus().getMessage();
                return OpenShiftUIActivator.statusFactory().errorStatus(problem, e);
            }
            return Status.OK_STATUS;
        }
    });
    builder.runWhenSuccessfullyDone(new UIJob("Verifying required project...") {

        @Override
        public IStatus runInUIThread(IProgressMonitor monitor) {
            if (!model.hasProjects()) {
                List<IProject> projects = new ObservableTreeItem2ModelConverter().convert(model.getProjectItems());
                Connection connection = model.getConnection();
                NewProjectWizard newProjectWizard = new NewProjectWizard(connection, projects);
                if (Dialog.CANCEL == WizardUtils.openWizardDialog(newProjectWizard, getShell())) {
                    closeAfter[0] = closeOnCancel;
                    return Status.CANCEL_STATUS;
                } else {
                    model.loadResources();
                    model.setProject(newProjectWizard.getProject());
                }
            }
            return Status.OK_STATUS;
        }
    });
    return builder;
}
Also used : AbstractDelegatingMonitorJob(org.jboss.tools.openshift.internal.common.core.job.AbstractDelegatingMonitorJob) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) OpenShiftException(com.openshift.restclient.OpenShiftException) Connection(org.jboss.tools.openshift.core.connection.Connection) UIJob(org.eclipse.ui.progress.UIJob) ObservableTreeItem2ModelConverter(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter) List(java.util.List) NewProjectWizard(org.jboss.tools.openshift.internal.ui.wizard.project.NewProjectWizard) JobChainBuilder(org.jboss.tools.openshift.internal.common.core.job.JobChainBuilder)

Example 7 with ObservableTreeItem2ModelConverter

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

the class ApplicationSourceListPage method createServerTemplateControls.

private IObservableValue createServerTemplateControls(TabFolder tabFolder, TabFolderTraverseListener tabFolderTraverseListener, IObservableValue uploadTemplate, DataBindingContext dbc) {
    TabItem serverTemplatesTab = new TabItem(tabFolder, SWT.NONE);
    serverTemplatesTab.setText("Server application source");
    Composite parent = new Composite(tabFolder, SWT.NONE);
    GridLayoutFactory.fillDefaults().margins(10, 6).spacing(2, 2).applyTo(parent);
    serverTemplatesTab.setControl(parent);
    // filter text
    final Text txtTemplateFilter = UIUtils.createSearchText(parent);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(txtTemplateFilter);
    IObservableValue eclipseProjectObservable = BeanProperties.value(IApplicationSourceListPageModel.PROPERTY_ECLIPSE_PROJECT).observe(model);
    DataBindingUtils.addDisposableValueChangeListener(new IValueChangeListener() {

        @Override
        public void handleValueChange(ValueChangeEvent event) {
            filterTemplates(txtTemplateFilter, (org.eclipse.core.resources.IProject) event.getObservableValue().getValue());
        }
    }, eclipseProjectObservable, txtTemplateFilter);
    filterTemplates(txtTemplateFilter, model.getEclipseProject());
    // the list of templates
    this.templatesViewer = createServerTemplatesViewer(parent, txtTemplateFilter);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).hint(400, 180).applyTo(templatesViewer.getControl());
    IObservableValue selectedViewerServerTemplate = ViewerProperties.singleSelection().observe(templatesViewer);
    ValueBindingBuilder.bind(selectedViewerServerTemplate).converting(new ObservableTreeItem2ModelConverter(IApplicationSource.class)).to(BeanProperties.value(IApplicationSourceListPageModel.PROPERTY_SERVER_APP_SOURCE).observe(model)).converting(new Model2ObservableTreeItemConverter(ApplicationSourceTreeItems.INSTANCE)).in(dbc);
    templatesViewer.addDoubleClickListener(onServerTemplateDoubleClicked());
    txtTemplateFilter.addModifyListener(onFilterTextTyped(templatesViewer));
    tabFolderTraverseListener.bindTabControls(tabFolder.getItemCount() - 1, txtTemplateFilter, templatesViewer.getTree());
    return selectedViewerServerTemplate;
}
Also used : IValueChangeListener(org.eclipse.core.databinding.observable.value.IValueChangeListener) TabItem(org.eclipse.swt.widgets.TabItem) ValueChangeEvent(org.eclipse.core.databinding.observable.value.ValueChangeEvent) Composite(org.eclipse.swt.widgets.Composite) Model2ObservableTreeItemConverter(org.jboss.tools.openshift.internal.ui.treeitem.Model2ObservableTreeItemConverter) ObservableTreeItem2ModelConverter(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter) Text(org.eclipse.swt.widgets.Text) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue)

Example 8 with ObservableTreeItem2ModelConverter

use of org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter 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)

Aggregations

ObservableTreeItem2ModelConverter (org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter)8 Binding (org.eclipse.core.databinding.Binding)5 IObservableValue (org.eclipse.core.databinding.observable.value.IObservableValue)5 Button (org.eclipse.swt.widgets.Button)5 RequiredControlDecorationUpdater (org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater)5 ObservableListContentProvider (org.eclipse.jface.databinding.viewers.ObservableListContentProvider)4 ComboViewer (org.eclipse.jface.viewers.ComboViewer)4 StructuredViewer (org.eclipse.jface.viewers.StructuredViewer)4 Composite (org.eclipse.swt.widgets.Composite)4 Label (org.eclipse.swt.widgets.Label)4 WritableValue (org.eclipse.core.databinding.observable.value.WritableValue)3 IStatus (org.eclipse.core.runtime.IStatus)3 ExpansionEvent (org.eclipse.ui.forms.events.ExpansionEvent)3 ExpandableComposite (org.eclipse.ui.forms.widgets.ExpandableComposite)3 ProjectViewerComparator (org.jboss.tools.openshift.internal.ui.comparators.ProjectViewerComparator)3 Model2ObservableTreeItemConverter (org.jboss.tools.openshift.internal.ui.treeitem.Model2ObservableTreeItemConverter)3 IBuildConfig (com.openshift.restclient.model.IBuildConfig)2 IProject (com.openshift.restclient.model.IProject)2 IResource (com.openshift.restclient.model.IResource)2 MultiValidator (org.eclipse.core.databinding.validation.MultiValidator)2