| /******************************************************************************* |
| * Copyright (c) 2004, 2007 Boeing. |
| * 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: |
| * Boeing - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.osee.ats.editor.service.branch; |
| |
| import org.eclipse.jface.action.Action; |
| import org.eclipse.osee.ats.editor.SMAManager; |
| import org.eclipse.osee.ats.editor.service.WorkPageService; |
| import org.eclipse.osee.ats.workflow.AtsWorkPage; |
| import org.eclipse.osee.framework.db.connection.exception.OseeCoreException; |
| import org.eclipse.osee.framework.skynet.core.event.BranchEventType; |
| import org.eclipse.osee.framework.skynet.core.event.IBranchEventListener; |
| import org.eclipse.osee.framework.skynet.core.event.OseeEventManager; |
| import org.eclipse.osee.framework.skynet.core.event.Sender; |
| import org.eclipse.osee.framework.ui.plugin.util.Displays; |
| import org.eclipse.osee.framework.ui.skynet.FrameworkImage; |
| import org.eclipse.osee.framework.ui.skynet.ImageManager; |
| |
| /** |
| * @author Donald G. Dunne |
| */ |
| public class ShowChangeReportService extends WorkPageService implements IBranchEventListener { |
| |
| // Since this service is only going to be added for the Implement state, Location.AllState will |
| // work |
| public ShowChangeReportService(SMAManager smaMgr) { |
| super(smaMgr); |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.osee.ats.editor.service.WorkPageService#isShowSidebarService(org.eclipse.osee.ats.workflow.AtsWorkPage) |
| */ |
| @Override |
| public boolean isShowSidebarService(AtsWorkPage page) throws OseeCoreException { |
| return false; |
| } |
| |
| private Action toolBarAction; |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.osee.ats.editor.service.WorkPageService#createToolbarService() |
| */ |
| @Override |
| public Action createToolbarService() { |
| toolBarAction = new Action(getName(), Action.AS_PUSH_BUTTON) { |
| @Override |
| public void run() { |
| smaMgr.getBranchMgr().showChangeReport(); |
| } |
| }; |
| toolBarAction.setToolTipText(getName()); |
| toolBarAction.setImageDescriptor(ImageManager.getImageDescriptor(FrameworkImage.BRANCH_CHANGE)); |
| OseeEventManager.addListener(this); |
| refresh(); |
| return toolBarAction; |
| } |
| |
| @Override |
| public void dispose() { |
| OseeEventManager.removeListener(this); |
| super.dispose(); |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.osee.ats.editor.service.WorkPageService#getName() |
| */ |
| @Override |
| public String getName() { |
| return "Show Change Report"; |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see org.eclipse.osee.ats.editor.statistic.WorkPageStatistic#refresh() |
| */ |
| @Override |
| public void refresh() { |
| if (toolBarAction != null) { |
| toolBarAction.setEnabled(isEnabled()); |
| } |
| } |
| |
| private boolean isEnabled() { |
| boolean enabled = false; |
| try { |
| if (smaMgr.getBranchMgr().isWorkingBranchInWork()) { |
| enabled = true; |
| } else { |
| enabled = smaMgr.getBranchMgr().isCommittedBranchExists(); |
| } |
| } catch (Exception ex) { |
| // do nothing |
| } |
| return enabled; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.osee.framework.skynet.core.eventx.IBranchEventListener#handleBranchEvent(org.eclipse.osee.framework.ui.plugin.event.Sender, org.eclipse.osee.framework.skynet.core.artifact.BranchModType, int) |
| */ |
| @Override |
| public void handleBranchEvent(Sender sender, BranchEventType branchModType, int branchId) { |
| Displays.ensureInDisplayThread(new Runnable() { |
| /* (non-Javadoc) |
| * @see java.lang.Runnable#run() |
| */ |
| @Override |
| public void run() { |
| refresh(); |
| } |
| }); |
| |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.osee.framework.skynet.core.eventx.IBranchEventListener#handleLocalBranchToArtifactCacheUpdateEvent(org.eclipse.osee.framework.ui.plugin.event.Sender) |
| */ |
| @Override |
| public void handleLocalBranchToArtifactCacheUpdateEvent(Sender sender) { |
| Displays.ensureInDisplayThread(new Runnable() { |
| /* (non-Javadoc) |
| * @see java.lang.Runnable#run() |
| */ |
| @Override |
| public void run() { |
| refresh(); |
| } |
| }); |
| |
| } |
| |
| } |