001: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012: // POSSIBILITY OF SUCH DAMAGE.
013: //
014: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015: package com.metaboss.applications.designstudio.propertiesview;
016:
017: import java.awt.BorderLayout;
018: import java.util.Properties;
019:
020: import javax.swing.JPanel;
021: import javax.swing.JScrollPane;
022: import javax.swing.JTabbedPane;
023: import javax.swing.JTable;
024: import javax.swing.SwingConstants;
025:
026: import com.metaboss.applications.designstudio.Application;
027: import com.metaboss.applications.designstudio.BaseUserObject;
028: import com.metaboss.applications.designstudio.Application.OnErrorsFoundEvent;
029: import com.metaboss.applications.designstudio.Application.RefreshEvent;
030: import com.metaboss.applications.designstudio.errorsview.ErrorsViewPanel;
031: import com.metaboss.applications.designstudio.systemlog.LogViewPanel;
032:
033: /* proeprties view panel class */
034:
035: public class PropertiesViewPanel extends JPanel {
036: private JTabbedPane mTabControl = null;
037: private PropertiesTableModel mModel = new PropertiesTableModel();
038: private JTable mTable = new PropertiesTable(mModel);
039: private ErrorsViewPanel mErrors = new ErrorsViewPanel();
040: private LogViewPanel mLogViewPanel = new LogViewPanel();
041:
042: // constructor
043: public PropertiesViewPanel() {
044: super (new BorderLayout());
045: mTabControl = new JTabbedPane();
046: try {
047: add(mTabControl, null);
048: if (Application.properties.mViewPropertiesBar)
049: mTabControl.addTab(Application
050: .getString("properties_tab"), new JScrollPane(
051: mTable));
052: mTabControl.addTab(Application.getString("errors_tab"),
053: mErrors);
054: if (Application.properties.mViewSystemLog)
055: mTabControl.addTab(Application
056: .getString("systemlog_tab"), mLogViewPanel);
057:
058: /*mTabControl.addTab("Doc", new JScrollPane(new UnderConstructionViewPanel()));
059: mTabControl.addTab("Errors", new JScrollPane(new UnderConstructionViewPanel()));*/
060: mTabControl.setBorder(null);
061: mTabControl.setFont(Application.DEFAULT_FONT);
062: mTabControl.setTabPlacement(SwingConstants.BOTTOM);
063: } catch (Throwable t) {
064: t.printStackTrace();
065: }
066: Application
067: .addRefreshListener(new Application.RefreshListener() {
068: public void refresh(RefreshEvent event) {
069: clear();
070: }
071: });
072: Application
073: .addOnErrorsFoundListener(new Application.OnErrorsFoundListener() {
074: public void errorsFound(OnErrorsFoundEvent event) {
075: mTabControl.setSelectedIndex(mTabControl
076: .getTabCount() - 2);
077: }
078: });
079: }
080:
081: public PropertiesViewPanel(Properties pProperties) {
082: super (new BorderLayout());
083: mModel.loadPorperties(pProperties);
084: add(new JScrollPane(mTable));
085: }
086:
087: // edit object proeprties
088: public void editProperties(BaseUserObject pObject) throws Exception {
089: if (!Application.properties.mViewPropertiesBar)
090: return;
091:
092: int lOldIndex = mTabControl.getSelectedIndex();
093: String lOldTitle = (lOldIndex > -1) ? mTabControl
094: .getTitleAt(lOldIndex) : null;
095:
096: clear();
097: try {
098: if (pObject != null && pObject.getMode() == 0) {
099: pObject.loadObjectProperties(mModel);
100: pObject.addExtraPropertiesTabs(mTabControl);
101: }
102:
103: if (lOldTitle != null) {
104: int lIndex = mTabControl.indexOfTab(lOldTitle);
105: if (lIndex > -1)
106: lOldIndex = lIndex;
107: }
108: if (lOldIndex >= mTabControl.getTabCount())
109: lOldIndex = mTabControl.getTabCount() - 1;
110: mTabControl.setSelectedIndex(lOldIndex);
111: } finally {
112: mModel.fireTableDataChanged();
113: }
114: }
115:
116: // clear panel
117: public void clear() {
118: removeExtraTabs();
119: mModel.clear();
120: }
121:
122: // show errors tab
123: public void viewErrors() {
124: mTabControl.setSelectedIndex(mTabControl.getTabCount() - 1);
125: mErrors.loadErrors();
126: }
127:
128: // check tabs
129: public void checkTabs() {
130: int lLogIndex = mTabControl.indexOfTab(Application
131: .getString("systemlog_tab"));
132: if (Application.properties.mViewSystemLog) {
133: if (lLogIndex < 0)
134: mTabControl.addTab(Application
135: .getString("systemlog_tab"), mLogViewPanel);
136: } else {
137: if (lLogIndex > -1)
138: mTabControl.removeTabAt(lLogIndex);
139: }
140:
141: int lPropertiesIndex = mTabControl.indexOfTab(Application
142: .getString("properties_tab"));
143: if (Application.properties.mViewPropertiesBar) {
144: if (lPropertiesIndex < 0)
145: mTabControl.insertTab(Application
146: .getString("properties_tab"), null,
147: new JScrollPane(mTable), null, 0);
148: } else {
149: if (lPropertiesIndex > -1) {
150: mTabControl.removeTabAt(lPropertiesIndex);
151: removeExtraTabs();
152: }
153: }
154: }
155:
156: // remove extra tabs from tabcontrol
157: private void removeExtraTabs() {
158: int lTabCount = 1;
159: int lStartIndex = 0;
160: int lPropertiesIndex = mTabControl.indexOfTab(Application
161: .getString("properties_tab"));
162: if (lPropertiesIndex > -1) {
163: lTabCount++;
164: lStartIndex++;
165: }
166: int lLogIndex = mTabControl.indexOfTab(Application
167: .getString("systemlog_tab"));
168: if (lLogIndex > -1)
169: lTabCount++;
170:
171: while (mTabControl.getTabCount() > lTabCount)
172: mTabControl.removeTabAt(lStartIndex);
173: }
174: }
|