KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > ui > wizards > ActivitiesTableViewer


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.update.internal.ui.wizards;
12
13 import java.util.ArrayList JavaDoc;
14
15 import org.eclipse.jface.viewers.*;
16 import org.eclipse.swt.*;
17 import org.eclipse.swt.graphics.*;
18 import org.eclipse.swt.layout.*;
19 import org.eclipse.swt.widgets.*;
20 import org.eclipse.update.configuration.*;
21 import org.eclipse.update.core.*;
22 import org.eclipse.update.internal.core.*;
23 import org.eclipse.update.internal.ui.*;
24 import org.eclipse.update.internal.ui.parts.*;
25
26
27 /**
28  * Viewer for configuration activities
29  */

30 public class ActivitiesTableViewer{
31
32     private static InstallLogParser parser;
33     
34     static class ActivitiesContentProvider
35         extends DefaultContentProvider
36         implements IStructuredContentProvider {
37         
38         private boolean showCurrentOnly;
39         
40         public ActivitiesContentProvider(boolean showCurrentOnly){
41             this.showCurrentOnly = showCurrentOnly;
42         }
43         public ActivitiesContentProvider(){
44             this.showCurrentOnly = false;
45         }
46         
47         public Object JavaDoc[] getElements(Object JavaDoc element) {
48             InstallConfiguration currentConfig = (InstallConfiguration)element;
49             InstallConfiguration[] configs = parser.getConfigurations();
50             boolean hitCurrentConfig = false;
51             ArrayList JavaDoc activitiesList = new ArrayList JavaDoc();
52             for (int i = 0; i<configs.length; i++){
53                 if (configs[i].equals(currentConfig) && !hitCurrentConfig)
54                     hitCurrentConfig = true;
55                 if (hitCurrentConfig && showCurrentOnly)
56                     return configs[i].getActivities();
57                 else if (hitCurrentConfig){
58                     IActivity[] activities = configs[i].getActivities();
59                     for (int j = 0; j<activities.length; j++)
60                         activitiesList.add(activities[j]);
61                 }
62                 
63             }
64             return (IActivity[])activitiesList.toArray(new IActivity[activitiesList.size()]);
65         }
66         
67     }
68
69     static class ActivitiesLabelProvider
70         extends LabelProvider
71         implements ITableLabelProvider {
72         public Image getColumnImage(Object JavaDoc element, int columnIndex) {
73             if (columnIndex == 0) {
74                 UpdateLabelProvider provider =
75                     UpdateUI.getDefault().getLabelProvider();
76                 switch (((IActivity) element).getStatus()) {
77                     case IActivity.STATUS_OK :
78                         return provider.get(UpdateUIImages.DESC_OK_ST_OBJ, 0);
79                     case IActivity.STATUS_NOK :
80                         return provider.get(UpdateUIImages.DESC_ERR_ST_OBJ, 0);
81                 }
82             }
83             return null;
84         }
85
86         public String JavaDoc getColumnText(Object JavaDoc element, int columnIndex) {
87             IActivity activity = (IActivity) element;
88             switch (columnIndex) {
89                 case 1 :
90                     return Utilities.format(activity.getDate());
91                 case 2 :
92                     return activity.getLabel();
93                 case 3 :
94                     return getActionLabel(activity);
95             }
96             return ""; //$NON-NLS-1$
97
}
98
99         private String JavaDoc getActionLabel(IActivity activity) {
100             int action = activity.getAction();
101             switch (action) {
102                 case IActivity.ACTION_CONFIGURE :
103                     return UpdateUIMessages.ActivitiesTableViewer_enabled;
104                 case IActivity.ACTION_FEATURE_INSTALL :
105                     return UpdateUIMessages.ActivitiesTableViewer_featureInstalled;
106                 case IActivity.ACTION_FEATURE_REMOVE :
107                     return UpdateUIMessages.ActivitiesTableViewer_featureRemoved;
108                 case IActivity.ACTION_SITE_INSTALL :
109                     return UpdateUIMessages.ActivitiesTableViewer_siteInstalled;
110                 case IActivity.ACTION_SITE_REMOVE :
111                     return UpdateUIMessages.ActivitiesTableViewer_siteRemoved;
112                 case IActivity.ACTION_UNCONFIGURE :
113                     return UpdateUIMessages.ActivitiesTableViewer_disabled;
114                 case IActivity.ACTION_REVERT :
115                     return UpdateUIMessages.ActivitiesTableViewer_revert;
116                 case IActivity.ACTION_RECONCILIATION :
117                     return UpdateUIMessages.ActivitiesTableViewer_reconcile;
118                 default :
119                     return UpdateUIMessages.ActivitiesTableViewer_unknown;
120             }
121         }
122     }
123
124     public static TableViewer createViewer(Composite parent, boolean showCurrentOnly) {
125         parser = new InstallLogParser();
126         parser.parseInstallationLog();
127         Table table = new Table(parent, SWT.BORDER);
128         table.setLayoutData(new GridData(GridData.FILL_BOTH));
129         table.setHeaderVisible(true);
130
131         TableColumn column = new TableColumn(table, SWT.NONE);
132
133         column = new TableColumn(table, SWT.NONE);
134         column.setText(UpdateUIMessages.ActivitiesTableViewer_date);
135
136         column = new TableColumn(table, SWT.NONE);
137         column.setText(UpdateUIMessages.ActivitiesTableViewer_target);
138
139         column = new TableColumn(table, SWT.NONE);
140         column.setText(UpdateUIMessages.ActivitiesTableViewer_action);
141
142         TableViewer activitiesViewer = new TableViewer(table);
143         activitiesViewer.setLabelProvider(new ActivitiesLabelProvider());
144         activitiesViewer.setContentProvider(new ActivitiesContentProvider(showCurrentOnly));
145         return activitiesViewer;
146     }
147
148 }
149
Popular Tags