summaryrefslogtreecommitdiffstats
path: root/src/org.gluster.storage.management.console/src/org/gluster/storage/management/console/views/pages/BricksPage.java
blob: c9660a770ac965b22b6a431278963db1e7bf83fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*******************************************************************************
 * Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com>
 * This file is part of Gluster Management Console.
 *
 * Gluster Management Console is free software; you can redistribute it and/or 
 * modify it under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *  
 * Gluster Management Console is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License
 * for more details.
 *  
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see
 * <http://www.gnu.org/licenses/>.
 *******************************************************************************/
package org.gluster.storage.management.console.views.pages;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.ui.IWorkbenchSite;
import org.gluster.storage.management.console.BrickTableLabelProvider;
import org.gluster.storage.management.core.model.Brick;
import org.gluster.storage.management.core.model.ClusterListener;
import org.gluster.storage.management.core.model.DefaultClusterListener;
import org.gluster.storage.management.core.model.Event;
import org.gluster.storage.management.core.model.Volume;


public class BricksPage extends AbstractTableViewerPage<Brick> {
	private List<Brick> bricks;
	
	public enum BRICK_TABLE_COLUMN_INDICES {
		SERVER, BRICK, FREE_SPACE, TOTAL_SPACE, STATUS
	};

	private static final String[] DISK_TABLE_COLUMN_NAMES = new String[] { "Server", "Brick Directory", "Free Space (GB)",
			"Total Space (GB)", "Status" };

	public BricksPage(Composite parent, int style, IWorkbenchSite site, final List<Brick> bricks) {
		super(site, parent, style, true, true, bricks);
		this.bricks = bricks;
	}

	@Override
	protected ClusterListener createClusterListener() {
		return new DefaultClusterListener() {
			@SuppressWarnings("unchecked")
			@Override
			public void volumeChanged(Volume volume, Event event) {
				switch (event.getEventType()) {
				case BRICKS_ADDED:
					tableViewer.add(((Collection<Brick>) event.getEventData()).toArray());
					parent.update();
					break;

				case BRICKS_REMOVED:
					tableViewer.remove(((Collection<Brick>) event.getEventData()).toArray());
					parent.update();
					break;

				case BRICKS_CHANGED:
					Object eventData = event.getEventData();
					Brick[] updatedBricks;
					if(eventData instanceof Map) {
						updatedBricks = ((Map<Brick, Brick>) eventData).keySet().toArray(new Brick[0]); 
					} else {
						updatedBricks = ((Collection<Brick>)eventData).toArray(new Brick[0]);
					}
					tableViewer.update(updatedBricks, null);
					parent.update();
					tableViewer.refresh(true);
				default:
					break;
				}
			}
		};
	}

	@Override
	protected String[] getColumnNames() {
		return DISK_TABLE_COLUMN_NAMES;
	}
	
	@Override
	protected void setColumnProperties(Table table) {
		guiHelper.setColumnProperties(table, BRICK_TABLE_COLUMN_INDICES.SERVER.ordinal(), SWT.CENTER, 100);
		guiHelper.setColumnProperties(table, BRICK_TABLE_COLUMN_INDICES.BRICK.ordinal(), SWT.CENTER, 100);
		guiHelper.setColumnProperties(table, BRICK_TABLE_COLUMN_INDICES.FREE_SPACE.ordinal(), SWT.CENTER, 90);
		guiHelper.setColumnProperties(table, BRICK_TABLE_COLUMN_INDICES.TOTAL_SPACE.ordinal(), SWT.CENTER, 90);
	}
	
	@Override
	protected ITableLabelProvider getLabelProvider() {
		return new BrickTableLabelProvider();
	}
	
	@Override
	protected IContentProvider getContentProvider() {
		return new ArrayContentProvider();
	}
	
	@Override
	protected List<Brick> getAllEntities() {
		return bricks;
	}

	@Override
	protected ViewerComparator createViewerComparator() {
		return null;
	}
}