aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbeyhan@eclipsesource.com2012-03-03 13:14:21 (EST)
committerbeyhan@eclipsesource.com2012-03-03 13:14:21 (EST)
commitf1c52854afcd4e34029e94a138901e4d42fc3b2e (patch)
tree2e2df604ae5a4c85915df56c521a2926c2b215a3
parentf8c85ec21cfade1fe13932232a758b65ecdb0d21 (diff)
downloadorg.eclipse.rtp-f1c52854afcd4e34029e94a138901e4d42fc3b2e.zip
org.eclipse.rtp-f1c52854afcd4e34029e94a138901e4d42fc3b2e.tar.gz
org.eclipse.rtp-f1c52854afcd4e34029e94a138901e4d42fc3b2e.tar.bz2
364706: [Configurator][UI] Provide a configurator UI
https://bugs.eclipse.org/bugs/show_bug.cgi?id=364706 * UI reorganized * ComponentsTab refectored
-rw-r--r--bundles/org.eclipse.rtp.configurator.ui/src/org/eclipse/rtp/configurator/ui/ComponentsTab.java113
-rw-r--r--bundles/org.eclipse.rtp.configurator.ui/src/org/eclipse/rtp/configurator/ui/ComponentsTabContentUtil.java75
-rw-r--r--bundles/org.eclipse.rtp.configurator.ui/src/org/eclipse/rtp/configurator/ui/SourcesLabelProvider.java8
3 files changed, 126 insertions, 70 deletions
diff --git a/bundles/org.eclipse.rtp.configurator.ui/src/org/eclipse/rtp/configurator/ui/ComponentsTab.java b/bundles/org.eclipse.rtp.configurator.ui/src/org/eclipse/rtp/configurator/ui/ComponentsTab.java
index 5e378c4..d6520a6 100644
--- a/bundles/org.eclipse.rtp.configurator.ui/src/org/eclipse/rtp/configurator/ui/ComponentsTab.java
+++ b/bundles/org.eclipse.rtp.configurator.ui/src/org/eclipse/rtp/configurator/ui/ComponentsTab.java
@@ -8,16 +8,12 @@
package org.eclipse.rtp.configurator.ui;
import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.rtp.configurator.rest.RestTemplate;
import org.eclipse.rtp.configurator.ui.internal.event.EventingServiceUtil;
import org.eclipse.rtp.configurator.ui.internal.event.IConfigurationEvent;
import org.eclipse.rtp.configurator.ui.internal.event.IConfigurationListener;
@@ -29,6 +25,8 @@ import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
@@ -39,26 +37,17 @@ import org.eclipse.swt.widgets.Text;
public class ComponentsTab extends AbstractTabContribution {
private final SourcesContentProvider contentProvider = new SourcesContentProvider();
- private RestTemplate restTemplate;
- protected static String[] comboLabels = new String[]{
- "all", "installed", "uninstalled"
- };
- private final Map<String, String> listMapping = new HashMap<String, String>() {
-
- {
- put( comboLabels[ 0 ], "/rt/list" );
- put( comboLabels[ 1 ], "/rt/list/installed" );
- put( comboLabels[ 2 ], "/rt/list/uninstaller" );
- }
- };
TreeViewer viewer;
private Combo combo;
private Button addSource;
private Button removeSource;
private Button updateWorld;
- private List<Source> sources;
- private List<Source> installedSources;
private Display display;
+ ComponentsTabContentUtil contentUtil;
+
+ public ComponentsTab() {
+ contentUtil = new ComponentsTabContentUtil();
+ }
@Override
public String getTitle() {
@@ -70,10 +59,23 @@ public class ComponentsTab extends AbstractTabContribution {
protected void populateControl( Display display, Composite composite ) {
this.display = display;
Composite tab = UiHelper.createGreedyGridComposite( composite, 1, true );
- Composite tabToolbarComposite = UiHelper.createGridComposite( tab, 5, false );
- Label searchLabel = new Label( tabToolbarComposite, SWT.NONE );
+ final ComponentsFilter filter = createToolBar( tab );
+ createTreeView( display, tab, filter );
+ Composite provisioningActionsComposite = UiHelper.createGridComposite( tab, 2, false );
+ addInstallButton( provisioningActionsComposite );
+ addUninstallButton( provisioningActionsComposite );
+ addUpdateWorldButton( provisioningActionsComposite );
+ registerTabForConfigurationChanges();
+ }
+
+ private ComponentsFilter createToolBar( Composite tab ) {
+ Composite tabToolbarComposite = UiHelper.createGridComposite( tab, 3, true );
+ Composite searchComposite = new Composite( tabToolbarComposite, SWT.NONE );
+ searchComposite.setLayout( new GridLayout( 2, false ) );
+ searchComposite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
+ Label searchLabel = new Label( searchComposite, SWT.NONE );
searchLabel.setText( "Search: " );
- final Text filterText = UiHelper.createText( tabToolbarComposite, 1, "Please enter filter" );
+ final Text filterText = UiHelper.createText( searchComposite, 1, "Please enter filter" );
final ComponentsFilter filter = new ComponentsFilter();
filterText.addKeyListener( new KeyAdapter() {
@@ -83,9 +85,12 @@ public class ComponentsTab extends AbstractTabContribution {
viewer.refresh();
}
} );
- Label filterLabel = new Label( tabToolbarComposite, SWT.NONE );
+ Composite filterComposite = new Composite( tabToolbarComposite, SWT.NONE );
+ filterComposite.setLayout( new GridLayout( 2, false ) );
+ filterComposite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
+ Label filterLabel = new Label( filterComposite, SWT.NONE );
filterLabel.setText( "Filter: " );
- combo = UiHelper.createComboBox( tabToolbarComposite, 1, comboLabels );
+ combo = UiHelper.createComboBox( filterComposite, 1, contentUtil.getComboLabels() );
combo.addSelectionListener( new SelectionAdapter() {
@Override
@@ -93,8 +98,16 @@ public class ComponentsTab extends AbstractTabContribution {
refresh();
}
} );
- Button refreshButton = UiHelper.createPushButton( tabToolbarComposite, "refresh" );
+ Composite refreshComposite = new Composite( tabToolbarComposite, SWT.NONE );
+ refreshComposite.setLayout( new GridLayout( 2, true ) );
+ refreshComposite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
+ new Label( refreshComposite, SWT.NONE );
+ Button refreshButton = UiHelper.createPushButton( refreshComposite, "refresh" );
refreshButton.addSelectionListener( new RefreshButtonSelectionListener( this ) );
+ return filter;
+ }
+
+ private void createTreeView( Display display, Composite tab, final ComponentsFilter filter ) {
Composite treeComposite = UiHelper.createGreedyGridComposite( tab, 1, true );
viewer = UiHelper.createTreeViewer( new Composite( treeComposite, SWT.NONE ) );
viewer.addFilter( filter );
@@ -112,15 +125,10 @@ public class ComponentsTab extends AbstractTabContribution {
};
viewer.addSelectionChangedListener( listener );
viewer.setContentProvider( contentProvider );
- SourcesLabelProvider labelProvider = new SourcesLabelProvider( this );
+ SourcesLabelProvider labelProvider = new SourcesLabelProvider( contentUtil );
labelProvider.init( display );
viewer.setLabelProvider( labelProvider );
viewer.setInput( new ArrayList<Source>() );
- Composite provisioningActionsComposite = UiHelper.createGridComposite( tab, 2, false );
- addInstallButton( provisioningActionsComposite );
- addUninstallButton( provisioningActionsComposite );
- addUpdateWorldButton( provisioningActionsComposite );
- registerTabForConfigurationChanges();
}
private void registerTabForConfigurationChanges() {
@@ -134,7 +142,7 @@ public class ComponentsTab extends AbstractTabContribution {
@Override
public void widgetSelected( SelectionEvent e ) {
- restTemplate.delete( "/rt/uninstall" + generateSelectedSourceUri() );
+ contentUtil.getRestTemplate().delete( "/rt/uninstall" + generateSelectedSourceUri() );
}
} );
}
@@ -145,7 +153,7 @@ public class ComponentsTab extends AbstractTabContribution {
@Override
public void widgetSelected( SelectionEvent e ) {
- restTemplate.put( "/rt/updateworld" );
+ contentUtil.getRestTemplate().put( "/rt/updateworld" );
}
} );
}
@@ -157,7 +165,7 @@ public class ComponentsTab extends AbstractTabContribution {
@Override
public void widgetSelected( SelectionEvent e ) {
String uri = "/rt/install" + generateSelectedSourceUri();
- restTemplate.put( uri );
+ contentUtil.getRestTemplate().put( uri );
}
} );
}
@@ -169,7 +177,7 @@ public class ComponentsTab extends AbstractTabContribution {
} else {
sourceVersion = ( SourceVersion )selectedElement;
}
- if( isInstalled( sourceVersion ) ) {
+ if( contentUtil.isInstalled( sourceVersion ) ) {
addSource.setEnabled( false );
removeSource.setEnabled( true );
} else {
@@ -178,15 +186,6 @@ public class ComponentsTab extends AbstractTabContribution {
}
}
- public boolean isInstalled( SourceVersion sourceVersion ) {
- boolean result = false;
- for( int i = 0; i < installedSources.size() && result == false; i++ ) {
- Source source = installedSources.get( i );
- result = source.getVersions().contains( sourceVersion );
- }
- return result;
- }
-
String generateSelectedSourceUri() {
String version = null;
String name = null;
@@ -196,44 +195,26 @@ public class ComponentsTab extends AbstractTabContribution {
name = ( ( Source )selectedElement ).getName();
} else if( selectedElement instanceof SourceVersion ) {
version = ( ( SourceVersion )selectedElement ).getVersion();
- name = getSourceVersionSource( ( SourceVersion )selectedElement ).getName();
+ name = contentUtil.getSourceVersionSource( ( SourceVersion )selectedElement ).getName();
}
String uri = "/" + name + "/" + version;
return uri;
}
- private Source getSourceVersionSource( SourceVersion sourceVersion ) {
- Source result = null;
- if( sources != null ) {
- for( Source source : sources ) {
- List<SourceVersion> versions = source.getVersions();
- for( SourceVersion version : versions ) {
- if( version.equals( sourceVersion ) ) {
- result = source;
- }
- }
- }
- }
- return result;
- }
-
public void configurationChanged( IConfigurationEvent event ) {
- restTemplate = new RestTemplate( event.getNewIntanceURI() );
+ contentUtil.setConfigurationURI( event.getNewIntanceURI() );
refresh();
}
public void refresh() {
- if( restTemplate != null && !display.isDisposed() ) {
+ if( contentUtil != null && !display.isDisposed() ) {
display.asyncExec( new Runnable() {
@Override
public void run() {
int selectionIndex = combo.getSelectionIndex();
- sources = restTemplate.getForEntitiesAsList( listMapping.get( ComponentsTab.comboLabels[ selectionIndex ] ),
- Source.class );
- installedSources = restTemplate.getForEntitiesAsList( listMapping.get( ComponentsTab.comboLabels[ 1 ] ),
- Source.class );
- viewer.setInput( sources );
+ contentUtil.refresh( contentUtil.getComboLabels()[ selectionIndex ] );
+ viewer.setInput( contentUtil.getSourcec() );
addSource.setEnabled( false );
removeSource.setEnabled( false );
}
diff --git a/bundles/org.eclipse.rtp.configurator.ui/src/org/eclipse/rtp/configurator/ui/ComponentsTabContentUtil.java b/bundles/org.eclipse.rtp.configurator.ui/src/org/eclipse/rtp/configurator/ui/ComponentsTabContentUtil.java
new file mode 100644
index 0000000..0941645
--- /dev/null
+++ b/bundles/org.eclipse.rtp.configurator.ui/src/org/eclipse/rtp/configurator/ui/ComponentsTabContentUtil.java
@@ -0,0 +1,75 @@
+package org.eclipse.rtp.configurator.ui;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.rtp.configurator.rest.RestTemplate;
+import org.eclipse.rtp.core.model.Source;
+import org.eclipse.rtp.core.model.SourceVersion;
+
+public class ComponentsTabContentUtil {
+
+ private List<Source> sources;
+ private List<Source> installedSources;
+ private RestTemplate restTemplate;
+ private String configurationURI;
+ private static String[] comboLabels = new String[]{
+ "all", "installed", "uninstalled"
+ };
+ private final Map<String, String> listMapping = new HashMap<String, String>() {
+
+ {
+ put( comboLabels[ 0 ], "/rt/list" );
+ put( comboLabels[ 1 ], "/rt/list/installed" );
+ put( comboLabels[ 2 ], "/rt/list/uninstaller" );
+ }
+ };
+
+ public void setConfigurationURI( String configurationURI ) {
+ this.configurationURI = configurationURI;
+ }
+
+ public String[] getComboLabels() {
+ return comboLabels;
+ }
+
+ public List<Source> getSourcec() {
+ return sources;
+ }
+
+ public RestTemplate getRestTemplate() {
+ return restTemplate;
+ }
+
+ public boolean isInstalled( SourceVersion sourceVersion ) {
+ boolean result = false;
+ for( int i = 0; i < installedSources.size() && result == false; i++ ) {
+ Source source = installedSources.get( i );
+ result = source.getVersions().contains( sourceVersion );
+ }
+ return result;
+ }
+
+ public Source getSourceVersionSource( SourceVersion sourceVersion ) {
+ Source result = null;
+ if( sources != null ) {
+ for( Source source : sources ) {
+ List<SourceVersion> versions = source.getVersions();
+ for( SourceVersion version : versions ) {
+ if( version.equals( sourceVersion ) ) {
+ result = source;
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ public void refresh( String componentsFilter ) {
+ restTemplate = new RestTemplate( configurationURI );
+ sources = restTemplate.getForEntitiesAsList( listMapping.get( componentsFilter ), Source.class );
+ installedSources = restTemplate.getForEntitiesAsList( listMapping.get( componentsFilter ),
+ Source.class );
+ }
+}
diff --git a/bundles/org.eclipse.rtp.configurator.ui/src/org/eclipse/rtp/configurator/ui/SourcesLabelProvider.java b/bundles/org.eclipse.rtp.configurator.ui/src/org/eclipse/rtp/configurator/ui/SourcesLabelProvider.java
index b6cbbdf..ee40afe 100644
--- a/bundles/org.eclipse.rtp.configurator.ui/src/org/eclipse/rtp/configurator/ui/SourcesLabelProvider.java
+++ b/bundles/org.eclipse.rtp.configurator.ui/src/org/eclipse/rtp/configurator/ui/SourcesLabelProvider.java
@@ -17,12 +17,12 @@ import org.eclipse.swt.widgets.Display;
class SourcesLabelProvider implements ITableLabelProvider {
private Image httpSource;
- private final ComponentsTab componentsTab;
+ private final ComponentsTabContentUtil contentUtil;
// TODO check supported sources...
// private Image fileSource;
- public SourcesLabelProvider( ComponentsTab componentsTab ) {
- this.componentsTab = componentsTab;
+ public SourcesLabelProvider( ComponentsTabContentUtil contentUtil ) {
+ this.contentUtil = contentUtil;
}
public void init( Display display ) {
@@ -52,7 +52,7 @@ class SourcesLabelProvider implements ITableLabelProvider {
} else if( columnIndex == 1 && element instanceof SourceVersion ) {
result = ( ( SourceVersion )element ).getRepositoryUrl().toString();
} else if( columnIndex == 2 && element instanceof SourceVersion ) {
- boolean installed = componentsTab.isInstalled( ( SourceVersion )element );
+ boolean installed = contentUtil.isInstalled( ( SourceVersion )element );
if( installed ) {
result = "installed";
} else {