summaryrefslogtreecommitdiffstats
path: root/src/org.gluster.storage.management.console/src/org/gluster/storage/management/console/views/GlusterViewsManager.java
blob: ba1ba8df539d66b478c6ec1f5fad2f16ad930be0 (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
124
125
126
127
128
/*******************************************************************************
 * Copyright (c) 2006-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 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see
 * <http://www.gnu.org/licenses/>.
 *******************************************************************************/
package org.gluster.storage.management.console.views;

import org.eclipse.ui.IViewReference;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.gluster.storage.management.console.ConsoleConstants;
import org.gluster.storage.management.core.model.Cluster;
import org.gluster.storage.management.core.model.Entity;
import org.gluster.storage.management.core.model.EntityGroup;
import org.gluster.storage.management.core.model.GlusterServer;
import org.gluster.storage.management.core.model.Server;
import org.gluster.storage.management.core.model.Volume;


/**
 * @see ViewsManager
 */
public class GlusterViewsManager implements ViewsManager {
	private IWorkbenchPage page;

	public GlusterViewsManager(IWorkbenchPage page) {
		this.page = page;
	}

	/* (non-Javadoc)
	 * @see org.gluster.storage.management.console.views.ViewsManager#updateViews(org.gluster.storage.management.core.model.Entity)
	 */
	@SuppressWarnings("rawtypes")
	@Override
	public void updateViews(Entity entity) {
		closeAllViews();

		try {
			if (entity instanceof EntityGroup) {
				showViewsForEntityGroup((EntityGroup)entity);
			} else if (entity.getClass() == Server.class) {
				showViewsForDiscoveredServer((Server)entity);
			} else if (entity.getClass() == GlusterServer.class) {
				showViewsForGlusterServer((GlusterServer)entity);
			} else if (entity instanceof Volume) {
				showViewsForVolume((Volume)entity);
			} else if (entity instanceof Cluster) {
				showViewsForCluster((Cluster)entity);
			}
		} catch (PartInitException e) {
			e.printStackTrace();
		}
	}

	private void closeAllViews() {
		IViewReference[] viewReferences = page.getViewReferences();
		for (final IViewReference viewReference : viewReferences) {
			if (!(viewReference.getId().equals(NavigationView.ID) || viewReference.getId().equals(
					ConsoleConstants.TERMINAL_VIEW_ID))) {
				page.hideView(viewReference);
			}
		}
	}

	private void showViewsForCluster(Cluster cluster) throws PartInitException {
		page.showView(ClusterSummaryView.ID);
		page.showView(TasksView.ID, null, IWorkbenchPage.VIEW_CREATE);
	}

	private void showViewsForVolume(Volume volume) throws PartInitException {
		page.showView(VolumeSummaryView.ID);
		page.showView(VolumeBricksView.ID, null, IWorkbenchPage.VIEW_CREATE);
		page.showView(VolumeOptionsView.ID, null, IWorkbenchPage.VIEW_CREATE);
		page.showView(VolumeLogsView.ID, null, IWorkbenchPage.VIEW_CREATE);
	}

	private void showViewsForGlusterServer(GlusterServer server) throws PartInitException {
		page.showView(GlusterServerSummaryView.ID);
		if (server.getStatus() == GlusterServer.SERVER_STATUS.ONLINE) {
			page.showView(GlusterServerDisksView.ID, null, IWorkbenchPage.VIEW_CREATE);
			//page.showView(GlusterServerLogsView.ID, null, IWorkbenchPage.VIEW_CREATE);
		}
	}

	private void showViewsForDiscoveredServer(Server server) throws PartInitException {
		page.showView(DiscoveredServerView.ID);
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	private void showViewsForEntityGroup(EntityGroup entityGroup) throws PartInitException {
		Class entityType = entityGroup.getEntityType();
		if (entityType == Server.class) {
			showViewForServers(entityGroup);
		} else if (entityType == Volume.class) {
			showViewsForVolumes(entityGroup);
		} else if (entityType == GlusterServer.class) {
			showViewsForGlusterServers(entityGroup);
		}
	}

	private void showViewsForGlusterServers(EntityGroup<GlusterServer> server) throws PartInitException {
		page.showView(GlusterServersSummaryView.ID);
		page.showView(GlusterServersView.ID, null, IWorkbenchPage.VIEW_CREATE);
		page.showView(DisksView.ID, null, IWorkbenchPage.VIEW_CREATE);
	}

	private void showViewsForVolumes(EntityGroup<Volume> volumes) throws PartInitException {
		page.showView(VolumesSummaryView.ID);
		page.showView(VolumesView.ID, null, IWorkbenchPage.VIEW_CREATE);
	}

	private void showViewForServers(EntityGroup<Server> servers) throws PartInitException {
		page.showView(DiscoveredServersView.ID);
	}
}