// THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
// CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
// OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Copyright 2000-2005 Softaris Pty.Ltd. All Rights Reserved.
package com.metaboss.applications.designstudio;
import java.awt.AWTEvent;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.EventListener;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.ResourceBundle;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.swing.AbstractButton;
import javax.swing.Action;
import javax.swing.ButtonGroup;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JToggleButton;
import javax.swing.JToolBar;
import javax.swing.UIManager;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Appender;
import org.apache.log4j.Layout;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.SimpleLayout;
import org.apache.log4j.WriterAppender;
import org.jgraph.graph.GraphConstants;
import com.jgoodies.plaf.FontSizeHints;
import com.jgoodies.plaf.Options;
import com.metaboss.applications.designstudio.auxilarydialogs.AboutDialog;
import com.metaboss.applications.designstudio.auxilarydialogs.CopyElementDialog;
import com.metaboss.applications.designstudio.auxilarydialogs.SaveContentDialog;
import com.metaboss.applications.designstudio.auxilarydialogs.SplashScreen;
import com.metaboss.applications.designstudio.components.ContainerAction;
import com.metaboss.applications.designstudio.components.ModelFileFilter;
import com.metaboss.applications.designstudio.components.SeparatorAction;
import com.metaboss.applications.designstudio.components.ToolBarSeparator;
import com.metaboss.applications.designstudio.icons.IconsHolder;
import com.metaboss.applications.designstudio.systemlog.LogOutputStream;
import com.metaboss.applications.designstudio.userobjects.ModelUserObject;
import com.metaboss.applications.designstudio.userobjects.UserObjectFactory;
import com.metaboss.enterprise.bs.BSNamingAndDirectoryServiceInvocationException;
import com.metaboss.licensing.LicenseService;
import com.metaboss.sdlctools.models.ModelRepository;
import com.metaboss.sdlctools.models.ModelValidationException;
import com.metaboss.sdlctools.models.impl.metabossmodel.ModelElementResolverImpl;
import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
import com.metaboss.sdlctools.models.metabossmodel.ModelUtils;
import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.AbstractNamespace;
import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataDictionary;
import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataType;
import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Namespace;
import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Structure;
import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.TypeTemplate;
import com.metaboss.sdlctools.models.metabossmodel.designlibrarymodel.DesignLibrary;
import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Enterprise;
import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Message;
import com.metaboss.sdlctools.models.metabossmodel.technologylibrarymodel.RelationalStorageTechnology;
import com.metaboss.sdlctools.models.metabossmodel.visualmodel.Diagram;
/* Metaboss design Studio application class */
public class Application extends JComponent
{
// Model Repository
public static ModelRepository sModelRepository = null;
public static ArrayList sModelErrors = new ArrayList();
public static String sErrorElement = null;
public static ArrayList sModels = new ArrayList();
public static ModelChangesListener sModelListener = new ModelChangesListener();
// The path for the user and system settings for the application
public static final String sApplicationPath = "/com/metaboss/applications/designstudio";
public static final String sApplicationName = "MetaBossDesignStudio";
// properties file name
public static final String PROPERTIES_FILE = "MetaBossDesignStudio.properties";
// default application font
public static final Font DEFAULT_FONT = new Font("Dialog", Font.PLAIN, 11);
public static final Font DEFAULT_FONT_BOLD = new Font("Dialog", Font.BOLD, 11);
public static final Font DEFAULT_FONT_SMALL = new Font("Dialog", Font.PLAIN, 8);
public static final Font EDITOR_FONT = new Font("Courier New", Font.PLAIN, 12);
public static final Font VERTEX_FONT = GraphConstants.defaultFont.deriveFont(Font.BOLD, 12);
// resource strings
public static ResourceBundle resStrings = null;
// properties
public static ApplicationProperties properties = new ApplicationProperties();
public static Object sClassInitialisationSemaphore = new Object();
public static LicenseService sLicenseService = null;
// Application
public static Application instance = null;
public static MainFrame mainFrame = null;
public static SplashScreen splash = null;
// icons
public static ImageIcon METABOSS_LOGO = IconsHolder.loadIcon("MBLogo.png");
public static ImageIcon METABOSS_ICON = IconsHolder.loadIcon("MetaBoss.gif");
public static ImageIcon ADD_ICON = IconsHolder.loadIcon("add.gif");
public static ImageIcon ADDNEW_ICON = IconsHolder.loadIcon("AddNew.gif");
public static ImageIcon ASSOCIATION_ICON = IconsHolder.loadIcon("ModelElement_Association.gif");
public static ImageIcon ATTRIBUTE_ICON = IconsHolder.loadIcon("ModelElement_Attribute.gif");
//public static ImageIcon ENTITY_ICON = IconsHolder.loadIcon("ModelElement_Entity.gif");
public static ImageIcon ENTITY_ICON = IconsHolder.loadIcon("Graph_Entity.gif");
public static ImageIcon REPORT_ICON = IconsHolder.loadIcon("ModelElement_Report.gif");
public static ImageIcon MESSAGE_ICON = IconsHolder.loadIcon("ModelElement_Message.gif");
public static ImageIcon DOMAIN_ICON = IconsHolder.loadIcon("ModelElement_Domain.gif");
public static ImageIcon FIELDS_ICON = IconsHolder.loadIcon("Fields.gif");
public static ImageIcon ENTERPRISE_ICON = IconsHolder.loadIcon("ModelElement_Enterprise.gif");
public static ImageIcon SYSTEM_ICON = IconsHolder.loadIcon("ModelElement_System.gif");
public static ImageIcon PRIMARYKEY_ICON = IconsHolder.loadIcon("ModelElement_PrimaryKeyElement.gif");
public static ImageIcon SERVICEMODULE_ICON = IconsHolder.loadIcon("ModelElement_Servicemodule.gif");
public static ImageIcon SERVICEMODULESERVICE_ICON = IconsHolder.loadIcon("ModelElement_Service.gif");
public static ImageIcon STRUCTURE_ICON = IconsHolder.loadIcon("ModelElement_Structure.gif");
public static ImageIcon EDIT_ICON = IconsHolder.loadIcon("Edit.gif");
public static ImageIcon DELETE_ICON = IconsHolder.loadIcon("Delete.gif");
public static ImageIcon VIEWSTRUCTURE_ICON = IconsHolder.loadIcon("ViewStructure.gif");
public static ImageIcon VIEWSOURCE_ICON = IconsHolder.loadIcon("ViewSource.gif");
public static ImageIcon ADDSOURCE_ICON = IconsHolder.loadIcon("AddSource.gif");
public static ImageIcon DELETESOURCE_ICON = IconsHolder.loadIcon("DeleteSource.gif");
public static ImageIcon OPTIONS_ICON = IconsHolder.loadIcon("Options.gif");
public static ImageIcon SELECTOR_ICON = IconsHolder.loadIcon("ModelElement_Selector.gif");
public static ImageIcon ASSOCIATIONROLE_ICON = IconsHolder.loadIcon("ModelElement_AssociationRole.gif");
public static ImageIcon APPLICATION_ICON = IconsHolder.loadIcon("Application.gif");
public static ImageIcon STATE_ICON = IconsHolder.loadIcon("ModelElement_State.gif");
public static ImageIcon SEARCH_ICON = IconsHolder.loadIcon("Search.gif");
public static ImageIcon PRINT_ICON = IconsHolder.loadIcon("Print.gif");
public static ImageIcon BRINGTOFRONT_ICON = IconsHolder.loadIcon("BringToFront.gif");
public static ImageIcon BRINGTOBACK_ICON = IconsHolder.loadIcon("BringToBack.gif");
public static ImageIcon NORMALSIZE_ICON = IconsHolder.loadIcon("NormalSize.gif");
public static ImageIcon ZOOMIN_ICON = IconsHolder.loadIcon("ZoomIn.gif");
public static ImageIcon ZOOMOUT_ICON = IconsHolder.loadIcon("ZoomOut.gif");
public static ImageIcon FITTOSIZE_ICON = IconsHolder.loadIcon("FitToSize.gif");
public static ImageIcon UNSELECT_ICON = IconsHolder.loadIcon("Unselect.gif");
public static ImageIcon REFRESH_ICON = IconsHolder.loadIcon("Refresh.gif");
public static ImageIcon DATATYPE_ICON = IconsHolder.loadIcon("ModelElement_DataType.gif");
public static ImageIcon TYPETEMPLATE_ICON = IconsHolder.loadIcon("ModelElement_TypeTemplate.gif");
public static ImageIcon PROPERTY_ICON = IconsHolder.loadIcon("ModelElement_Property.gif");
public static ImageIcon PROPERTYDESCRIPTOR_ICON = IconsHolder.loadIcon("ModelElement_PropertyDescriptor.gif");
public static ImageIcon STATETRANSITION_ICON = IconsHolder.loadIcon("ModelElement_Transition.gif");
public static ImageIcon ALIGNTOGRID_ICON = IconsHolder.loadIcon("AlignToGrid.gif");
public static ImageIcon DOMAINCLASSDIAGRAM_ICON = IconsHolder.loadIcon("DomainClassDiagram.gif");
public static ImageIcon STATESDIAGRAM_ICON = IconsHolder.loadIcon("StatesDiagram.gif");
public static ImageIcon SYSTEMSDIAGRAM_ICON = IconsHolder.loadIcon("SystemsDiagram.gif");
public static ImageIcon SAVE_ICON = IconsHolder.loadIcon("Save.gif");
public static ImageIcon CHECK_ICON = IconsHolder.loadIcon("check.gif");
public static ImageIcon UNCHECK_ICON = IconsHolder.loadIcon("uncheck.gif");
public static ImageIcon SERVICEIMPL_ICON = IconsHolder.loadIcon("serviceimpl.gif");
public static ImageIcon OPERATION_ICON = IconsHolder.loadIcon("ModelElement_Operation.gif");
public static ImageIcon OUTMESSAGE_ICON = IconsHolder.loadIcon("ModelElement_OperationOutputMessage.gif");
public static ImageIcon REPORTOUTPUTELEMENT_ICON = IconsHolder.loadIcon("ModelElement_ReportOutputElement.gif");
public static ImageIcon CLASSDIAGRAM_ICON = IconsHolder.loadIcon("ClassDiagram.gif");
public static ImageIcon NAMESPACE_ICON = IconsHolder.loadIcon("ModelElement_Namespace.gif");
public static ImageIcon STORAGE_ICON = IconsHolder.loadIcon("ModelElement_StorageTechnology.gif");
public static ImageIcon DATADICTIONARY_ICON = IconsHolder.loadIcon("ModelElement_DataDictionary.gif");
public static ImageIcon VALIDATE_ICON = IconsHolder.loadIcon("Validate.gif");
public static ImageIcon KEYELEMENT_ICON = IconsHolder.loadIcon("KeyElement.gif");
public static ImageIcon ADDALLATTRIBUTES_ICON = IconsHolder.loadIcon("AddAllAttributes.gif");
public static ImageIcon DESIGNLIB_ICON = IconsHolder.loadIcon("ModelElement_DesignLibrary.gif");
public static ImageIcon TECHLIB_ICON = IconsHolder.loadIcon("ModelElement_TechnologyLibrary.gif");
public static ImageIcon OPEN_ICON = IconsHolder.loadIcon("Open.gif");
public static ImageIcon LIBRARY_ICON = IconsHolder.loadIcon("Library.gif");
public static ImageIcon COPYTOCLIP_ICON = IconsHolder.loadIcon("CopyToClipboard.gif");
public static ImageIcon CLEAR_ICON = IconsHolder.loadIcon("Clear.gif");
public static ImageIcon ENTITYTABLE_ICON = IconsHolder.loadIcon("EntityTable.gif");
public static ImageIcon ASSOCIATIONTABLE_ICON = IconsHolder.loadIcon("AssociationTable.gif");
public static ImageIcon TABLE_ICON = IconsHolder.loadIcon("Table.gif");
public static ImageIcon ATTRIBUTECOLUMN_ICON = IconsHolder.loadIcon("ModelElement_AttributeColumn.gif");
public static ImageIcon EXPORTXMI_ICON = IconsHolder.loadIcon("ExportXMI.gif");
public static ImageIcon DOMAINIMPL_ICON = IconsHolder.loadIcon("ModelElement_DomainImplementation.gif");
public static ImageIcon STATEMACHINE_ICON = IconsHolder.loadIcon("ModelElement_StateMachine.gif");
public static ImageIcon LEFT_ICON = IconsHolder.loadIcon("Left.gif");
public static ImageIcon LEFTLEFT_ICON = IconsHolder.loadIcon("LeftLeft.gif");
public static ImageIcon RIGHT_ICON = IconsHolder.loadIcon("Right.gif");
public static ImageIcon RIGHTRIGHT_ICON = IconsHolder.loadIcon("RightRight.gif");
public static ImageIcon COPYELEMENT_ICON = IconsHolder.loadIcon("CopyElement.gif");
public static ImageIcon INPUTFIELD_ICON = IconsHolder.loadIcon("ModelElement_InputField.gif");
public static ImageIcon OUTPUTFIELD_ICON = IconsHolder.loadIcon("ModelElement_OutputField.gif");
public static ImageIcon SEARCHDOWN_ICON = IconsHolder.loadIcon("SearchDown.gif");
public static ImageIcon SEARCHUP_ICON = IconsHolder.loadIcon("SearchUp.gif");
public static ImageIcon DESCRIPTION_ICON = IconsHolder.loadIcon("Description.gif");
public static ImageIcon ERRORSIGN_ICON = IconsHolder.loadIcon("ErrorSign.gif");
public static ImageIcon WARNINGSIGN_ICON = IconsHolder.loadIcon("Warning.gif");
public static ImageIcon MODELERROR_ICON = IconsHolder.loadIcon("ModelErrors.gif");
public static ImageIcon ELEMENTERROR_ICON = IconsHolder.loadIcon("ElementErrors.gif");
public static ImageIcon RECTIFY_ICON = IconsHolder.loadIcon("Rectify.gif");
public static ImageIcon EXPORTMBXMI_ICON = IconsHolder.loadIcon("ExportMetabossXMI.gif");
public static ImageIcon CONSTRAINT_ICON = IconsHolder.loadIcon("ModelElement_ModelElementConstraint.gif");
public static ImageIcon NEWMODEL_ICON = IconsHolder.loadIcon("NewModel.gif");
public static ImageIcon DIAGRAM_ICON = IconsHolder.loadIcon("Diagram.gif");
public static ImageIcon PASTE_ICON = IconsHolder.loadIcon("Paste.gif");
public static ImageIcon DELETEFROMMODEL_ICON = IconsHolder.loadIcon("DeleteFromModel.gif");
public static ImageIcon MOVEUP_ICON = IconsHolder.loadIcon("MoveUp.gif");
public static ImageIcon MOVEDOWN_ICON = IconsHolder.loadIcon("MoveDown.gif");
public static ImageIcon EXPANDTREE_ICON = IconsHolder.loadIcon("ExpandTree.gif");
public static ImageIcon COLLAPSETREE_ICON = IconsHolder.loadIcon("CollapseTree.gif");
public static ImageIcon BISTREAM_ICON = IconsHolder.loadIcon("Bistream.gif");
public static ImageIcon UPSTREAM_ICON = IconsHolder.loadIcon("Upstream.gif");
public static ImageIcon DOWNSTREAM_ICON = IconsHolder.loadIcon("Downstream.gif");
public static ImageIcon LESSDETAILS_ICON = IconsHolder.loadIcon("LessDetails.gif");
public static ImageIcon MOREDETAILS_ICON = IconsHolder.loadIcon("MoreDetails.gif");
public static ImageIcon ACTOR_ICON = IconsHolder.loadIcon("Actor.gif");
public static ImageIcon USECASE_ICON = IconsHolder.loadIcon("UseCase.gif");
public static ImageIcon USAGESPECIFICATION_ICON = IconsHolder.loadIcon("ModelElement_UsageSpecification.gif");
public static ImageIcon SYSTEMUSECASEDIAGRAM_ICON = IconsHolder.loadIcon("SystemUseCasesDiagram.gif");
public static ImageIcon EVENTSUBSCRIPTION_ICON = IconsHolder.loadIcon("ModelElement_EventSubscription.gif");
public static ImageIcon EVENT_ICON = IconsHolder.loadIcon("ModelElement_Event.gif");
public static ImageIcon SYNCEVENT_ICON = IconsHolder.loadIcon("SyncronisationEvent.gif");
public static ImageIcon GRAPH_ENTITY_ICON = IconsHolder.loadIcon("Graph_Entity.gif");
public static ImageIcon GRAPH_COMPOSITION_ICON = IconsHolder.loadIcon("Graph_Composition.gif");
public static ImageIcon GRAPH_AGREGATION_ICON = IconsHolder.loadIcon("Graph_Agregation.gif");
public static ImageIcon GRAPH_ASSOCIATION_ICON = IconsHolder.loadIcon("Graph_Association.gif");
public static ImageIcon GRAPH_GENERALIZATION_ICON = IconsHolder.loadIcon("Graph_Generalization.gif");
public static ImageIcon GRAPH_DEPENDENCY_ICON = IconsHolder.loadIcon("Graph_Dependency.gif");
public static ImageIcon GRAPH_SYSTEM_ICON = IconsHolder.loadIcon("Graph_System.gif");
public static ImageIcon GRAPH_CLASS_ICON = IconsHolder.loadIcon("Graph_Class.gif");
public static ImageIcon GRAPH_INITIALSTATE_ICON = IconsHolder.loadIcon("Graph_InitialState.gif");
public static ImageIcon GRAPH_FINALSTATE_ICON = IconsHolder.loadIcon("Graph_FinalState.gif");
public static ImageIcon GRAPH_PUBLIC_ICON = IconsHolder.loadIcon("public.gif");
private static Log sLogger = null;
private static String sModelTechLibFileName = null;
private static String sModelDesignLibFileName = null;
private static String sSaveModelName = null;
private static boolean sAddSeparator = false;
/** Design Center application main entry point */
public static void main(String[] args)
{
try
{
initialiseLogging();
com.metaboss.util.MetaBossSpecificUtils.setupSystemProperties();
loadLicenseInfo();
printStartupBanner();
resStrings = ResourceBundle.getBundle("com.metaboss.applications.designstudio.DesignStudioStrings");
splash = new SplashScreen();
UserPreferences.initialise(Application.sApplicationName);
checkPath();
sModelTechLibFileName = System.getProperty("MetaBoss.Home") + File.separator + "technologylib" + File.separator + "Model.xml";
sModelDesignLibFileName = System.getProperty("MetaBoss.Home") + File.separator + "designlib" + File.separator + "Model.xml";
// Start application
instance = new Application();
instance.loadSettings();
instance.configureUI();
instance.startUI();
// Mark the end of the startup
sLogger.info("Start up complete");
}
catch (Exception e)
{
e.printStackTrace();
}
}
private static void initialiseLogging()
{
// Override the console output
LogOutputStream lOutputStream = new LogOutputStream(System.out);
System.setOut(lOutputStream);
System.setErr(System.out);
// Init log4j stuff
Layout lLayout = new SimpleLayout();
Appender lAppender = new WriterAppender(lLayout,lOutputStream);
Logger lRootLogger = Logger.getRootLogger();
lRootLogger.setLevel(Level.INFO);
lRootLogger.addAppender(lAppender);
// Initialise looger only after dealing with log4j
sLogger = LogFactory.getLog(Application.class);
}
private static void printStartupBanner() throws Exception
{
// Print startup banner
loadLicenseInfo();
sLogger.info("MetaBoss Design Studio is starting up ....");
sLogger.info("Product Version: " + sLicenseService.getProductVersion() + " (Built on " + sLicenseService.getProductBuildDate() + " " + sLicenseService.getProductBuildTime() + ")");
sLogger.info(sLicenseService.getManufacturerCopyrightNotice());
}
public static void beginTransaction() throws Exception
{
if (sModelRepository!=null)
sModelRepository.beginTransaction();
}
public static void commit() throws Exception
{
if (sModelRepository!=null)
{
sModelRepository.commitTransaction();
if (properties.mAutoValidateModel)
validateModels(true, true);
}
}
public static void rollback() throws Exception
{
if (sModelRepository!=null)
sModelRepository.rollbackTransaction();
}
public static void checkAndRollback() throws Exception
{
if (sModelRepository!=null && isInTransaction()) rollback();
}
public static boolean isInTransaction()
{
try
{
return (sModelRepository!=null && sModelRepository.isInTransaction());
}
catch (Exception e)
{
return false;
}
}
// return ModelElement by its ID
public static ModelElement getModelElementByID(String ID)
{
ModelElement lResult =null;
if (sModelRepository!=null)
{
try
{
javax.jmi.reflect.RefBaseObject lObject = sModelRepository.getModelObjectByRepositoryId(ID);
if (lObject instanceof ModelElement)
lResult = (ModelElement)lObject;
}
catch (Exception e)
{
lResult =null;
}
}
return lResult;
}
// return UserObject by ID
public static BaseUserObject getUserObjectByID(String ID)
{
ModelElement lElement = getModelElementByID(ID);
if (lElement!=null)
return UserObjectFactory.createUserObject(lElement);
else
return null;
}
public static BaseUserObject getCurrentUserObject()
{
if (mainFrame!=null && mainFrame.mTreePanel!=null)
return mainFrame.mTreePanel.getCurrentUserObject();
else
return null;
}
// return registration key
public static boolean getRegistered()
{
return (sLicenseService!=null) ? sLicenseService.isProductCommerciallyLicensed() : false;
}
// return Application Version
public static String getVersionString()
{
Object[] arguments = {getVersion(), getBuildDate()};
return java.text.MessageFormat.format("Version {0} (build date {1})", arguments );
}
public static String getVersion()
{
String lMajor = System.getProperty("com.metaboss.release.id.majorversion");
String lMinor = System.getProperty("com.metaboss.release.id.minorversion");
String lBuild = System.getProperty("com.metaboss.release.id.buildnumber");
return lMajor + "." + lMinor + "." + lBuild;
}
public static String getBuildDate()
{
String lDate = System.getProperty("com.metaboss.release.id.builddate");
String lTime = System.getProperty("com.metaboss.release.id.buildtime");
return lDate + " " + lTime;
}
// return resource string
public static String getString(String pTitle)
{
String lResult = null;
try
{
lResult = resStrings.getString(pTitle);
}
catch (Exception e)
{
e.printStackTrace();
lResult = null;
}
return lResult;
}
// show error message
public static void showError(String pError)
{
JOptionPane.showMessageDialog(mainFrame, pError, "Error", JOptionPane.ERROR_MESSAGE);
}
// show warning message
public static void showWarning(String pWarning)
{
JOptionPane.showMessageDialog(mainFrame, pWarning, "Warning", JOptionPane.WARNING_MESSAGE);
}
// show information message
public static void showInformation(String pInformation)
{
JOptionPane.showMessageDialog(mainFrame, pInformation, "Information", JOptionPane.INFORMATION_MESSAGE);
}
// process exception
public static void processError(Throwable e)
{
if (e==null) return;
if (e instanceof ModelWarning)
{
String lString = e.getMessage();
if (lString!=null && lString.length()>0)
{
String lMessage = e.getMessage();
System.err.println(lMessage);
showWarning(lMessage);
}
}
else
{
e.printStackTrace();
String lString = e.getMessage();
if (lString!=null && lString.length()>0)
showError(e.getMessage());
}
}
// draw and return "object add" icon
public static ImageIcon getAddIcon(ImageIcon pRealIcon)
{
BufferedImage lImage = new BufferedImage(pRealIcon.getIconWidth(), pRealIcon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics lGraphics = lImage.getGraphics();
ImageIcon lAddIcon = Application.ADD_ICON;
pRealIcon.paintIcon(null, lGraphics, -2, 2);
lAddIcon.paintIcon(null, lGraphics, lImage.getWidth()-lAddIcon.getIconWidth(), 0);
return new ImageIcon(lImage);
}
// draw and return "key" icon
public static ImageIcon getKeyIcon(ImageIcon pRealIcon)
{
BufferedImage lImage = new BufferedImage(pRealIcon.getIconWidth(), pRealIcon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics lGraphics = lImage.getGraphics();
ImageIcon lKeyIcon = Application.KEYELEMENT_ICON;
pRealIcon.paintIcon(null, lGraphics, 0, 0);
lKeyIcon.paintIcon(null, lGraphics, 0, lImage.getHeight()-lKeyIcon.getIconHeight());
return new ImageIcon(lImage);
}
// draw and return "error" icon
public static ImageIcon getErrorIcon(Icon pRealIcon)
{
BufferedImage lImage = new BufferedImage(pRealIcon.getIconWidth(), pRealIcon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics lGraphics = lImage.getGraphics();
ImageIcon lIcon = Application.ERRORSIGN_ICON;
pRealIcon.paintIcon(null, lGraphics, 0, 0);
lIcon.paintIcon(null, lGraphics, 0, lImage.getHeight()-lIcon.getIconHeight());
return new ImageIcon(lImage);
}
// draw and return "warning" icon
public static ImageIcon getWarningIcon(Icon pRealIcon)
{
BufferedImage lImage = new BufferedImage(pRealIcon.getIconWidth(), pRealIcon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics lGraphics = lImage.getGraphics();
ImageIcon lIcon = Application.WARNINGSIGN_ICON;
pRealIcon.paintIcon(null, lGraphics, 0, 0);
lIcon.paintIcon(null, lGraphics, 0, lImage.getHeight()-lIcon.getIconHeight());
return new ImageIcon(lImage);
}
public static void defineButton(AbstractButton pButton)
{
if (pButton==null) return;
pButton.setText("");
pButton.setFocusable(false);
pButton.setMaximumSize(new Dimension(24, 24));
pButton.setMinimumSize(new Dimension(24, 24));
pButton.setPreferredSize(new Dimension(24, 24));
}
// Options Event
public static void addOptionsEventListener(OptionsChangedListener listener)
{
if (instance!=null)
instance.listenerList.add(OptionsChangedListener.class, listener);
}
public static void removeOptionsEventListener(OptionsChangedListener listener)
{
if (instance!=null)
instance.listenerList.remove(OptionsChangedListener.class, listener);
}
// Refresh Event
public static void addRefreshListener(RefreshListener listener)
{
if (instance!=null)
instance.listenerList.add(RefreshListener.class, listener);
}
public static void removeRefreshListener(RefreshListener listener)
{
if (instance!=null)
instance.listenerList.remove(RefreshListener.class, listener);
}
// Model Changed Event
public static void addObjectChanged(ObjectChangedListener listener)
{
if (instance!=null)
instance.listenerList.add(ObjectChangedListener.class, listener);
}
public static void removeObjectChanged(ObjectChangedListener listener)
{
if (instance!=null)
instance.listenerList.remove(ObjectChangedListener.class, listener);
}
// Show Container Event
public static void addContainerShowListener(ShowContainerListener listener)
{
if (instance!=null)
instance.listenerList.add(ShowContainerListener.class, listener);
}
public static void removeContainerShowListener(ShowContainerListener listener)
{
if (instance!=null)
instance.listenerList.remove(ShowContainerListener.class, listener);
}
// On Container close Event
public static void addOnContainerCloseListener(OnContainerCloseListener listener)
{
if (instance!=null)
instance.listenerList.add(OnContainerCloseListener.class, listener);
}
public static void removeOnContainerCloseListener(OnContainerCloseListener listener)
{
if (instance!=null)
instance.listenerList.remove(OnContainerCloseListener.class, listener);
}
// On Container Changed Event
public static void addOnContainerChangedListener(OnContainerChangedListener listener)
{
if (instance!=null)
instance.listenerList.add(OnContainerChangedListener.class, listener);
}
public static void removeOnContainerChangedListener(OnContainerChangedListener listener)
{
if (instance!=null)
instance.listenerList.remove(OnContainerChangedListener.class, listener);
}
// On Errors Found Event
public static void addOnErrorsFoundListener(OnErrorsFoundListener listener)
{
if (instance!=null)
instance.listenerList.add(OnErrorsFoundListener.class, listener);
}
public static void removeOnErrorsFoundListener(OnErrorsFoundListener listener)
{
if (instance!=null)
instance.listenerList.remove(OnErrorsFoundListener.class, listener);
}
// On Current Model Changed
public static void addOnModelChangedListener(OnModelChangedListener listener)
{
if (instance!=null)
instance.listenerList.add(OnModelChangedListener.class, listener);
}
public static void removeOnModelChangedListener(OnModelChangedListener listener)
{
if (instance!=null)
instance.listenerList.remove(OnModelChangedListener.class, listener);
}
// Model Closed
public static void addCloseModelListener(CloseModelListener listener)
{
if (instance!=null)
instance.listenerList.add(CloseModelListener.class, listener);
}
public static void removeCloseModelListener(CloseModelListener listener)
{
if (instance!=null)
instance.listenerList.remove(CloseModelListener.class, listener);
}
// Diagram Changed
public static void addRefreshDiagramsListener(RefreshDiagramsEventListener listener)
{
if (instance!=null)
instance.listenerList.add(RefreshDiagramsEventListener.class, listener);
}
public static void removeRefreshDiagramsListener(RefreshDiagramsEventListener listener)
{
if (instance!=null)
instance.listenerList.remove(RefreshDiagramsEventListener.class, listener);
}
// Index changed
public static void addElementIndexChangedEvent(OnElemenIndexChangedEventListener listener)
{
if (instance!=null)
instance.listenerList.add(OnElemenIndexChangedEventListener.class, listener);
}
public static void removeElementIndexChangedEvent(OnElemenIndexChangedEventListener listener)
{
if (instance!=null)
instance.listenerList.remove(OnElemenIndexChangedEventListener.class, listener);
}
// fire Properties changed event
public static void fireOptionsChanged(boolean pMetabossChanged)
{
if (instance!=null) instance.fireOptionsChangedEvent(pMetabossChanged);
}
public void fireOptionsChangedEvent(boolean pMetabossChanged)
{
OptionsChangedEvent lEvent = new OptionsChangedEvent(pMetabossChanged);
EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
queue.postEvent(lEvent);
}
// fire Refresh event
public static void fireRefresh()
{
if (instance!=null) instance.fireRefreshEvent();
}
public void fireRefreshEvent()
{
RefreshEvent lEvent = new RefreshEvent();
EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
queue.postEvent(lEvent);
}
// fire Model Changed event
public static void fireObjectSelected(BaseUserObject pUserObject)
{
if (instance!=null) instance.fireObjectChanged(pUserObject, ObjectChangedEvent.ET_SELECTED);
}
public static void fireObjectSelect(BaseUserObject pUserObject)
{
if (instance!=null) instance.fireObjectChanged(pUserObject, ObjectChangedEvent.ET_SELECT);
}
public static void fireObjectEdited(BaseUserObject pUserObject)
{
if (instance!=null) instance.fireObjectChanged(pUserObject, ObjectChangedEvent.ET_EDITED);
}
public static void fireObjectDeleted(String pID, String pModelName)
{
if (instance!=null) instance.fireObjectChanged(pID, pModelName, ObjectChangedEvent.ET_DELETED);
}
public static void fireObjectDeleted(BaseUserObject pUserObject)
{
if (instance!=null) instance.fireObjectChanged(pUserObject, ObjectChangedEvent.ET_DELETED);
}
public static void fireObjectInserted(BaseUserObject pUserObject)
{
if (instance!=null) instance.fireObjectChanged(pUserObject, ObjectChangedEvent.ET_INSERTED);
}
public void fireObjectChanged(BaseUserObject pObject, int pSource)
{
ObjectChangedEvent lEvent = new ObjectChangedEvent(pObject, pSource);
EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
queue.postEvent(lEvent);
}
public void fireObjectChanged(String pID, String pModelName, int pSource)
{
ObjectChangedEvent lEvent = new ObjectChangedEvent(pID, pModelName, pSource);
EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
queue.postEvent(lEvent);
}
public static void fireObjectMoved(BaseUserObject pUserObject)
{
if (instance!=null) instance.fireObjectChanged(pUserObject, ObjectChangedEvent.ET_MOVED);
}
// fire Show Container event
public static void fireShowContainer(BaseChildPanel pContainer, BaseUserObject pObject)
{
if (instance!=null) instance.fireShowContainerEvent(pContainer, pObject, null);
}
public static void fireShowContainer(BaseChildPanel pContainer, BaseUserObject pObject, Icon pIcon)
{
if (instance!=null) instance.fireShowContainerEvent(pContainer, pObject, pIcon);
}
public void fireShowContainerEvent(BaseChildPanel pContainer, BaseUserObject pObject, Icon pIcon)
{
ShowContainerEvent lEvent = new ShowContainerEvent(pContainer, pObject, pIcon);
EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
queue.postEvent(lEvent);
}
// fire On Container close event
public static void fireOnContainerClose(BaseChildPanel pContainer)
{
if (instance!=null) instance.fireOnContainerCloseEvent(pContainer);
}
public void fireOnContainerCloseEvent(BaseChildPanel pContainer)
{
OnContainerCloseEvent lEvent = new OnContainerCloseEvent(pContainer);
EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
queue.postEvent(lEvent);
}
// fire On Container Changed event
public static void fireOnContainerChanged(Container pContainer)
{
if (instance!=null) instance.fireOnContainerChangedEvent(pContainer);
}
public void fireOnContainerChangedEvent(Container pContainer)
{
OnContainerChangedEvent lEvent = new OnContainerChangedEvent(pContainer);
EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
queue.postEvent(lEvent);
}
// fire On Errors Found event
public static void fireOnErrorsFound()
{
if (instance!=null) instance.fireOnErrorsFoundEvent();
}
public void fireOnErrorsFoundEvent()
{
OnErrorsFoundEvent lEvent = new OnErrorsFoundEvent();
EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
queue.postEvent(lEvent);
}
// fire On Current Model Changed event
public static void fireOnCurrentModelChanged()
{
if (instance!=null) instance.fireOnCurrentModelChangedEvent();
}
public void fireOnCurrentModelChangedEvent()
{
OnModelChangedEvent lEvent = new OnModelChangedEvent(Application.getCurrentPackage(), OnModelChangedEvent.CURRENT_CHANGED);
EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
queue.postEvent(lEvent);
}
// fire Model closed
public static void fireOnModelClosed(ModelUserObject pModel)
{
if (instance!=null) instance.fireOnModelClosedEvent(pModel);
}
public void fireOnModelClosedEvent(ModelUserObject pModel)
{
OnModelChangedEvent lEvent = new OnModelChangedEvent(pModel, OnModelChangedEvent.MODEL_CLOSED);
EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
queue.postEvent(lEvent);
}
// fire Model opened
public static void fireOnModelOpened(ModelUserObject pModel)
{
if (instance!=null) instance.fireOnModelOpenedEvent(pModel);
}
public void fireOnModelOpenedEvent(ModelUserObject pModel)
{
OnModelChangedEvent lEvent = new OnModelChangedEvent(pModel, OnModelChangedEvent.MODEL_OPENED);
EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
queue.postEvent(lEvent);
}
// fire Model saved
public static void fireOnModelSaved(ModelUserObject pModel)
{
if (instance!=null) instance.fireOnModelSavedEvent(pModel);
}
public void fireOnModelSavedEvent(ModelUserObject pModel)
{
OnModelChangedEvent lEvent = new OnModelChangedEvent(pModel, OnModelChangedEvent.MODEL_SAVED);
EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
queue.postEvent(lEvent);
}
// fire Close Model event
public static void fireCloseModel(ModelUserObject pModel)
{
if (instance!=null) instance.fireCloseModelEvent(pModel);
}
public void fireCloseModelEvent(ModelUserObject pModel)
{
CloseModelEvent lEvent = new CloseModelEvent(pModel);
EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
queue.postEvent(lEvent);
}
// fire Refresh Diagram event
public static void fireRefreshDiagram(Diagram pDiagram, BaseUserObject pUserObject)
{
if (instance!=null) instance.fireRefreshDiagramEvent(pDiagram, pUserObject);
}
public void fireRefreshDiagramEvent(Diagram pDiagram, BaseUserObject pUserObject)
{
RefreshDiagramsEvent lEvent = new RefreshDiagramsEvent(pDiagram, pUserObject);
EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
queue.postEvent(lEvent);
}
// fire Index Changed event
public static void fireIndexChanged(BaseUserObject pUserObject, int pOldIndex, int pNewIndex)
{
if (instance!=null) instance.fireIndexChangedEvent(pUserObject, pOldIndex, pNewIndex);
}
public void fireIndexChangedEvent(BaseUserObject pUserObject, int pOldIndex, int pNewIndex)
{
OnElementIndexChangedEvent lEvent = new OnElementIndexChangedEvent(pUserObject, pOldIndex, pNewIndex);
EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
queue.postEvent(lEvent);
}
// exit application
public static void exit()
{
if (mainFrame!=null) mainFrame.beforeClose();
instance.saveSettings();
System.exit(0);
}
// fill actions
public static void fillActions(BaseUserObject pUserObject,
JToolBar pToolBar, JMenu pMenu, JPopupMenu pPopupMenu)
{
clearOldItems(pToolBar, pMenu, pPopupMenu);
Object[] lActions = (pUserObject!=null) ? pUserObject.getActions() : null;
simpleFillActions(lActions, pToolBar, pMenu, pPopupMenu);
if (pToolBar!=null) pToolBar.repaint();
}
public static void fillActions(Object[] pActions,
JToolBar pToolBar, JMenu pMenu, JPopupMenu pPopupMenu)
{
clearOldItems(pToolBar, pMenu, pPopupMenu);
simpleFillActions(pActions, pToolBar, pMenu, pPopupMenu);
if (pToolBar!=null) pToolBar.repaint();
}
public static void simpleFillActions(Object[] pActions,
JToolBar pToolBar, JMenu pMenu, JPopupMenu pPopupMenu)
{
try
{
if (pActions!=null)
for (int i=0; i<pActions.length; i++)
fillAction((Action)pActions[i], pToolBar, pMenu, pPopupMenu);
if (pMenu!=null) pMenu.setEnabled(pMenu.getItemCount()>0);
}
finally
{
sAddSeparator = false;
}
}
// fill button and menuitems for action
public static void fillAction(Action pAction,
JToolBar pToolBar, JMenu pMenu, JPopupMenu pPopupMenu)
{
if (pAction instanceof SeparatorAction)
{
if (pToolBar!=null) sAddSeparator = true;
if (pMenu!=null && pMenu.getItemCount()>0) pMenu.addSeparator();
if (pPopupMenu!=null) pPopupMenu.addSeparator();
} else
if (pAction instanceof ContainerAction)
{
JMenu pBar = new JMenu(pAction);
if (pMenu!=null) pMenu.add(pBar);
if (pPopupMenu!=null) pPopupMenu.add(pBar);
simpleFillActions(((ContainerAction)pAction).getActions(), pToolBar, pBar, null);
}
else
{
boolean lAddToToolBar = true;
boolean lAddToMenu = true;
boolean lAddToPopUp = true;
if (pAction instanceof BaseAction)
{
lAddToToolBar = ((BaseAction)pAction).getAddToToolBar() && ((BaseAction)pAction).getValue(Action.SMALL_ICON)!=null;
lAddToMenu = ((BaseAction)pAction).mAddToMenu;
lAddToPopUp = ((BaseAction)pAction).mAddToPopUp;
}
if (pToolBar!=null && lAddToToolBar)
{
if (sAddSeparator)
{
if (pToolBar.getComponentCount()>0)
pToolBar.add(new ToolBarSeparator(pToolBar));
sAddSeparator = false;
}
pToolBar.add(createButton(pAction));
}
if (pMenu!=null && lAddToMenu)
pMenu.add(createMenuItem(pAction));
if (pPopupMenu!=null && lAddToPopUp)
pPopupMenu.add(createMenuItem(pAction));
}
}
public static JMenuItem createMenuItem(Action pAction)
{
JMenuItem lResult = null;
if (pAction!=null && pAction instanceof BaseAction)
{
if (((BaseAction)pAction).isCheck())
{
JCheckBoxMenuItem lItem = new JCheckBoxMenuItem(pAction);
lItem.setState(((BaseAction)pAction).isChecked());
lResult = lItem;
}
}
if (lResult==null) lResult = new JMenuItem(pAction);
lResult.setToolTipText(null);
return lResult;
}
public static AbstractButton createButton(Action pAction)
{
AbstractButton lResult = null;
if (pAction!=null && pAction instanceof BaseAction && ((BaseAction)pAction).isCheck())
{
lResult = new JToggleButton(pAction);
if (((BaseAction)pAction).getSelectedIcon()!=null)
lResult.setSelectedIcon(((BaseAction)pAction).getSelectedIcon());
ButtonGroup lGroup = ((BaseAction)pAction).getButtonGroup();
if (lGroup!=null) lGroup.add(lResult);
}
else
lResult = new JButton(pAction);
defineButton(lResult);
return lResult;
}
// clear old items and buttons
public static void clearOldItems(JToolBar pToolBar, JMenu pMenu, JPopupMenu pPopupMenu)
{
if (pMenu!=null) pMenu.removeAll();
if (pToolBar!=null) pToolBar.removeAll();
if (pPopupMenu!=null) pPopupMenu.removeAll();
}
// laod application settings
public void loadSettings()
{
try
{
Application.properties.loadProperties();
}
catch(Exception e)
{
e.printStackTrace();
properties.setDefaultValues();
}
loadModels();
}
// save application settings
public void saveSettings()
{
try
{
Application.properties.saveProperties();
}
catch(Exception e)
{
e.printStackTrace();
}
try
{
sModelRepository.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
// get current package
public static ModelUserObject getCurrentPackage()
{
if (mainFrame!=null)
return mainFrame.getCurrentPackage();
return null;
}
// get models count
public static int getModelsCount()
{
return sModels.size();
}
// return model user object by index
public static ModelUserObject getModel(int index)
{
ModelUserObject lResult = null;
try
{
lResult = (ModelUserObject)sModels.get(index);
}
catch (Exception e)
{
lResult = null;
}
return lResult;
}
public static ModelUserObject getModel(String pFileName)
{
for (int i=0; i<sModels.size(); i++)
{
ModelUserObject lModel = getModel(i);
if (lModel.getFileName().equals(pFileName)) return lModel;
}
return null;
}
public static ModelUserObject getModel(MetaBossModelPackage pPackage)
{
for (int i=0; i<sModels.size(); i++)
{
ModelUserObject lModel = getModel(i);
if (lModel.getPackage().equals(pPackage)) return lModel;
}
return null;
}
// create Model
public static void createModel()
{
JFileChooser lChooser = new JFileChooser();
ModelFileFilter lFilter = new ModelFileFilter();
lChooser.setDialogTitle("Select New Model Root Directory");
lChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
if (Application.properties.mLastDir!=null)
lChooser.setCurrentDirectory((new File(Application.properties.mLastDir)).getParentFile());
int returnVal = lChooser.showDialog(mainFrame, "Select");
if (returnVal == JFileChooser.APPROVE_OPTION)
{
String lPath = lChooser.getSelectedFile().getPath();
String lFileName = lPath + File.separator + "Model.xml";
File lFile = new File(lPath);
if (lFile.exists() && lFile.list().length>0)
{
int n = JOptionPane.showConfirmDialog(null,
Application.getString("nonemptydir_query"),
"Confirm", JOptionPane.YES_NO_OPTION);
if (n!=0) return;
}
try
{
ModelUserObject lModel = new ModelUserObject(lFileName, true, false);
sModels.add(lModel);
if (lModel!=null)
{
fireOnModelOpened(lModel);
Application.properties.mLastDir = lFileName;
}
}
catch (Exception e)
{
processError(e);
}
}
}
// open Model
public static void openModel()
{
JFileChooser lChooser = new JFileChooser();
ModelFileFilter lFilter = new ModelFileFilter();
lChooser.setDialogTitle("Open Model");
lFilter.addExtension("xml");
lFilter.setDescription("MetaBoss Model files");
lChooser.setFileFilter(lFilter);
if (Application.properties.mLastDir!=null)
lChooser.setCurrentDirectory((new File(Application.properties.mLastDir)).getParentFile());
int returnVal = lChooser.showOpenDialog(mainFrame);
if (returnVal == JFileChooser.APPROVE_OPTION)
{
try
{
String lPath = lChooser.getSelectedFile().getPath();
openModel(lPath);
properties.mLastDir = lPath;
}
catch (Exception e)
{
processError(e);
}
}
}
public static void openModel(String pFileName) throws Exception
{
Cursor lCursor = mainFrame.getCursor();
try
{
mainFrame.setCursor(new Cursor(Cursor.WAIT_CURSOR));
ModelUserObject lModel = getModel(pFileName);
if (lModel==null)
{
lModel = new ModelUserObject(pFileName, false, false);
sModels.add(lModel);
properties.removeFromReopen(pFileName);
}
if (lModel!=null) fireOnModelOpened(lModel);
}
finally
{
mainFrame.setCursor(lCursor);
}
}
// close Model
public static void closeModel(ModelUserObject pModel, boolean pSilent, boolean pSave)
{
if (pModel==null) return;
if (pModel.isModified() && pSave)
{
try
{
if (pSilent)
saveModel(pModel);
else
{
int n = JOptionPane.showConfirmDialog(null,
"\"" + pModel.getModelName() + "\" has been modified! Save changes?",
"Confirm", JOptionPane.YES_NO_CANCEL_OPTION);
if (n==0)
saveOneModel(pModel);
else
if (n==2)
return;
}
}
catch (Exception e)
{
processError(e);
}
}
try
{
pModel.closeModel();
}
catch (Exception e)
{
processError(e);
}
}
// close all models
public static void closeAllModels() throws Exception
{
ArrayList lList = new ArrayList();
for (int i=0; i<getModelsCount(); i++)
{
ModelUserObject lObject = getModel(i);
if (lObject.isModified()) lList.add(lObject);
}
if (lList.size()>0)
{
SaveContentDialog lDialog = new SaveContentDialog(mainFrame, lList);
if (lDialog.getModalResult()==SaveContentDialog.MR_OK)
{
for (int i=0; i<getModelsCount(); i++)
{
ModelUserObject lObject = getModel(i);
closeModel(lObject, true, lList.contains(lObject));
}
}
}
}
// load Metaboss Models
public static void loadModels()
{
sModels.clear();
try
{
Context lContext = new InitialContext();
sModelRepository = (ModelRepository)lContext.lookup(ModelRepository.COMPONENT_URL);
}
catch (Exception e)
{
sModelRepository = null;
e.printStackTrace();
}
if (sModelRepository!=null)
{
//??? Enterprise Models
for (int i=0; i<properties.mPreLoadModels.size(); i++)
{
String lFileName = (String)properties.mPreLoadModels.get(i);
if (lFileName!=null)
{
File lFile = new File(lFileName);
if (lFile.exists())
{
try
{
sModels.add(new ModelUserObject(lFileName, false, false));
}
catch (Exception e)
{
e.printStackTrace();
}
}
else
{
String lError = java.text.MessageFormat.format("File \"{0}\" is not found. Design studio is unable to open the model!", new Object[] {lFileName});
System.err.println(lError);
}
}
}
//??? design lib
try
{
sModels.add(new ModelUserObject(sModelDesignLibFileName, false, true));
}
catch (Exception e)
{
e.printStackTrace();
}
//??? tech lib
try
{
sModels.add(new ModelUserObject(sModelTechLibFileName, false, true));
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
// get count of modified models
public static int getModifiedModelsCount()
{
int lResult = 0;
try
{
String[] lModels = sModelRepository.listModelNames();
if (lModels!=null)
for (int i=0; i<lModels.length; i++)
if (sModelRepository.isModelModified(lModels[i]))
lResult++;
}
catch (Exception e)
{
lResult = 0;
}
return lResult;
}
// save Metaboss models
public static void saveModels(boolean pShowDialog, boolean pClose) throws Exception
{
Cursor lCursor = mainFrame.getCursor();
try
{
mainFrame.setCursor(new Cursor(Cursor.WAIT_CURSOR));
sModelErrors.clear();
sSaveModelName = null;
if (pShowDialog)
{
ArrayList lList = new ArrayList();
for (int i=0; i<getModelsCount(); i++)
{
ModelUserObject lObject = getModel(i);
if (lObject.isModified()) lList.add(lObject);
}
if (lList.size()>0)
{
SaveContentDialog lDialog = new SaveContentDialog(mainFrame, lList);
if (lDialog.getModalResult()==SaveContentDialog.MR_OK)
{
for (int i=0; i<getModelsCount(); i++)
{
ModelUserObject lObject = getModel(i);
if (lList.contains(lObject)) saveModel(lObject);
}
}
else
throw new Exception();
}
}
else
{
String[] lModels = sModelRepository.listModelNames();
if (lModels!=null)
for (int i=0; i<lModels.length; i++)
saveModel(lModels[i]);
}
fireOnErrorsFound();
if (sModelErrors.size()>0) showErrorsFound(pClose);
}
finally
{
mainFrame.setCursor(lCursor);
}
}
// check for errors
public static boolean errorsFound()
{
return sModelErrors.size()>0;
}
public static void setErrorElementID(String pID)
{
if ((sErrorElement!=null && pID==null) || (sErrorElement==null && pID!=null) ||
(sErrorElement!=null && !sErrorElement.equals(pID)))
{
sErrorElement = pID;
fireOnErrorsFound();
}
}
private static void saveInvalidModels() throws Exception
{
if (sSaveModelName!=null)
saveModelNoValidate(sSaveModelName);
else
{
for (int i=0; i<sModelErrors.size(); i++)
{
ModelErrorDescription lDescription = (ModelErrorDescription)sModelErrors.get(i);
if (lDescription!=null) saveModelNoValidate(lDescription.getModelName());
}
}
}
// delete errors of the given model
public static void removeModelErrors(ModelUserObject pModel)
{
if (pModel!=null)
{
int i = 0;
while (i<sModelErrors.size())
{
ModelErrorDescription lDescription = (ModelErrorDescription)sModelErrors.get(i);
if (lDescription.getModelName().equals(pModel.getFileName()))
sModelErrors.remove(lDescription);
else
i++;
}
}
}
public static void removeModelErrors(String pModelName)
{
if (pModelName!=null)
{
int i = 0;
while (i<sModelErrors.size())
{
ModelErrorDescription lDescription = (ModelErrorDescription)sModelErrors.get(i);
if (lDescription.getModelName().equals(pModelName))
sModelErrors.remove(lDescription);
else
i++;
}
}
}
public static int getModelErrorsCount(ModelUserObject pModel)
{
int lResult = 0;
for (int i=0; i<sModelErrors.size(); i++)
{
ModelErrorDescription lDescription = (ModelErrorDescription)sModelErrors.get(i);
if (lDescription.getModelName().equals(pModel.getFileName()))
lResult++;
}
return lResult;
}
// show Errors dialog
private static void showErrorsFound(boolean pClose) throws Exception
{
if (properties.mValidateModelOnSave)
{
if (pClose)
{
int n = JOptionPane.showConfirmDialog(mainFrame,
getString("save_errors") + getString("save_errors_prompt0"),
getString("save_errors_caption"), JOptionPane.YES_NO_CANCEL_OPTION);
switch (n)
{
case 0:
saveInvalidModels();
break;
case 2:
throw new Exception();
}
}
else
{
int n = JOptionPane.showConfirmDialog(mainFrame,
getString("save_errors") + getString("save_errors_prompt1"),
getString("save_errors_caption"), JOptionPane.YES_NO_OPTION);
switch (n)
{
case 0:
saveInvalidModels();
break;
}
}
}
else
saveInvalidModels();
}
// validate and save model
public static void saveModel(String pModelName) throws Exception
{
if (sModelRepository.isModelModified(pModelName))
{
try
{
sModelRepository.saveModel(pModelName, true);
fireOnModelSaved(getModel(pModelName));
}
catch (ModelValidationException e)
{
sModelErrors.add(new ModelErrorDescription(pModelName, e));
}
catch (Exception e)
{
processError(e);
}
}
}
public static void saveModel(ModelUserObject pModel) throws Exception
{
saveModel(pModel.getFileName());
}
public static void saveOneModel(ModelUserObject pModel) throws Exception
{
Cursor lCursor = mainFrame.getCursor();
try
{
mainFrame.setCursor(new Cursor(Cursor.WAIT_CURSOR));
sSaveModelName = pModel.getFileName();
try
{
try
{
removeModelErrors(pModel);
saveModel(pModel.getFileName());
}
catch (Exception e)
{
processError(e);
}
fireOnErrorsFound();
if (getModelErrorsCount(pModel)>0) showErrorsFound(false);
}
finally
{
sSaveModelName = null;
}
}
finally
{
mainFrame.setCursor(lCursor);
}
}
// save model withouot validation
public static void saveModelNoValidate(String pModelName) throws Exception
{
if (sModelRepository.isModelModified(pModelName))
{
try
{
sModelRepository.saveModel(pModelName, false);
fireOnModelSaved(getModel(pModelName));
}
catch (Exception e)
{
processError(e);
}
}
}
public static void saveModelNoVlidate(ModelUserObject pModel) throws Exception
{
saveModelNoValidate(pModel.getFileName());
//fireOnModelSaved(pModel);
}
public static int getErrorsCount()
{
int lResult = 0;
for (int i=0; i<sModelErrors.size(); i++)
lResult += ((ModelErrorDescription)sModelErrors.get(i)).getCount();
return lResult;
}
// check element ID
public static boolean isErrorElementID(String pID)
{
if (pID!=null)
{
for (int i=0; i<sModelErrors.size(); i++)
{
ModelErrorDescription lDescription = (ModelErrorDescription)sModelErrors.get(i);
if (lDescription!=null)
{
for (int k=0; k<lDescription.getCount(); k++)
{
ModelValidationException lError = lDescription.getError();
if (lError!=null)
{
String lID = lError.getErrorModelElementRepositoryId(k);
if (lID!=null && lID.equals(pID))
return true;
}
}
}
}
}
return false;
}
// validate models
public static void validateModels(boolean pSilent, boolean pCheck)
{
Cursor lCursor = mainFrame.getCursor();
try
{
mainFrame.setCursor(new Cursor(Cursor.WAIT_CURSOR));
int lErrorsCount = getErrorsCount();
try
{
//???sModelErrors.clear();
String[] lModels = sModelRepository.listModelNames();
if (lModels!=null)
for (int i=0; i<lModels.length; i++)
if (!pCheck || sModelRepository.isModelModified(lModels[i]))
validateModel(lModels[i]);
}
catch(Exception e)
{
e.printStackTrace();
}
int lNewErrorsCount = getErrorsCount();
if (/*!pSilent ||*/ lErrorsCount!=lNewErrorsCount)
fireOnErrorsFound();
if (!pSilent && lNewErrorsCount==0)
showInformation(getString("validation_ok"));
}
finally
{
mainFrame.setCursor(lCursor);
}
}
// validate and save model
public static void validateModel(String pModelName) throws Exception
{
try
{
removeModelErrors(pModelName);
sModelRepository.validateModel(pModelName);
}
catch (ModelValidationException e)
{
sModelErrors.add(new ModelErrorDescription(pModelName, e));
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void validateModel(ModelUserObject pModel)
{
Cursor lCursor = mainFrame.getCursor();
try
{
mainFrame.setCursor(new Cursor(Cursor.WAIT_CURSOR));
try
{
validateModel(pModel.getFileName());
}
catch (Exception e)
{
e.printStackTrace();
}
fireOnErrorsFound();
}
finally
{
mainFrame.setCursor(lCursor);
}
}
// rectify model
public static void rectifyModel(String pModelName)
{
try
{
sModelRepository.rectifyModel(pModelName);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void rectifyModel(ModelUserObject pModel)
{
Cursor lCursor = mainFrame.getCursor();
try
{
mainFrame.setCursor(new Cursor(Cursor.WAIT_CURSOR));
try
{
removeModelErrors(pModel);
rectifyModel(pModel.getFileName());
}
catch (Exception e)
{
e.printStackTrace();
}
}
finally
{
mainFrame.setCursor(lCursor);
}
validateModel(pModel);
}
// export model
public static void exportModel(ModelUserObject pModel, boolean pInUML) throws Exception
{
JFileChooser lChooser = new JFileChooser();
ModelFileFilter lFilter = new ModelFileFilter();
lChooser.setDialogTitle("Select XML File");
lFilter.addExtension("xml");
lFilter.setDescription("XML files");
lChooser.setFileFilter(lFilter);
if (Application.properties.mLastDir!=null)
lChooser.setCurrentDirectory((new File(Application.properties.mLastDir)).getParentFile());
lChooser.setSelectedFile(new File(pModel.getModelName()+".xml"));
int returnVal = lChooser.showSaveDialog(mainFrame);
if (returnVal == JFileChooser.APPROVE_OPTION)
{
File lFile = lChooser.getSelectedFile();
Cursor lCursor = mainFrame.getCursor();
try
{
mainFrame.setCursor(new Cursor(Cursor.WAIT_CURSOR));
// If we have ben asked to export as UML, we need to convert it first
String lModelName = pModel.getFileName();
if (pInUML)
{
// Pick a name for the temporary model
String lTempUMLModelName = "TempUML_TempUML_TempUML_" + lModelName + "_TempUML_TempUML_TempUML";
try
{
ModelUtils.convertMetaBossModelToUMLModel(lModelName,lTempUMLModelName);
sModelRepository.exportModel(lTempUMLModelName, false, lFile, new Properties());
}
finally
{
// Close the temporary model.
if (sModelRepository.containsModel(lTempUMLModelName))
sModelRepository.closeModel(lTempUMLModelName);
}
}
else
sModelRepository.exportModel(pModel.getFileName(), false, lFile, new Properties());
Application.properties.mLastDir = lFile.getPath();
Object[] arguments = {pModel.getModelName(), lFile.getPath()};
showInformation(java.text.MessageFormat.format(getString("exported_message"), arguments));
}
finally
{
mainFrame.setCursor(lCursor);
}
}
}
// copy Model Element
public static void copyModelElement(BaseUserObject pObject, ModelUserObject pCurrentPackage)
{
ArrayList lList = new ArrayList();
for (int i=0; i<getModelsCount(); i++)
{
ModelUserObject lObject = getModel(i);
if (!lObject.isSystem() && !lObject.equals(pCurrentPackage))
lList.add(lObject);
}
if (lList.size()>0)
{
CopyElementDialog lDialog = new CopyElementDialog(mainFrame, lList);
if (lDialog.getModalResult()==CopyElementDialog.MR_OK)
{
for (int i=0; i<getModelsCount(); i++)
{
ModelUserObject lObject = getModel(i);
if (lList.contains(lObject))
{
try
{
copyModelElement(lObject, pObject);
}
catch (Exception e)
{
processError(e);
}
}
}
}
}
}
public static void copyModelElement(ModelUserObject pModel, BaseUserObject pObject) throws Exception
{
if (pModel == null || pObject == null || pModel.isSystem())
return;
Enterprise lEnterprise = (Enterprise)pModel.getRootElement();
if (lEnterprise == null)
return;
Cursor lCursor = mainFrame.getCursor();
try
{
mainFrame.setCursor(new Cursor(Cursor.WAIT_CURSOR));
boolean lInTransaction = isInTransaction();
if (!lInTransaction)
beginTransaction();
try
{
ModelElement lSourceModelElement = pObject.getBOObject();
if (lSourceModelElement instanceof Namespace ||
lSourceModelElement instanceof TypeTemplate ||
lSourceModelElement instanceof Structure ||
lSourceModelElement instanceof Message ||
lSourceModelElement instanceof DataType)
{
DataDictionary lSourceOwnerDataDictionary = null;
if (lSourceModelElement instanceof Namespace)
lSourceOwnerDataDictionary = ((Namespace)lSourceModelElement).getOwnerDataDictionary();
else
if (lSourceModelElement instanceof TypeTemplate)
lSourceOwnerDataDictionary = ((TypeTemplate)lSourceModelElement).getOwnerDataDictionary();
else
if (lSourceModelElement instanceof DataType)
lSourceOwnerDataDictionary = ((DataType)lSourceModelElement).getOwnerDataDictionary();
else
if (lSourceModelElement instanceof Message)
lSourceOwnerDataDictionary = ((Message)lSourceModelElement).getOwnerDataDictionary();
else
if (lSourceModelElement instanceof Structure)
lSourceOwnerDataDictionary = ((Structure)lSourceModelElement).getOwnerDataDictionary();
// Get or create target data dictionary (use shallow copy)
DataDictionary lTargetOwnerDictionary = lEnterprise.getDesignLibrary().findDataDictionary(lSourceOwnerDataDictionary.getName());
if (lTargetOwnerDictionary == null)
{
lTargetOwnerDictionary = (DataDictionary)sModelRepository.copyModelElement(lSourceOwnerDataDictionary,sModelRepository.getOwnerModelName(lEnterprise), false,null);
}
// Find or create target namespace and the whole tree above it
// This will ensure that the taget model has the Namespace where the Namespace/TypeTemplate/DataType must be created
List lSourcePathWithoutDictionary = null;
if (lSourceModelElement instanceof TypeTemplate)
lSourcePathWithoutDictionary = ((TypeTemplate)lSourceModelElement).getNamespace().getPathWithoutDictionary();
else
if (lSourceModelElement instanceof DataType)
lSourcePathWithoutDictionary = ((DataType)lSourceModelElement).getNamespace().getPathWithoutDictionary();
else
if (lSourceModelElement instanceof Namespace)
lSourcePathWithoutDictionary = ((Namespace)lSourceModelElement).getNamespace().getPathWithoutDictionary();
else
if (lSourceModelElement instanceof Message)
lSourcePathWithoutDictionary = ((Message)lSourceModelElement).getNamespace().getPathWithoutDictionary();
else
if (lSourceModelElement instanceof Structure)
lSourcePathWithoutDictionary = ((Structure)lSourceModelElement).getNamespace().getPathWithoutDictionary();
AbstractNamespace lTargetParentNamespace = lTargetOwnerDictionary;
for (Iterator lSourceNamespaceIterator = lSourcePathWithoutDictionary.iterator();lSourceNamespaceIterator.hasNext();)
{
AbstractNamespace lSourceNamespace = (AbstractNamespace)lSourceNamespaceIterator.next();
AbstractNamespace lTargetNamespace = lTargetParentNamespace.findSubNamespace(lSourceNamespace.getName());
if (lTargetNamespace == null)
{
// Namespace is not present - create shallow copy of the source.
lTargetNamespace = (Namespace)sModelRepository.copyModelElement(lSourceNamespace, pModel.getFileName(), false,null);
lTargetParentNamespace.getSubNamespaces().add(lTargetNamespace);
}
// Step down one level
lTargetParentNamespace = lTargetNamespace;
}
// We now have the target parent namespace, check if it already has the element same to what we have been asked to copy
if (lSourceModelElement instanceof TypeTemplate)
{
TypeTemplate lSourceTypeTemplate = (TypeTemplate)lSourceModelElement;
TypeTemplate lTargetTypeTemplate = lTargetParentNamespace.findTypeTemplate(lSourceTypeTemplate.getName());
if (lTargetTypeTemplate != null)
{
if (JOptionPane.showConfirmDialog(mainFrame, "TypeTemplate " + lSourceTypeTemplate.getName() + " already exists in the target model. Do you wish to overwrite it?", "Copy Model Element", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION)
sModelRepository.retrofitModelElement(lSourceTypeTemplate,lTargetTypeTemplate,ModelElementResolverImpl.getInstance());
}
else
{
lTargetTypeTemplate = (TypeTemplate)sModelRepository.copyModelElement(lSourceTypeTemplate, pModel.getFileName(), true,ModelElementResolverImpl.getInstance());
lTargetTypeTemplate.setNamespace(lTargetParentNamespace);
}
}
else
if (lSourceModelElement instanceof DataType)
{
DataType lSourceDataType = (DataType)lSourceModelElement;
DataType lTargetDataType = lTargetParentNamespace.findDataType(lSourceDataType.getName());
if (lTargetDataType != null)
{
if (JOptionPane.showConfirmDialog(mainFrame, "DataType " + lSourceDataType.getName() + " already exists in the target model. Do you wish to overwrite it?", "Copy Model Element", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION)
sModelRepository.retrofitModelElement(lSourceDataType,lTargetDataType,ModelElementResolverImpl.getInstance());
}
else
{
lTargetDataType = (DataType)sModelRepository.copyModelElement(lSourceDataType, pModel.getFileName(), true,ModelElementResolverImpl.getInstance());
lTargetDataType.setNamespace(lTargetParentNamespace);
}
}
else
if (lSourceModelElement instanceof Structure)
{
Structure lSourceStructure = (Structure)lSourceModelElement;
Structure lTargetStructure = lTargetParentNamespace.findStructure(lSourceStructure.getName());
if (lTargetStructure != null)
{
if (JOptionPane.showConfirmDialog(mainFrame, "Structure " + lSourceStructure.getName() + " already exists in the target model. Do you wish to overwrite it?", "Copy Model Element", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION)
sModelRepository.retrofitModelElement(lSourceStructure,lTargetStructure,ModelElementResolverImpl.getInstance());
}
else
{
lTargetStructure = (Structure)sModelRepository.copyModelElement(lSourceStructure, pModel.getFileName(), true,ModelElementResolverImpl.getInstance());
lTargetStructure.setNamespace(lTargetParentNamespace);
}
}
else
if (lSourceModelElement instanceof Message)
{
Message lSourceMessage = (Message)lSourceModelElement;
Message lTargetMessage = lTargetParentNamespace.findMessage(lSourceMessage.getName());
if (lTargetMessage != null)
{
if (JOptionPane.showConfirmDialog(mainFrame, "Message " + lSourceMessage.getName() + " already exists in the target model. Do you wish to overwrite it?", "Copy Model Element", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION)
sModelRepository.retrofitModelElement(lSourceMessage,lTargetMessage,ModelElementResolverImpl.getInstance());
}
else
{
lTargetMessage = (Message)sModelRepository.copyModelElement(lSourceMessage, pModel.getFileName(), true,ModelElementResolverImpl.getInstance());
lTargetMessage.setNamespace(lTargetParentNamespace);
}
}
else
if (lSourceModelElement instanceof Namespace)
{
Namespace lSourceNamespace = (Namespace)lSourceModelElement;
Namespace lTargetNamespace = lTargetParentNamespace.findSubNamespace(lSourceNamespace.getName());
if (lTargetNamespace != null)
{
if (JOptionPane.showConfirmDialog(mainFrame, "Namespace " + lSourceNamespace.getName() + " already exists in the target model. Do you wish to overwrite it?", "Copy Model Element", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION)
sModelRepository.retrofitModelElement(lSourceNamespace,lTargetNamespace,ModelElementResolverImpl.getInstance());
}
else
{
lTargetNamespace = (Namespace)sModelRepository.copyModelElement(lSourceNamespace, pModel.getFileName(), true,ModelElementResolverImpl.getInstance());
lTargetNamespace.setNamespace(lTargetParentNamespace);
}
}
}
else
if (lSourceModelElement instanceof RelationalStorageTechnology)
{
RelationalStorageTechnology lSourceRelationalStorageTechnology = (RelationalStorageTechnology)lSourceModelElement;
checkObjectAlreadyIn(pModel.getModelName(), pObject, lEnterprise.getTechnologyLibrary().getStorageTechnologies());
RelationalStorageTechnology lTargetRelationalStorageTechnology = (RelationalStorageTechnology)sModelRepository.copyModelElement(lSourceRelationalStorageTechnology, pModel.getFileName(), true,ModelElementResolverImpl.getInstance());
lEnterprise.getTechnologyLibrary().getStorageTechnologies().add(lTargetRelationalStorageTechnology);
}
else
if (lSourceModelElement instanceof DataDictionary)
{
DataDictionary lSourceDataDictionary = (DataDictionary)lSourceModelElement;
DesignLibrary lTargetDesignLibrary = lEnterprise.getDesignLibrary();
// Retrofit existing or create new data dictionary in the target model
DataDictionary lTargetDataDictionary = lTargetDesignLibrary.findDataDictionary(lSourceDataDictionary.getName());
if (lTargetDataDictionary != null)
{
if (JOptionPane.showConfirmDialog(mainFrame, "Data Dictionary " + lSourceDataDictionary.getName() + " already exists in the target model. Do you wish to overwrite it?", "Copy Model Element", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION)
sModelRepository.retrofitModelElement(lSourceDataDictionary,lTargetDataDictionary,ModelElementResolverImpl.getInstance());
}
else
{
lTargetDataDictionary = (DataDictionary)sModelRepository.copyModelElement(lSourceDataDictionary,sModelRepository.getOwnerModelName(lEnterprise), true,ModelElementResolverImpl.getInstance());
lTargetDataDictionary.setDesignLibrary(lTargetDesignLibrary);
}
}
else
if (lSourceModelElement instanceof com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System)
{
com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSourceSystem = (com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System)lSourceModelElement;
com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lTargetSystem = lEnterprise.findSystem(lSourceSystem.getName());
// Retrofit existing or create new system in the target model
if (lTargetSystem != null)
{
if (JOptionPane.showConfirmDialog(mainFrame, "System " + lSourceSystem.getName() + " already exists in the target model. Do you wish to overwrite it?", "Copy Model Element", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION)
sModelRepository.retrofitModelElement(lSourceSystem,lTargetSystem,ModelElementResolverImpl.getInstance());
}
else
{
lTargetSystem = (com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System)sModelRepository.copyModelElement(lSourceSystem,sModelRepository.getOwnerModelName(lEnterprise), true,ModelElementResolverImpl.getInstance());
lTargetSystem.setEnterprise(lEnterprise);
}
}
if (!lInTransaction)
commit();
}
finally
{
if (!lInTransaction)
checkAndRollback();
}
}
finally
{
mainFrame.setCursor(lCursor);
}
}
// get TypeTemplate for newly copied DataType
private static TypeTemplate getTypeTemplateForNewDataType(ModelUserObject pModel,
BaseUserObject pOldDataType, DataDictionary pDictionary)
{
TypeTemplate lResult = null;
if (pModel!=null && pOldDataType!=null && pDictionary!=null)
{
TypeTemplate lOldTypeTemplate = ((DataType)pOldDataType.getBOObject()).getTypetemplate();
if (lOldTypeTemplate!=null)
{
lResult = findTypeTemplate(pDictionary, lOldTypeTemplate.getName());
if (lResult==null)
{
int n = JOptionPane.showConfirmDialog(mainFrame,
java.text.MessageFormat.format(getString("notypetemplate_message"), new Object[]{pModel.getModelName()}),
getString("confirm"), JOptionPane.YES_NO_OPTION);
switch (n)
{
case 0:
try
{
copyModelElement(pModel, UserObjectFactory.createUserObject(lOldTypeTemplate));
lResult = findTypeTemplate(pDictionary, lOldTypeTemplate.getName());
}
catch (Exception e)
{
processError(e);
}
break;
}
}
}
}
return lResult;
}
private static TypeTemplate findTypeTemplate(AbstractNamespace pNameSpace, String pName)
{
TypeTemplate lResult = null;
if (pNameSpace!=null)
{
lResult = pNameSpace.findTypeTemplate(pName);
if (lResult==null)
{
Object[] lNameSpaces = pNameSpace.getSubNamespaces().toArray();
for (int i=0; i<lNameSpaces.length; i++)
{
lResult = findTypeTemplate((AbstractNamespace)lNameSpaces[i], pName);
if (lResult!=null) break;
}
}
}
return lResult;
}
private static void checkObjectAlreadyIn(String pModelName, BaseUserObject pObject, Collection pCollection) throws Exception
{
if (pObject!=null && pCollection!=null)
{
ModelElement lElement = findModelElement(pObject.getBOObject(), pCollection.toArray());
if (lElement!=null)
throw new ModelWarning(java.text.MessageFormat.format(getString("elementalreadyin_message"), new Object[]{pModelName, pObject.getElementType(), pObject.toString()}));
}
}
private static ModelElement findModelElement(ModelElement pModelElement, Object[] pElements)
{
if (pElements!=null)
{
for (int i=0; i<pElements.length; i++)
{
ModelElement lModelElement = (ModelElement)pElements[i];
if (lModelElement.getName().equals(pModelElement.getName())) return lModelElement;
}
}
return null;
}
// load license information
public static void loadLicenseInfo()
{
try
{
synchronized(sClassInitialisationSemaphore)
{
try
{
javax.naming.Context lCtx = new javax.naming.InitialContext();
sLicenseService = (LicenseService)lCtx.lookup(LicenseService.COMPONENT_URL);
}
catch(javax.naming.NamingException e)
{
throw new BSNamingAndDirectoryServiceInvocationException("Unable to initialise CopyrightUtils",e);
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
// process application event
protected void processEvent(AWTEvent e)
{
if (e instanceof OptionsChangedEvent)
{
EventListener[] listeners = listenerList.getListeners(OptionsChangedListener.class);
for (int i=0; i<listeners.length; i++)
((OptionsChangedListener)listeners[i]).optionsChanged((OptionsChangedEvent)e);
} else
if (e instanceof RefreshEvent)
{
EventListener[] listeners = listenerList.getListeners(RefreshListener.class);
for (int i=0; i<listeners.length; i++)
((RefreshListener)listeners[i]).refresh((RefreshEvent)e);
} else
if (e instanceof ObjectChangedEvent)
{
EventListener[] listeners = listenerList.getListeners(ObjectChangedListener.class);
for (int i=0; i<listeners.length; i++)
((ObjectChangedListener)listeners[i]).onObjectChanged((ObjectChangedEvent)e);
} else
if (e instanceof ShowContainerEvent)
{
EventListener[] listeners = listenerList.getListeners(ShowContainerListener.class);
for (int i=0; i<listeners.length; i++)
((ShowContainerListener)listeners[i]).showContainer((ShowContainerEvent)e);
} else
if (e instanceof OnContainerCloseEvent)
{
EventListener[] listeners = listenerList.getListeners(OnContainerCloseListener.class);
for (int i=0; i<listeners.length; i++)
((OnContainerCloseListener)listeners[i]).closeContainer((OnContainerCloseEvent)e);
} else
if (e instanceof OnContainerChangedEvent)
{
EventListener[] listeners = listenerList.getListeners(OnContainerChangedListener.class);
for (int i=0; i<listeners.length; i++)
((OnContainerChangedListener)listeners[i]).containerChanged((OnContainerChangedEvent)e);
} else
if (e instanceof OnErrorsFoundEvent)
{
EventListener[] listeners = listenerList.getListeners(OnErrorsFoundListener.class);
for (int i=0; i<listeners.length; i++)
((OnErrorsFoundListener)listeners[i]).errorsFound((OnErrorsFoundEvent)e);
} else
if (e instanceof OnModelChangedEvent)
{
EventListener[] listeners = listenerList.getListeners(OnModelChangedListener.class);
for (int i=0; i<listeners.length; i++)
((OnModelChangedListener)listeners[i]).modelChanged((OnModelChangedEvent)e);
} else
if (e instanceof CloseModelEvent)
{
EventListener[] listeners = listenerList.getListeners(CloseModelListener.class);
for (int i=0; i<listeners.length; i++)
((CloseModelListener)listeners[i]).closeModel((CloseModelEvent)e);
} else
if (e instanceof RefreshDiagramsEvent)
{
EventListener[] listeners = listenerList.getListeners(RefreshDiagramsEventListener.class);
for (int i=0; i<listeners.length; i++)
((RefreshDiagramsEventListener)listeners[i]).refreshDiagram((RefreshDiagramsEvent)e);
} else
if (e instanceof OnElementIndexChangedEvent)
{
EventListener[] listeners = listenerList.getListeners(OnElemenIndexChangedEventListener.class);
for (int i=0; i<listeners.length; i++)
((OnElemenIndexChangedEventListener)listeners[i]).indexChanged((OnElementIndexChangedEvent)e);
}
else
super.processEvent(e);
}
private void configureUI()
{
UIManager.put(Options.USE_SYSTEM_FONTS_APP_KEY, Boolean.TRUE);
Options.setGlobalFontSizeHints(FontSizeHints.MIXED);
Options.setDefaultIconSize(new Dimension(18, 18));
//String lafName =
// LookUtils.isWindowsXP()
// ? Options.getCrossPlatformLookAndFeelClassName()
// : Options.getSystemLookAndFeelClassName();
//String lafName = Options.getSystemLookAndFeelClassName();
String lafName = Options.getCrossPlatformLookAndFeelClassName();
try
{
UIManager.setLookAndFeel(lafName);
//PlasticLookAndFeel.setMyCurrentTheme(new DesertBluer());
//UIManager.setLookAndFeel(new Plastic3DLookAndFeel());
}
catch (Exception e)
{
System.err.println("Can't set look & feel:" + e);
}
}
private void startUI()
{
try
{
mainFrame = new MainFrame();
mainFrame.makeVisible();
if (!getRegistered())
new AboutDialog(mainFrame);
}
catch(Throwable t)
{
t.printStackTrace();
}
}
// check and correct Metaboss system variables
public static void checkPath()
{
// Ensure that MetaBoss.Home is given and accessible
String lMetaBossHome = System.getProperty("MetaBoss.Home");
if (lMetaBossHome == null)
{
System.out.println("MetaBoss.Home system property must be specified.");
System.exit(1);
}
File lMetaBossHomeFile = new File(lMetaBossHome).getAbsoluteFile();
if (lMetaBossHomeFile.exists() == false ||
lMetaBossHomeFile.isDirectory() == false ||
lMetaBossHomeFile.canRead() == false )
{
System.out.println("MetaBoss.Home system property does not point to accessible directory: " + lMetaBossHomeFile.getAbsolutePath());
System.exit(1);
}
// Set property to absolute, so no one will have any troubles
System.setProperty("MetaBoss.Home",lMetaBossHomeFile.getAbsolutePath());
// Ensure that MetaBoss.SystemDefinitionPath is given and accessible
/*String lMetaBossSystemDefinitionPath = System.getProperty("MetaBoss.SystemDefinitionPath");
if (lMetaBossSystemDefinitionPath == null)
{
System.out.println("MetaBoss.SystemDefinitionPath system property must be specified.");
System.exit(1);
}
File lMetaBossSystemDefinitionPathFile = new File(lMetaBossSystemDefinitionPath).getAbsoluteFile();
if (lMetaBossSystemDefinitionPathFile.exists() == false ||
lMetaBossSystemDefinitionPathFile.isDirectory() == false ||
lMetaBossSystemDefinitionPathFile.canRead() == false)
{
System.out.println("MetaBoss.SystemDefinitionPath system property does not point to accessible directory: " + lMetaBossSystemDefinitionPathFile.getAbsolutePath());
System.exit(1);
}
// Set property to absolute, so no one will have any troubles
System.setProperty("MetaBoss.SystemDefinitionPath",lMetaBossSystemDefinitionPathFile.getAbsolutePath());*/
}
/* Auxilary classes */
/* Events */
/* Application Options Changed Event */
public class OptionsChangedEvent extends AWTEvent
{
public static final int OPTIONS_EVENT = AWTEvent.RESERVED_ID_MAX + 998;
private boolean mMetabossChanged = false;
public OptionsChangedEvent()
{
super(Application.instance, OPTIONS_EVENT);
}
public OptionsChangedEvent(boolean pMetabossChanged)
{
super(Application.instance, OPTIONS_EVENT);
mMetabossChanged = pMetabossChanged;
}
public boolean getMetabossChanged()
{
return mMetabossChanged;
}
}
/* Options Changed Event Listener */
public interface OptionsChangedListener extends EventListener
{
public void optionsChanged(OptionsChangedEvent event);
}
/* Application Refresh Event */
public class RefreshEvent extends AWTEvent
{
public static final int REFRESH_EVENT = AWTEvent.RESERVED_ID_MAX + 997;
public RefreshEvent()
{
super(Application.instance, REFRESH_EVENT);
}
}
/* Refresh Event Listener */
public interface RefreshListener extends EventListener
{
public void refresh(RefreshEvent event);
}
/* Application Model Object Changed Event */
public class ObjectChangedEvent extends AWTEvent
{
public static final int OBJECTCHANGED_EVENT = AWTEvent.RESERVED_ID_MAX + 996;
public static final int ET_SELECTED = 0;
public static final int ET_EDITED = 1;
public static final int ET_INSERTED = 2;
public static final int ET_DELETED = 3;
public static final int ET_SELECT = 4;
public static final int ET_MOVED = 5;
private BaseUserObject mUserObject = null;
private String mID = null;
private String mModelName = null;
private int mSource = ET_SELECTED;
public ObjectChangedEvent(BaseUserObject pUserObject, int pSource)
{
super(Application.instance, OBJECTCHANGED_EVENT);
mUserObject = pUserObject;
if (mUserObject!=null) mID = mUserObject.getID();
mSource = pSource;
}
public ObjectChangedEvent(String pID, String pModelName, int pSource)
{
super(Application.instance, OBJECTCHANGED_EVENT);
mID = pID;
mModelName = pModelName;
mSource = pSource;
}
public BaseUserObject getUserObject()
{
return mUserObject;
}
public String getObjectID()
{
return mID;
}
public String getModelName()
{
return mModelName;
}
public int getEventSource()
{
return mSource;
}
}
/* Model Changed Event Listener */
public interface ObjectChangedListener extends EventListener
{
public void onObjectChanged(ObjectChangedEvent event);
}
/* Application Show Container Event */
public class ShowContainerEvent extends AWTEvent
{
public static final int SHOWCONTANER_EVENT = AWTEvent.RESERVED_ID_MAX + 996;
private BaseChildPanel mContainer = null;
private BaseUserObject mObject = null;
private Icon mIcon = null;
public ShowContainerEvent(BaseChildPanel pContainer, BaseUserObject pObject)
{
super(Application.instance, SHOWCONTANER_EVENT);
mContainer = pContainer;
mObject = pObject;
}
public ShowContainerEvent(BaseChildPanel pContainer, BaseUserObject pObject, Icon pIcon)
{
super(Application.instance, SHOWCONTANER_EVENT);
mContainer = pContainer;
mObject = pObject;
mIcon = pIcon;
}
public BaseChildPanel getContainer()
{
return mContainer;
}
public BaseUserObject getUserObject()
{
return mObject;
}
public Icon getIcon()
{
return (mIcon!=null) ? mIcon : mObject.getIcon();
}
}
/* Show Container Event Listener */
public interface ShowContainerListener extends EventListener
{
public void showContainer(ShowContainerEvent event);
}
/* On Container Closed Event */
public class OnContainerCloseEvent extends AWTEvent
{
public static final int ONCONTAINERCLOSE_EVENT = AWTEvent.RESERVED_ID_MAX + 995;
private BaseChildPanel mContainer = null;
public OnContainerCloseEvent(BaseChildPanel pContainer)
{
super(Application.instance, ONCONTAINERCLOSE_EVENT);
mContainer = pContainer;
}
public Container getContainer()
{
return mContainer;
}
}
/* On Container Close Event Listener */
public interface OnContainerCloseListener extends EventListener
{
public void closeContainer(OnContainerCloseEvent event);
}
/* On Container Changed Event */
public class OnContainerChangedEvent extends AWTEvent
{
public static final int ONCONTAINERCHANGED_EVENT = AWTEvent.RESERVED_ID_MAX + 994;
private Container mContainer = null;
public OnContainerChangedEvent(Container pContainer)
{
super(Application.instance, ONCONTAINERCHANGED_EVENT);
mContainer = pContainer;
}
public Container getContainer()
{
return mContainer;
}
}
/* On Container Changed Event Listener */
public interface OnContainerChangedListener extends EventListener
{
public void containerChanged(OnContainerChangedEvent event);
}
/* On Errors Found Event */
public class OnErrorsFoundEvent extends AWTEvent
{
public static final int ERRORSFOUND_EVENT = AWTEvent.RESERVED_ID_MAX + 993;
public OnErrorsFoundEvent()
{
super(Application.instance, ERRORSFOUND_EVENT);
}
}
/* Errors Found Event Listener */
public interface OnErrorsFoundListener extends EventListener
{
public void errorsFound(OnErrorsFoundEvent event);
}
/* On Current Model Changed */
public class OnModelChangedEvent extends AWTEvent
{
public static final int MODELCHANGED_EVENT = AWTEvent.RESERVED_ID_MAX + 992;
public static final int CURRENT_CHANGED = 0;
public static final int MODEL_CLOSED = 1;
public static final int MODEL_OPENED = 2;
public static final int MODEL_SAVED = 3;
private ModelUserObject mModel = null;
private int mEventSource = CURRENT_CHANGED;
public OnModelChangedEvent(ModelUserObject pMaster, int pSource)
{
super(Application.instance, MODELCHANGED_EVENT);
mModel = pMaster;
mEventSource = pSource;
}
public ModelUserObject getModel()
{
return mModel;
}
public int getEventSource()
{
return mEventSource;
}
}
/* Errors Found Event Listener */
public interface OnModelChangedListener extends EventListener
{
public void modelChanged(OnModelChangedEvent event);
}
/* Close Model Event */
public class CloseModelEvent extends AWTEvent
{
public static final int ERRORSFOUND_EVENT = AWTEvent.RESERVED_ID_MAX + 991;
private ModelUserObject mModel = null;
public CloseModelEvent(ModelUserObject pModel)
{
super(Application.instance, ERRORSFOUND_EVENT);
mModel = pModel;
}
public ModelUserObject getModel()
{
return mModel;
}
}
/* Close Model Event Listener */
public interface CloseModelListener extends EventListener
{
public void closeModel(CloseModelEvent event);
}
/* Refresh Diagram Event */
public class RefreshDiagramsEvent extends AWTEvent
{
public static final int REFRESHDIAGRAM_EVENT = AWTEvent.RESERVED_ID_MAX + 990;
protected Diagram mDiagram = null;
protected BaseUserObject mUserObject = null;
public RefreshDiagramsEvent(Diagram pDiagram, BaseUserObject pUserObject)
{
super(Application.instance, REFRESHDIAGRAM_EVENT);
mDiagram = pDiagram;
mUserObject = pUserObject;
}
// get graph panel
public Diagram getDiagram()
{
return mDiagram;
}
// get user object
public BaseUserObject getUserObject()
{
return mUserObject;
}
}
/* Refresh Diagram Event Listener */
public interface RefreshDiagramsEventListener extends EventListener
{
public void refreshDiagram(RefreshDiagramsEvent event);
}
/* Tree element index changed Event */
public class OnElementIndexChangedEvent extends AWTEvent
{
public static final int INDEXCHANGED_EVENT = AWTEvent.RESERVED_ID_MAX + 989;
protected BaseUserObject mUserObject = null;
protected int mOldIndex = -1;
protected int mNewIndex = -1;
public OnElementIndexChangedEvent(BaseUserObject pUserObject, int pOldIndex, int pNewIndex)
{
super(Application.instance, INDEXCHANGED_EVENT);
mUserObject = pUserObject;
mOldIndex = pOldIndex;
mNewIndex = pNewIndex;
}
// get user object
public BaseUserObject getUserObject()
{
return mUserObject;
}
// get old index
public int getOldIndex()
{
return mOldIndex;
}
// get old index
public int getNewIndex()
{
return mNewIndex;
}
}
/* Tree element index changed Event listener */
public interface OnElemenIndexChangedEventListener extends EventListener
{
public void indexChanged(OnElementIndexChangedEvent event);
}
}
|