/* * Copyright (c) 2012 NoMagic, Inc. All Rights Reserved. */ package com.nomagic.magicdraw.examples.projectusagemap; import com.nomagic.actions.AMConfigurator; import com.nomagic.actions.ActionsCategory; import com.nomagic.actions.ActionsManager; import com.nomagic.actions.NMAction; import com.nomagic.ci.persistence.PersistenceException; import com.nomagic.magicdraw.actions.ActionsConfiguratorsManager; import com.nomagic.magicdraw.actions.ActionsID; import com.nomagic.magicdraw.plugins.Plugin; import com.nomagic.magicdraw.teamwork2.ITeamworkService; import com.nomagic.magicdraw.teamwork2.TeamworkService; import com.nomagic.magicdraw.visualization.projectsmap.ProjectMapHelper; import javax.annotation.CheckForNull; import java.awt.event.ActionEvent; import java.rmi.RemoteException; /** * Export to model project usage map repository view action. * This action is a demo action to demonstrate how it is possible * to export project usage map repository view using provided API. * * @author Modestas */ public class ProjectUsageMapExportToModelDemo extends Plugin { @Override public void init() { ActionsConfiguratorsManager manager = ActionsConfiguratorsManager.getInstance(); createMenuConfiguration(manager); } /** * Creates action in collaborate menu. * * @param manager instance of ActionsConfiguratorsManager */ private static void createMenuConfiguration(ActionsConfiguratorsManager manager) { AMConfigurator mainMenuConfigurator = new AMConfigurator() { @Override public void configure(ActionsManager mngr) { ActionsCategory category = (ActionsCategory) mngr.getActionFor(ActionsID.TEAMWORK); if (category != null) { category.addAction(new ExportProjectUsageMap()); } } @Override public int getPriority() { return AMConfigurator.HIGH_PRIORITY; } }; manager.addMainMenuConfigurator(mainMenuConfigurator); } @Override public boolean close() { return true; } @Override public boolean isSupported() { return true; } /** * Action which is able to export teamwork server repository view to model. * For action to be enabled user should login to teamwork server first. */ private static class ExportProjectUsageMap extends NMAction { /** * Constructor. */ public ExportProjectUsageMap() { super("EXPORT_PROJECT_USAGE_MAP_ID", "Export project usage map repository", null); } @Override public void updateState() { ITeamworkService activeInstance = TeamworkService.getActiveInstance(); setEnabled(activeInstance != null && activeInstance.isConnected()); } @Override public void actionPerformed(@CheckForNull ActionEvent e) { try { /* * There are and other ways how to export model. * Please check other methods in {@link ProjectMapHelper} */ ProjectMapHelper.exportRepositoryMapToModel(null); } catch (RemoteException | PersistenceException e1) { e1.printStackTrace(); } } } }