1 6 package com.nightlabs.ipanema.config; 7 8 import java.util.ArrayList ; 9 import java.util.Collection ; 10 11 import javax.jdo.FetchPlan; 12 13 import org.eclipse.jface.viewers.IStructuredContentProvider; 14 import org.eclipse.jface.viewers.ITableLabelProvider; 15 import org.eclipse.jface.viewers.TableViewer; 16 import org.eclipse.jface.viewers.Viewer; 17 import org.eclipse.swt.SWT; 18 import org.eclipse.swt.graphics.Image; 19 import org.eclipse.swt.widgets.Composite; 20 import org.eclipse.swt.widgets.Table; 21 import org.eclipse.swt.widgets.TableColumn; 22 23 import com.nightlabs.ipanema.base.login.Login; 24 import com.nightlabs.rcp.layout.WeightedTableLayout; 25 import com.nightlabs.rcp.table.AbstractTableComposite; 26 27 31 public class UserConfigTable extends AbstractTableComposite { 32 33 public static final String [] DEFAULT_FETCH_GROUP = new String [] { 34 FetchPlan.DEFAULT, 35 FetchPlan.VALUES, 36 Config.FETCH_GROUP_THIS_CONFIG 37 }; 38 39 public static class ContentProvider implements IStructuredContentProvider { 40 41 private static final Collection EMPTY_COLLECTION = new ArrayList (0); 42 43 public Object [] getElements(Object inputElement) { 44 if (inputElement instanceof UserConfigGroup) 45 setSelectedUserConfigGroup((UserConfigGroup)inputElement); 46 else if (inputElement == null) 47 setSelectedUserConfigGroup(null); 48 49 return getUserConfigs().toArray(); 50 } 51 52 public void dispose() { 53 } 54 55 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 56 } 57 58 private UserConfigGroup selectedUserConfigGroup = null; 59 60 public void setSelectedUserConfigGroup(UserConfigGroup selectedUserConfigGroup) { 61 this.selectedUserConfigGroup = selectedUserConfigGroup; 62 } 63 64 public Collection getUserConfigs() { 65 if (selectedUserConfigGroup == null) 66 return EMPTY_COLLECTION; 67 68 try { 69 ConfigManager configManager = ConfigManagerUtil.getHome(Login.getLogin().getInitialContextProperties()).create(); 70 return configManager.getUserConfigsForGroup(selectedUserConfigGroup, DEFAULT_FETCH_GROUP); 71 } catch (Throwable e) { 72 throw new RuntimeException (e); 73 } 74 } 75 } 76 77 public static class LabelProvider extends org.eclipse.jface.viewers.LabelProvider implements ITableLabelProvider { 78 79 public Image getColumnImage(Object element, int columnIndex) { 80 return null; 81 } 82 83 public String getColumnText(Object element, int columnIndex) { 84 return ((UserConfigGroup)element).getUserConfigID(); 85 } 86 } 87 88 89 93 public UserConfigTable(Composite parent, int style) { 94 super(parent, style); 95 } 96 97 100 protected void createTableColumns(Table table) { 101 new TableColumn(table, SWT.LEFT).setText("UserConfig"); 102 table.setLayout(new WeightedTableLayout(new int[] {1})); 103 } 104 105 108 protected void setTableProvider(TableViewer tableViewer) { 109 tableViewer.setContentProvider(new ContentProvider()); 110 tableViewer.setLabelProvider(new LabelProvider()); 111 } 112 113 } 114 | Popular Tags |