| /******************************************************************************* |
| * Copyright (c) 2008-2011 Chair for Applied Software Engineering, |
| * Technische Universitaet Muenchen. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| ******************************************************************************/ |
| package org.eclipse.emf.emfstore.client.ui.views.emfstorebrowser.handlers; |
| |
| import org.eclipse.core.commands.AbstractHandler; |
| import org.eclipse.core.commands.ExecutionEvent; |
| import org.eclipse.core.commands.ExecutionException; |
| import org.eclipse.emf.emfstore.client.model.ServerInfo; |
| import org.eclipse.emf.emfstore.client.model.WorkspaceManager; |
| import org.eclipse.emf.emfstore.client.model.util.EMFStoreCommand; |
| import org.eclipse.emf.emfstore.client.model.util.WorkspaceUtil; |
| import org.eclipse.emf.emfstore.server.exceptions.EmfStoreException; |
| import org.eclipse.jface.viewers.ISelection; |
| import org.eclipse.jface.viewers.IStructuredSelection; |
| import org.eclipse.jface.viewers.TreeNode; |
| import org.eclipse.swt.widgets.Display; |
| import org.eclipse.ui.IWorkbenchWindow; |
| import org.eclipse.ui.PlatformUI; |
| |
| /** |
| * Changes the user session. |
| * |
| * @author Shterev |
| */ |
| public class ChangeSessionHandler extends AbstractHandler { |
| |
| /** |
| * {@inheritDoc} |
| */ |
| public Object execute(ExecutionEvent event) throws ExecutionException { |
| IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); |
| ISelection selection = activeWorkbenchWindow.getSelectionService().getSelection(); |
| Object obj = ((IStructuredSelection) selection).getFirstElement(); |
| if (!(obj instanceof TreeNode)) { |
| return null; |
| } |
| TreeNode node = (TreeNode) obj; |
| final ServerInfo element = (ServerInfo) node.getValue(); |
| new EMFStoreCommand() { |
| @Override |
| protected void doRun() { |
| try { |
| element.getLastUsersession().logout(); |
| } catch (EmfStoreException e) { |
| WorkspaceUtil.logException(e.getMessage(), e); |
| } |
| element.getLastUsersession().setSessionId(null); |
| // reset the password in the RAM cache |
| if (!element.getLastUsersession().isSavePassword()) { |
| element.getLastUsersession().setPassword(null); |
| } |
| WorkspaceManager.getInstance().getCurrentWorkspace().save(); |
| } |
| }.run(); |
| Display.getDefault().asyncExec(new Runnable() { |
| public void run() { |
| PlatformUI.getWorkbench().getDecoratorManager() |
| .update("org.eclipse.emf.emfstore.client.ui.views.emfstorebrowser.LoginDecorator"); |
| } |
| }); |
| return null; |
| } |
| } |