// 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.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import java.util.ArrayList;
import javax.swing.Action;
import javax.swing.ActionMap;
import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
import javax.swing.UIManager;
import com.metaboss.applications.designstudio.Application.ObjectChangedEvent;
import com.metaboss.applications.designstudio.Application.OnContainerChangedEvent;
import com.metaboss.applications.designstudio.Application.OnContainerCloseEvent;
import com.metaboss.applications.designstudio.Application.OnElementIndexChangedEvent;
import com.metaboss.applications.designstudio.Application.OnModelChangedEvent;
import com.metaboss.applications.designstudio.Application.OptionsChangedEvent;
import com.metaboss.applications.designstudio.Application.ShowContainerEvent;
import com.metaboss.applications.designstudio.auxilarydialogs.AboutDialog;
import com.metaboss.applications.designstudio.auxilarydialogs.OptionsDialog;
import com.metaboss.applications.designstudio.components.ContainerAction;
import com.metaboss.applications.designstudio.components.DockLayout;
import com.metaboss.applications.designstudio.components.EtchedToolBarBorder;
import com.metaboss.applications.designstudio.components.SeparatorAction;
import com.metaboss.applications.designstudio.components.SplitPane;
import com.metaboss.applications.designstudio.components.StatusBar;
import com.metaboss.applications.designstudio.components.TabPanel;
import com.metaboss.applications.designstudio.components.TabPanel.TabPanelEvent;
import com.metaboss.applications.designstudio.designtree.DesignTreePanel;
import com.metaboss.applications.designstudio.designtree.DesignTreeTabDescriptor;
import com.metaboss.applications.designstudio.icons.IconsHolder;
import com.metaboss.applications.designstudio.propertiesview.PropertiesViewPanel;
import com.metaboss.applications.designstudio.userobjects.ModelUserObject;
import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
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.StorageTechnology;
/* Design Studion main frame class */
public class MainFrame extends JFrame
{
public static final int MIN_WIDTH = 300;
public static final int MIN_HEIGHT = 200;
private boolean mNoClose = false;
// UI components
private SplitPane mSplitPane = null;
private SplitPane mRightSplitPane = null;
private StatusBar mStatusBar = new StatusBar();
private JPanel mMDI = new MDIPanel();
private TabPanel mTabPanel = null;
private JPanel mToolbarBoundry = new JPanel();
// designtreepanel
public DesignTreePanel mTreePanel = null;
private PropertiesViewPanel mPropertiesPanel = null;
// toolbars
private JToolBar mFileToolBar = new JToolBar();
private JToolBar mActionToolBar = new JToolBar();
private JToolBar mModelToolBar = new JToolBar();
private JToolBar mCurrentWindowToolBar = new JToolBar();
// main menu
private JMenuBar mMenuBar = new JMenuBar();
private JMenu mMenuFile = new JMenu(Application.getString("file_menu"));
private JMenu mMenuView = new JMenu(Application.getString("view_menu"));
private JMenu mMenuTools = new JMenu(Application.getString("tools_menu"));
private JMenu mMenuWindow = new JMenu(Application.getString("window_menu"));
private JMenu mMenuAction = new JMenu(Application.getString("action_menu"));
private JMenu mMenuModel = new JMenu(Application.getString("model_menu"));
private JMenu mMenuHelp = new JMenu(Application.getString("help_menu"));
private int mNextFrameX = 0;
private int mNextFrameY = 0;
private int mFrameDistance = 0;
// actions
private Action mExitAction = new ExitAction();
private Action mSearchAction = new SearchAction();
private Action mRefreshAction = new RefreshAction();
private Action mPrintAction = new PrintAction();
private Action mOptionsAction = new OptionsAction();
private Action mAboutAction = new AboutAction();
private Action mCloseActiveWindowAction = new CloseActiveWindowAction();
private Action mCloseAllAction = new CloseAllAction();
private Action mNextWindowAction = new NextWindowAction();
private Action mPrevWindowAction = new PrevWindowAction();
private Action mShowStatusBarAction = new ShowStatusBarAction();
private Action mShowPropertiesBarAction = new ShowPropertiesBarAction();
private Action mShowSystemLogAction = new ShowSystemLogAction();
private Action mValidateModelAction = new ValidateModelAction();
private Action mRectifyModelAction = new RectifyModelAction();
private Action mValidateModelsAction = new ValidateModelsAction();
private Action mNewEnterpriseModelAction = new NewEnterpriseModelAction();
private Action mOpenModelAction = new OpenModelAction();
private Action mSaveModelAction = new SaveModelAction();
private Action mSaveAllModelsAction = new SaveAllModelsAction();
private Action mCloseModelAction = new CloseModelAction();
private Action mCloseAllModelsAction = new CloseAllModelsAction();
private Action mExportModelAsMetaBossXMIAction = new ExportModelAsMetaBossXMIAction();
private Action mExportModelAsUMLXMIAction = new ExportModelAsUMLXMIAction();
private Action mEditModelPropertiesAction = new EditModelPropertiesAction();
private ContainerAction mReopenAction = new ContainerAction(Application.getString("reopen_item"));
public MainFrame()
{
super(Application.getString("title"));
getContentPane().setFont(Application.DEFAULT_FONT);
//????
mSearchAction.setEnabled(false);
mPrintAction.setEnabled(false);
//????
try
{
addComponentListener(new ComponentAdapter()
{
public void componentResized(ComponentEvent e)
{
Component c = e.getComponent();
if (c.getWidth()<MIN_WIDTH) c.setSize(MIN_WIDTH, c.getHeight());
if (c.getHeight()<MIN_HEIGHT) c.setSize(c.getWidth(), MIN_HEIGHT);
}
});
createTabPanel();
createDesignTreePanel();
createPropertiesPanel();
createSplitPane();
createToolBar();
createMainMenu();
createStatusBar();
mToolbarBoundry.add(mSplitPane, BorderLayout.CENTER);
getContentPane().add(mToolbarBoundry);
getContentPane().add(mStatusBar, BorderLayout.SOUTH);
setIconImage(IconsHolder.loadImage("MetaBoss.gif"));
Application.fillActions(getFileActions(), mFileToolBar, mMenuFile, null);
Application.fillActions(getModelActions(), mModelToolBar, mMenuModel, null);
Application.fillActions(getViewActions(null), null, mMenuView, null);
Application.fillActions(getActionActions(null), mActionToolBar, mMenuAction, null);
Application.fillActions(getToolsActions(), null, mMenuTools, null);
Application.fillActions(getWindowActions(), null, mMenuWindow, null);
Application.fillActions(getHelpActions(), null, mMenuHelp, null);
pack();
createEventListeners();
checkActions();
// setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
InputMap lMap = mSplitPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
lMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.CTRL_MASK), "next");
lMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK), "prev");
ActionMap lActionMap = mSplitPane.getActionMap();
lActionMap.put("next", mNextWindowAction);
lActionMap.put("prev", mPrevWindowAction);
}
catch(Throwable t)
{
t.printStackTrace();
}
}
// show frame
public void makeVisible()
{
setBounds(Application.properties.mMainFrameBounds);
setVisible(true);
setSplittersInitialState();
Application.splash.setVisible(false);
}
public void beforeClose()
{
//???closeAllWindows(false);
Application.properties.mMainFrameBounds = getBounds();
Application.properties.mDeviderLocation = mSplitPane.getDividerLocation();
if (mPropertiesPanel.isVisible())
Application.properties.mRightDeviderLocation = mRightSplitPane.getDividerLocation();
Application.properties.mViewStatusBar = mStatusBar.isVisible();
//Application.properties.mViewPropertiesBar = mPropertiesPanel.isVisible();
}
// get current package
public ModelUserObject getCurrentPackage()
{
return mTreePanel.getCurrentPackage();
}
// update child compoents on options change event
protected void updateComponents()
{
//mTabPanel.setCloseRegime(Application.properties.mCloseButtonRegime);
}
/**Overridden so we can exit when window is closed*/
protected void processWindowEvent(WindowEvent e)
{
super.processWindowEvent(e);
switch (e.getID())
{
case WindowEvent.WINDOW_CLOSING:
if (!mNoClose) Application.exit();
break;
}
}
public class NoCloseException extends Exception {}
public void setVisible(boolean b)
{
if (!b)
{
if (closeAllWindows(false) && saveApplicationData())
{
super.setVisible(b);
}
}
else
super.setVisible(b);
}
// save Models
private boolean saveApplicationData()
{
mNoClose = false;
boolean lResult = true;
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try
{
try
{
Application.saveModels(true, true);
}
catch (Exception e)
{
lResult = false;
mNoClose = true;
}
}
finally
{
setCursor(Cursor.getDefaultCursor());
}
return lResult;
}
// create Application Events listeners
private void createEventListeners()
{
Application.addOptionsEventListener(new Application.OptionsChangedListener()
{
public void optionsChanged(OptionsChangedEvent event)
{
updateComponents();
if (event.getMetabossChanged())
{
beforeClose();
Application.fireRefresh();
}
}
});
Application.addContainerShowListener(new Application.ShowContainerListener()
{
public void showContainer(ShowContainerEvent event)
{
int lIndex = mTabPanel.findTabIndexByName(event.getUserObject().getID());
if (lIndex==-1)
{
BaseUserObject lObject = event.getUserObject();
if (lObject!=null)
mTabPanel.addTab(lObject.getContainerCaption(), lObject.getID(), event.getContainer(), event.getIcon());
}
else
mTabPanel.setTabIndex(lIndex);
checkActions();
}
});
Application.addOnContainerCloseListener(new Application.OnContainerCloseListener()
{
public void closeContainer(OnContainerCloseEvent event)
{
Application.fillActions(getViewActions(null), mCurrentWindowToolBar, mMenuView, null);
mToolbarBoundry.repaint();
checkActions();
}
});
Application.addOnContainerChangedListener(new Application.OnContainerChangedListener()
{
public void containerChanged(OnContainerChangedEvent event)
{
checkActions();
}
});
Application.addObjectChanged(new Application.ObjectChangedListener()
{
public void onObjectChanged(ObjectChangedEvent event)
{
BaseUserObject lObject = null;
switch (event.getEventSource())
{
case ObjectChangedEvent.ET_SELECTED:
processObjectChanged(event.getUserObject());
break;
case ObjectChangedEvent.ET_SELECT:
mTreePanel.objectSelected(event.getUserObject());
break;
case ObjectChangedEvent.ET_EDITED:
processObjectChanged(event.getUserObject());
mTreePanel.objectChanged(event.getUserObject());
checkActions();
break;
case ObjectChangedEvent.ET_INSERTED:
mTreePanel.addNewObject(event.getUserObject());
checkActions();
break;
case ObjectChangedEvent.ET_DELETED:
closeObjectContainers(event.getObjectID());
Application.fillActions(getActionActions(null), mActionToolBar, mMenuAction, null);
lObject = event.getUserObject();
if (lObject==null)
mTreePanel.removeNode(event.getObjectID());
else
mTreePanel.removeNode(lObject);
checkActions();
break;
case ObjectChangedEvent.ET_MOVED:
lObject = event.getUserObject();
if (lObject!=null)
{
mTreePanel.objectMoved(lObject);
checkActions();
}
break;
}
}
});
Application.addOnModelChangedListener(new Application.OnModelChangedListener()
{
public void modelChanged(OnModelChangedEvent event)
{
Application.fillActions(getFileActions(), mFileToolBar, mMenuFile, null);
checkActions();
processObjectChanged(mTreePanel.getCurrentUserObject());
}
});
Application.addCloseModelListener(new Application.CloseModelListener()
{
public void closeModel(Application.CloseModelEvent event)
{
try
{
Application.sModelRepository.closeModel(event.getModel().getFileName());
}
catch (Exception e)
{
Application.processError(e);
}
}
});
Application.addElementIndexChangedEvent(new Application.OnElemenIndexChangedEventListener()
{
public void indexChanged(OnElementIndexChangedEvent event)
{
mTreePanel.processObjectIndexChanged(event.getUserObject(), event.getNewIndex(), event.getOldIndex());
}
});
}
private void closeObjectContainers(String pID)
{
int i = 0;
while (i<mTabPanel.getTabCount())
{
BaseChildPanel lPanel = (BaseChildPanel)mTabPanel.getPanel(i);
if (lPanel!=null)
{
ModelElement lElement = lPanel.getBOObject();
if (lElement!=null && lElement.refMofId().equals(pID))
{
lPanel.setChanged(false);
mTabPanel.deleteTab(i);
continue;
}
if (lPanel instanceof BaseGraphPanel)
{
BaseGraphModel lModel = (BaseGraphModel)((BaseGraphPanel)lPanel).getModel();
if (lModel!=null && lModel.mDiagram!=null &&
lModel.mDiagram.refMofId().equals(pID))
{
lPanel.setChanged(false);
mTabPanel.deleteTab(i);
continue;
}
}
}
i++;
}
}
// process current model object changed event
private void processObjectChanged(BaseUserObject pObject)
{
Application.fillActions(getActionActions(pObject), mActionToolBar, mMenuAction, null);
showRightPropertiesPanel(pObject);
if (pObject!=null)
{
mStatusBar.setPanelText(1, pObject.getToolTip());
int lIndex = mTabPanel.findTabIndexByName(pObject.getID());
if (lIndex>-1)
mTabPanel.setTabCaption(pObject.getContainerCaption(), lIndex);
}
else
mStatusBar.setPanelText(1, "");
}
// create split pane
private void createSplitPane()
{
mMDI.setLayout(new BorderLayout());
mMDI.add(mTabPanel, BorderLayout.NORTH);
//mMDI.setBackground(SystemColor.desktop);
mMDI.setBackground(UIManager.getColor("desktop"));
mRightSplitPane = new SplitPane(JSplitPane.VERTICAL_SPLIT, mMDI, mPropertiesPanel);
mSplitPane = new SplitPane(JSplitPane.HORIZONTAL_SPLIT, mTreePanel, mRightSplitPane);
//getContentPane().add(mSplitPane);
}
// create properties panel
private void createPropertiesPanel()
{
mPropertiesPanel = new PropertiesViewPanel();
//mPropertiesPanel.setVisible(Application.properties.mViewPropertiesBar);
//??
}
//create toolbar
private void createToolBar()
{
mFileToolBar.setBorder(new EtchedToolBarBorder());
mFileToolBar.setRollover(true);
mActionToolBar.setBorder(new EtchedToolBarBorder());
mActionToolBar.setRollover(true);
mModelToolBar.setBorder(new EtchedToolBarBorder());
mModelToolBar.setRollover(true);
mCurrentWindowToolBar.setBorder(new EtchedToolBarBorder());
mCurrentWindowToolBar.setRollover(true);
// toolbar boundary
mToolbarBoundry.setLayout(new DockLayout());
mToolbarBoundry.add(mFileToolBar, BorderLayout.NORTH);
mToolbarBoundry.add(mModelToolBar, BorderLayout.NORTH);
mToolbarBoundry.add(mActionToolBar, BorderLayout.NORTH);
mToolbarBoundry.add(mCurrentWindowToolBar, BorderLayout.NORTH);
}
// create main menu
private void createMainMenu()
{
mMenuBar.add(mMenuFile);
mMenuBar.add(mMenuAction);
mMenuBar.add(mMenuView);
mMenuBar.add(mMenuModel);
mMenuBar.add(mMenuTools);
mMenuBar.add(mMenuWindow);
mMenuBar.add(mMenuHelp);
setJMenuBar(mMenuBar);
}
// create StatusBar
private void createStatusBar()
{
mStatusBar.setFont(Application.DEFAULT_FONT);
mStatusBar.addPanel(Application.getVersion(), 60, javax.swing.text.StyleConstants.ALIGN_CENTER);
mStatusBar.addPanel("", 200);
mStatusBar.setVisible(Application.properties.mViewStatusBar);
}
// create tabpanel
private void createTabPanel()
{
mTabPanel = new TabPanel(mMDI)
{
public void deleteTab(int pIndex)
{
checkContainerSaved((BaseChildPanel)getPanel(pIndex));
super.deleteTab(pIndex);
}
};
mTabPanel.setFont(Application.DEFAULT_FONT);
mTabPanel.setCloseRegime(TabPanel.CB_ONEFORALL);
mTabPanel.addTabPanelEventListener(new TabPanel.TabPanelListener()
{
public void tabChanged(TabPanelEvent event)
{
mCurrentWindowToolBar.removeAll();
Container lPanel = mTabPanel.getCurrentPanel();
if (lPanel instanceof BaseChildPanel)
{
BaseChildPanel lBaseChildPanel = (BaseChildPanel)lPanel;
Application.fillActions(getViewActions(lBaseChildPanel), mCurrentWindowToolBar, mMenuView, null);
lBaseChildPanel.containerActivate();
}
checkActions();
}
});
}
// create design tree panel
private void createDesignTreePanel()
{
try
{
mTreePanel = new DesignTreePanel();
}
catch(Throwable t)
{
t.printStackTrace();
}
}
// show right properties panel
private void showRightPropertiesPanel(BaseUserObject pUserObject)
{
if (pUserObject!=null)
{
try
{
mPropertiesPanel.editProperties(pUserObject);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
// set splitters initial state
private void setSplittersInitialState()
{
if (Application.properties.mDeviderLocation==0)
mSplitPane.setDividerLocation(0.3);
else
mSplitPane.setDividerLocation(Application.properties.mDeviderLocation);
setRightSplitter();
}
private void setRightSplitter()
{
if (mPropertiesPanel.isVisible())
{
if (Application.properties.mRightDeviderLocation==0)
mRightSplitPane.setDividerLocation(0.8);
else
mRightSplitPane.setDividerLocation(Application.properties.mRightDeviderLocation);
mRightSplitPane.setDividerSize(4);
}
else
mRightSplitPane.setDividerSize(0);
}
// Brings the next non-iconified internal frame to the front.
private void selectNextWindow()
{
int lIndex = mTabPanel.getTabIndex();
lIndex++;
if (lIndex>=mTabPanel.getTabCount()) lIndex = 0;
mTabPanel.setTabIndex(lIndex);
}
// Brings the prev non-iconified internal frame to the front.
private void selectPrevWindow()
{
int lIndex = mTabPanel.getTabIndex();
lIndex--;
if (lIndex<0) lIndex = mTabPanel.getTabCount()-1;
mTabPanel.setTabIndex(lIndex);
}
// close all windows
private boolean closeAllWindows(boolean pRepaint)
{
boolean lResult = true;
try
{
checkAllContainers();
mTabPanel.clearAll();
if (pRepaint) mMDI.repaint();
}
catch (NoCloseException e)
{
lResult = false;
}
catch (Exception e)
{
e.printStackTrace();
}
return lResult;
}
// close active window
private void closeActiveWindow()
{
mTabPanel.closeActiveWindow();
}
// show options dialog
private void showOptionsDialog() throws Exception
{
new OptionsDialog(this);
}
// show About dialog
private void showAboutDialog() throws Exception
{
new AboutDialog(this);
}
// create file menu actions list
private Object[] getFileActions()
{
ArrayList lList = new ArrayList();
lList.add(mNewEnterpriseModelAction);
lList.add(mOpenModelAction);
lList.add(mReopenAction);
mReopenAction.clearChildActions();
for (int i=0; i<Application.properties.mReopenModels.size(); i++)
mReopenAction.addChildAction(new ReopenModelAction((String)Application.properties.mReopenModels.get(i)));
lList.add(new SeparatorAction());
lList.add(mExportModelAsMetaBossXMIAction);
lList.add(mExportModelAsUMLXMIAction);
lList.add(mSaveModelAction);
lList.add(mSaveAllModelsAction);
lList.add(mCloseModelAction);
lList.add(mCloseAllModelsAction);
lList.add(new SeparatorAction());
lList.add(mPrintAction);
lList.add(mSearchAction);
lList.add(mRefreshAction);
lList.add(new SeparatorAction());
lList.add(mExitAction);
return lList.toArray();
}
// get Action menu Actions
public Object[] getActionActions(BaseUserObject pObject)
{
ArrayList lList = getActionActionsAsList(pObject);
return (lList!=null) ? lList.toArray() : null;
}
// get Action menu Actions
public ArrayList getActionActionsAsList(BaseUserObject pObject)
{
ArrayList lList = new ArrayList();
if (pObject!=null)
{
DesignTreeTabDescriptor lDescriptor = mTreePanel.getCurentTabDescriptor();
if (lDescriptor!=null)
{
if (lDescriptor.isSystem())
{
ModelElement lModelElement = pObject.getBOObject();
if (lModelElement instanceof Namespace ||
lModelElement instanceof DataType ||
lModelElement instanceof TypeTemplate ||
lModelElement instanceof Message ||
lModelElement instanceof Structure ||
lModelElement instanceof StorageTechnology)
{
lList.add(new CopyModelElementAction(pObject));
lList.add(new SeparatorAction());
}
}
else
if (lDescriptor.getRootUserObject().getBOObject() instanceof DesignLibrary)
{
ModelElement lModelElement = pObject.getBOObject();
if (lModelElement instanceof DataDictionary && lModelElement.getName().equals("core") == false)
{
lList.add(new CopyModelElementAction(pObject));
lList.add(new SeparatorAction());
}
}
else
if (lDescriptor.getRootUserObject().getBOObject() instanceof Enterprise)
{
ModelElement lModelElement = pObject.getBOObject();
if (lModelElement instanceof com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System)
{
lList.add(new CopyModelElementAction(pObject));
lList.add(new SeparatorAction());
}
}
}
Object[] lActions = pObject.getActions();
if (lActions!=null)
for (int i=0; i<lActions.length; i++)
lList.add(lActions[i]);
}
return lList;
}
// get Model menu actions list
private Object[] getModelActions()
{
ArrayList lList = new ArrayList();
lList.add(mValidateModelAction);
lList.add(mValidateModelsAction);
lList.add(mRectifyModelAction);
lList.add(new SeparatorAction());
lList.add(mEditModelPropertiesAction);
return lList.toArray();
}
// create View menu actions
private Object[] getViewActions(BaseChildPanel pPanel)
{
ArrayList lList = new ArrayList();
if (pPanel!=null)
{
Object[] lActions = pPanel.getActions();
if (lActions!=null)
for (int i=0; i<lActions.length; i++)
lList.add(lActions[i]);
}
lList.add(new SeparatorAction());
lList.add(mShowStatusBarAction);
lList.add(mShowPropertiesBarAction);
lList.add(mShowSystemLogAction);
return lList.toArray();
}
// create Window menu actions list
private Object[] getWindowActions()
{
ArrayList lList = new ArrayList();
lList.add(mNextWindowAction);
lList.add(mPrevWindowAction);
lList.add(new SeparatorAction());
lList.add(mCloseActiveWindowAction);
lList.add(mCloseAllAction);
return lList.toArray();
}
// create Tools menu actions list
private Object[] getToolsActions()
{
ArrayList lList = new ArrayList();
lList.add(mOptionsAction);
return lList.toArray();
}
// create Window menu actions list
private Object[] getHelpActions()
{
ArrayList lList = new ArrayList();
lList.add(mAboutAction);
return lList.toArray();
}
// check Actions
private void checkActions()
{
boolean lTabsThere = mTabPanel.getTabCount()>0;
boolean lMoreThenOne = mTabPanel.getTabCount()>1;
boolean lSelected = mTabPanel.getTabIndex()>-1;
mCloseActiveWindowAction.setEnabled(lTabsThere && lSelected);
mCloseAllAction.setEnabled(lTabsThere);
mNextWindowAction.setEnabled(lTabsThere && lSelected && lMoreThenOne);
mPrevWindowAction.setEnabled(lTabsThere && lSelected && lMoreThenOne);
DesignTreeTabDescriptor lDescriptor = mTreePanel.getCurentTabDescriptor();
ModelUserObject lPackage = getCurrentPackage();
boolean lEnabled = lPackage!=null && lDescriptor!=null;
mNewEnterpriseModelAction.setEnabled(true);
mOpenModelAction.setEnabled(true);
mReopenAction.setEnabled(Application.properties.mReopenModels.size()>0);
mSaveModelAction.setEnabled(lEnabled && (lDescriptor.isModified() || findUnsavedContainer(lPackage)));
mSaveAllModelsAction.setEnabled(Application.getModifiedModelsCount()>0);
mCloseModelAction.setEnabled(lEnabled && !lDescriptor.isSystem());
mEditModelPropertiesAction.setEnabled(lEnabled && !lDescriptor.isSystem());
mExportModelAsMetaBossXMIAction.setEnabled(lEnabled);
mExportModelAsUMLXMIAction.setEnabled(lEnabled);
mCloseAllModelsAction.setEnabled(Application.getModelsCount()>1);
mValidateModelAction.setEnabled(lEnabled);
mRectifyModelAction.setEnabled(lEnabled);
}
// check container saved
private void checkContainerSaved(BaseChildPanel pPanel)
{
if (pPanel==null) return;
if (pPanel.getChanged()) pPanel.saveContent();
}
// check and save all containers content
private void checkAllContainers() throws Exception
{
for (int i=0; i<mTabPanel.getTabCount(); i++)
{
BaseChildPanel lPanel = (BaseChildPanel)mTabPanel.getPanel(i);
if (lPanel!=null && lPanel.getChanged()) lPanel.saveContent();
}
}
// find unsaved container
private boolean findUnsavedContainer(ModelUserObject pPackage)
{
if (pPackage!=null)
{
for (int i=0; i<mTabPanel.getTabCount(); i++)
{
BaseChildPanel lPanel = (BaseChildPanel)mTabPanel.getPanel(i);
if (lPanel!=null && lPanel.getChanged() && lPanel.getPackage()!=null &&
lPanel.getPackage().equals(pPackage.getPackage()))
return true;
}
}
return false;
}
//create new model
private void createNewModel()
{
Application.createModel();
}
// open model
private void openModel()
{
Application.openModel();
}
// reopen model
private void reOpenModel(String pFileName)
{
try
{
Application.openModel(pFileName);
}
catch (Exception e)
{
Application.processError(e);
}
}
// close current model
private void closeCurrentModel()
{
try
{
checkAllContainers();
Application.closeModel(Application.getCurrentPackage(), false, true);
}
catch (Exception e)
{
Application.processError(e);
}
}
// close all models
private void closeAllModels()
{
try
{
checkAllContainers();
Application.closeAllModels();
}
catch (Exception e)
{
Application.processError(e);
}
}
// save current model
private void saveModel()
{
try
{
checkAllContainers();
DesignTreeTabDescriptor lDescriptor = mTreePanel.getCurentTabDescriptor();
if (lDescriptor!=null)
{
Object[] lPackages = lDescriptor.getPackages();
for (int i=0; i<lPackages.length; i++)
Application.saveOneModel((ModelUserObject)lPackages[i]);
}
}
catch (Exception e)
{
Application.processError(e);
}
checkActions();
}
// save all models
private void saveAllModels()
{
try
{
checkAllContainers();
Application.saveModels(false, false);
}
catch (Exception e)
{
Application.processError(e);
}
checkActions();
}
// Validate current model
private void validateCurrentModel()
{
DesignTreeTabDescriptor lDescriptor = mTreePanel.getCurentTabDescriptor();
if (lDescriptor!=null)
{
Object[] lPackages = lDescriptor.getPackages();
for (int i=0; i<lPackages.length; i++)
Application.validateModel((ModelUserObject)lPackages[i]);
}
}
// Rectify curent model
private void rectifyCurrentModel()
{
DesignTreeTabDescriptor lDescriptor = mTreePanel.getCurentTabDescriptor();
if (lDescriptor!=null)
{
Object[] lPackages = lDescriptor.getPackages();
for (int i=0; i<lPackages.length; i++)
Application.rectifyModel((ModelUserObject)lPackages[i]);
}
}
// Export
private void exportCurrentModelAsMetaBossXMI()
{
try
{
DesignTreeTabDescriptor lDescriptor = mTreePanel.getCurentTabDescriptor();
if (lDescriptor!=null)
{
Object[] lPackages = lDescriptor.getPackages();
for (int i=0; i<lPackages.length; i++)
Application.exportModel((ModelUserObject)lPackages[i], false);
}
}
catch (Exception e)
{
Application.processError(e);
}
}
// Export
private void exportCurrentModelAsUMLXMI()
{
try
{
DesignTreeTabDescriptor lDescriptor = mTreePanel.getCurentTabDescriptor();
if (lDescriptor!=null)
{
Object[] lPackages = lDescriptor.getPackages();
for (int i=0; i<lPackages.length; i++)
Application.exportModel((ModelUserObject)lPackages[i], true);
}
}
catch (Exception e)
{
Application.processError(e);
}
}
// edit current model properties
private void editCurrentModelProperties()
{
DesignTreeTabDescriptor lDescriptor = mTreePanel.getCurentTabDescriptor();
if (lDescriptor!=null) lDescriptor.editProperties();
}
// copy current model element
private void copyModelElement(BaseUserObject pObject)
{
Application.copyModelElement(pObject, getCurrentPackage());
}
// fire refresh event
private void fireRefresh()
{
try
{
checkAllContainers();
}
catch (Exception e)
{
e.printStackTrace();
}
Application.fireRefresh();
}
/* Auxilary classes */
/* MDI Panel class */
public class MDIPanel extends JPanel
{
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
Dimension lSize = getSize();
int lx = lSize.width - Application.METABOSS_LOGO.getIconWidth() - 10;
int ly = lSize.height - Application.METABOSS_LOGO.getIconHeight() - 10;
Application.METABOSS_LOGO.paintIcon(this, g, lx, ly);
}
}
/* Actions */
/* New Enterprise Model Action */
public class NewEnterpriseModelAction extends BaseAction
{
public NewEnterpriseModelAction()
{
super("New Enterprise Model", Application.NEWMODEL_ICON);
}
public void actionPerformed(ActionEvent arg0)
{
createNewModel();
}
}
/* Open Model Action */
public class OpenModelAction extends BaseAction
{
public OpenModelAction()
{
super("Open Model", Application.OPEN_ICON);
}
public void actionPerformed(ActionEvent arg0)
{
openModel();
}
}
/* Save Model Action */
public class SaveModelAction extends BaseAction
{
public SaveModelAction()
{
super("Save Model", Application.SAVE_ICON);
}
public void actionPerformed(ActionEvent arg0)
{
saveModel();
}
}
/* Save All Models Action */
public class SaveAllModelsAction extends BaseAction
{
public SaveAllModelsAction()
{
super("Save All Models", null);
}
public void actionPerformed(ActionEvent arg0)
{
saveAllModels();
}
}
/* Close Model Action */
public class CloseModelAction extends BaseAction
{
public CloseModelAction()
{
super("Close Model", null);
}
public void actionPerformed(ActionEvent arg0)
{
closeCurrentModel();
}
}
/* Close All Models */
public class CloseAllModelsAction extends BaseAction
{
public CloseAllModelsAction()
{
super("Close All Models", null);
}
public void actionPerformed(ActionEvent arg0)
{
closeAllModels();
}
}
/* Validate Models Action */
public class ValidateModelsAction extends BaseAction
{
public ValidateModelsAction()
{
super("Validate All Models", null);
}
public void actionPerformed(ActionEvent e)
{
Application.validateModels(false, false);
}
}
/* Validate Model Action */
public class ValidateModelAction extends BaseAction
{
public ValidateModelAction()
{
super("Validate Model", Application.VALIDATE_ICON);
}
public void actionPerformed(ActionEvent e)
{
validateCurrentModel();
}
}
/* Rectify Model Action */
public class RectifyModelAction extends BaseAction
{
public RectifyModelAction()
{
super("Rectify Model", "Attempt To Rectify Model", Application.RECTIFY_ICON);
}
public void actionPerformed(ActionEvent e)
{
rectifyCurrentModel();
}
}
/* Export Model As MetaBoss XMI Action */
public class ExportModelAsMetaBossXMIAction extends BaseAction
{
public ExportModelAsMetaBossXMIAction()
{
super("Export Model As MetaBoss XMI", Application.EXPORTMBXMI_ICON);
}
public void actionPerformed(ActionEvent e)
{
exportCurrentModelAsMetaBossXMI();
}
}
/* Export Model As UML XMI Action */
public class ExportModelAsUMLXMIAction extends BaseAction
{
public ExportModelAsUMLXMIAction()
{
super("Export Model As UML XMI", Application.EXPORTXMI_ICON);
}
public void actionPerformed(ActionEvent e)
{
exportCurrentModelAsUMLXMI();
}
}
/* Edit Model Properties Action */
public class EditModelPropertiesAction extends BaseAction
{
public EditModelPropertiesAction()
{
super(Application.getString("editproperties_action"), Application.EDIT_ICON);
mAddToToolBar = false;
}
public void actionPerformed(ActionEvent e)
{
editCurrentModelProperties();
}
}
/* Reopen Model Action */
public class ReopenModelAction extends BaseAction
{
private String mFileName = null;
public ReopenModelAction(String pFileName)
{
super(pFileName, null);
mFileName = pFileName;
}
public void actionPerformed(ActionEvent e)
{
int n = JOptionPane.showConfirmDialog(null,
"Open model \"" + mFileName + "\" ?",
"Confirm", JOptionPane.YES_NO_OPTION);
if (n==0)
reOpenModel(mFileName);
}
}
/* Copy Model Element Action */
public class CopyModelElementAction extends BaseAction
{
private BaseUserObject mObject = null;
public CopyModelElementAction(BaseUserObject pObject)
{
super("Copy Model Element", Application.COPYELEMENT_ICON);
mObject = pObject;
}
public void actionPerformed(ActionEvent e)
{
copyModelElement(mObject);
}
}
/* Exit Action */
public class ExitAction extends BaseAction
{
public ExitAction()
{
super("Exit", null);
}
public void actionPerformed(ActionEvent e)
{
setVisible(false);
if (!isVisible())
Application.exit();
}
}
/* Search model element Action */
public class SearchAction extends BaseAction
{
public SearchAction()
{
super("Search", Application.SEARCH_ICON);
}
public void actionPerformed(ActionEvent e)
{
//setSplittersInitialState(); //???
mToolbarBoundry.repaint();
}
}
/* Refresh Model Tree Action */
public class RefreshAction extends BaseAction
{
public RefreshAction()
{
super("Refresh", Application.REFRESH_ICON);
}
public void actionPerformed(ActionEvent e)
{
fireRefresh();
}
}
/* Print Action */
public class PrintAction extends BaseAction
{
public PrintAction()
{
super("Print", Application.PRINT_ICON);
}
public void actionPerformed(ActionEvent arg0)
{
//???
}
}
/* Development Studio Options Action */
public class OptionsAction extends BaseAction
{
public OptionsAction()
{
super("Options", Application.OPTIONS_ICON);
}
public void actionPerformed(ActionEvent e)
{
try
{
showOptionsDialog();
}
catch(Throwable t)
{
t.printStackTrace();
}
}
}
/* Close Active Window Action */
public class CloseActiveWindowAction extends BaseAction
{
public CloseActiveWindowAction()
{
super("Close Window", null);
}
public void actionPerformed(ActionEvent e)
{
closeActiveWindow();
}
}
/* Next Window Action */
public class NextWindowAction extends BaseAction
{
public NextWindowAction()
{
super("Next Window", null);
}
public void actionPerformed(ActionEvent e)
{
selectNextWindow();
}
}
/* Prev Window Action */
public class PrevWindowAction extends BaseAction
{
public PrevWindowAction()
{
super("Previous Window", null);
}
public void actionPerformed(ActionEvent e)
{
selectPrevWindow();
}
}
/* Close All Action */
public class CloseAllAction extends BaseAction
{
public CloseAllAction()
{
super("lose All", null);
}
public void actionPerformed(ActionEvent e)
{
try
{
closeAllWindows(true);
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}
/* About Action */
public class AboutAction extends BaseAction
{
public AboutAction()
{
super("About", null);
}
public void actionPerformed(ActionEvent e)
{
try
{
showAboutDialog();
}
catch(Throwable t)
{
t.printStackTrace();
}
}
}
/* Show status bar Action */
public class ShowStatusBarAction extends BaseAction
{
public ShowStatusBarAction()
{
super("Status Bar", null);
mIsCheck = true;
mIsChecked = Application.properties.mViewStatusBar;
}
public void actionPerformed(ActionEvent arg0)
{
super.actionPerformed(arg0);
mStatusBar.setVisible(isChecked());
}
}
/* Show Properties Panel Action */
public class ShowPropertiesBarAction extends BaseAction
{
public ShowPropertiesBarAction()
{
super("Properties Bar", null);
mIsCheck = true;
mIsChecked = Application.properties.mViewPropertiesBar;
}
public void actionPerformed(ActionEvent arg0)
{
super.actionPerformed(arg0);
Application.properties.mViewPropertiesBar = isChecked();
mPropertiesPanel.checkTabs();
//mPropertiesPanel.setVisible(isChecked());
//setRightSplitter();
}
}
/* Show System Log Action */
public class ShowSystemLogAction extends BaseAction
{
public ShowSystemLogAction()
{
super("System Log", null);
mIsCheck = true;
mIsChecked = Application.properties.mViewSystemLog;
}
public void actionPerformed(ActionEvent arg0)
{
super.actionPerformed(arg0);
Application.properties.mViewSystemLog = isChecked();
mPropertiesPanel.checkTabs();
}
}
}
|