[ 1749554 ] Adding duplicated item to TreeBar only throws Exception
https://sourceforge.net/tracker/?func=detail&atid=879332&aid=1749554&group_id=176962 [ 1748518 ] enhanced VTreePanel.java: group favorites https://sourceforge.net/tracker/?func=detail&atid=883808&aid=1748518&group_id=176962
This commit is contained in:
parent
0330d31ac6
commit
29a6345c2f
|
@ -24,6 +24,7 @@ import java.awt.event.*;
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.List;
|
||||||
import java.util.logging.*;
|
import java.util.logging.*;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.plaf.SplitPaneUI;
|
import javax.swing.plaf.SplitPaneUI;
|
||||||
|
@ -66,6 +67,7 @@ public final class VTreePanel extends CPanel
|
||||||
public VTreePanel(int WindowNo, boolean hasBar, boolean editable)
|
public VTreePanel(int WindowNo, boolean hasBar, boolean editable)
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
|
toolbar = new ArrayList<JToolBar>();
|
||||||
log.config("Bar=" + hasBar + ", Editable=" + editable);
|
log.config("Bar=" + hasBar + ", Editable=" + editable);
|
||||||
m_WindowNo = WindowNo;
|
m_WindowNo = WindowNo;
|
||||||
m_hasBar = hasBar;
|
m_hasBar = hasBar;
|
||||||
|
@ -76,7 +78,8 @@ public final class VTreePanel extends CPanel
|
||||||
if (!hasBar)
|
if (!hasBar)
|
||||||
{
|
{
|
||||||
bar.setPreferredSize(new Dimension(0,0));
|
bar.setPreferredSize(new Dimension(0,0));
|
||||||
centerSplitPane.setDividerLocation(0);
|
//centerSplitPane.setDividerLocation(0);
|
||||||
|
centerSplitPane.setDividerLocation(1000);
|
||||||
centerSplitPane.setDividerSize(0);
|
centerSplitPane.setDividerSize(0);
|
||||||
popMenuTree.remove(mBarAdd);
|
popMenuTree.remove(mBarAdd);
|
||||||
}
|
}
|
||||||
|
@ -123,16 +126,50 @@ public final class VTreePanel extends CPanel
|
||||||
// Shortcut Bar
|
// Shortcut Bar
|
||||||
if (m_hasBar)
|
if (m_hasBar)
|
||||||
{
|
{
|
||||||
toolbar.removeAll(); // remove all existing buttons
|
for (JToolBar jt : toolbar)
|
||||||
Enumeration en = m_root.preorderEnumeration();
|
jt.removeAll();
|
||||||
|
toolbarMap = new HashMap<Integer, JToolBar>();
|
||||||
|
Enumeration enTop =m_root.children();
|
||||||
|
JToolBar jt = null;
|
||||||
|
while (enTop.hasMoreElements())
|
||||||
|
{
|
||||||
|
MTreeNode ndTop = (MTreeNode)enTop.nextElement();
|
||||||
|
Enumeration en = ndTop.preorderEnumeration();
|
||||||
|
boolean labelDrawn=false;
|
||||||
while (en.hasMoreElements())
|
while (en.hasMoreElements())
|
||||||
{
|
{
|
||||||
MTreeNode nd = (MTreeNode)en.nextElement();
|
MTreeNode nd = (MTreeNode)en.nextElement();
|
||||||
if (nd.isOnBar())
|
if (nd.isOnBar()) {
|
||||||
addToBar(nd);
|
if (!labelDrawn) {
|
||||||
|
jt = new JToolBar(JToolBar.VERTICAL);
|
||||||
|
addToBar(ndTop, jt, true);
|
||||||
|
labelDrawn=true;
|
||||||
|
toolbarMap.put(ndTop.getNode_ID(), jt);
|
||||||
|
}
|
||||||
|
addToBar(nd, jt, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (jt!=null)
|
||||||
|
toolbar.add(jt);
|
||||||
|
jt=null;
|
||||||
|
}
|
||||||
|
//jbInit();
|
||||||
|
for (JToolBar jt2 : toolbar) {
|
||||||
|
jt2.setOpaque(false);
|
||||||
|
//jt2.setLayout(new GridBagLayout());
|
||||||
|
jt2.setFloatable(false);
|
||||||
|
jt2.setRollover(true);
|
||||||
|
jt2.setBorder(BorderFactory.createEmptyBorder());
|
||||||
|
CPanel barPart = new CPanel();
|
||||||
|
barPart.setLayout(new BorderLayout());
|
||||||
|
barPart.add(jt2, BorderLayout.NORTH);
|
||||||
|
barPart.setBorder(new ShadowBorder());
|
||||||
|
bar.add(barPart);
|
||||||
|
}
|
||||||
|
if (toolbarMap.size()<=3){
|
||||||
|
bar.setLayout(new GridLayout(0, 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} // initTree
|
} // initTree
|
||||||
|
|
||||||
|
@ -152,7 +189,11 @@ public final class VTreePanel extends CPanel
|
||||||
private CMenuItem mFrom = new CMenuItem();
|
private CMenuItem mFrom = new CMenuItem();
|
||||||
private CMenuItem mTo = new CMenuItem();
|
private CMenuItem mTo = new CMenuItem();
|
||||||
private CPanel bar = new CPanel();
|
private CPanel bar = new CPanel();
|
||||||
private JToolBar toolbar = new JToolBar(JToolBar.VERTICAL);
|
private java.util.List<JToolBar> toolbar;
|
||||||
|
private HashMap<Integer, JToolBar> toolbarMap;
|
||||||
|
private int toolBarCols=3;
|
||||||
|
//private int toolBarRows=2;
|
||||||
|
//private JToolBar toolbar = new JToolBar(JToolBar.VERTICAL);
|
||||||
private CMenuItem mBarAdd = new CMenuItem();
|
private CMenuItem mBarAdd = new CMenuItem();
|
||||||
private CMenuItem mBarRemove = new CMenuItem();
|
private CMenuItem mBarRemove = new CMenuItem();
|
||||||
private BorderLayout southLayout = new BorderLayout();
|
private BorderLayout southLayout = new BorderLayout();
|
||||||
|
@ -231,13 +272,19 @@ public final class VTreePanel extends CPanel
|
||||||
this.add(southPanel, BorderLayout.SOUTH);
|
this.add(southPanel, BorderLayout.SOUTH);
|
||||||
//
|
//
|
||||||
centerSplitPane.setOpaque(false);
|
centerSplitPane.setOpaque(false);
|
||||||
toolbar.setOpaque(false);
|
centerSplitPane.add(treePane, JSplitPane.LEFT); //fcsku 3.7.2007 switch menu/favorites
|
||||||
centerSplitPane.add(treePane, JSplitPane.RIGHT);
|
centerSplitPane.add(bar, JSplitPane.RIGHT);
|
||||||
centerSplitPane.add(bar, JSplitPane.LEFT);
|
|
||||||
centerSplitPane.setBorder(BorderFactory.createEmptyBorder());
|
centerSplitPane.setBorder(BorderFactory.createEmptyBorder());
|
||||||
removeSplitPaneBorder();
|
removeSplitPaneBorder();
|
||||||
|
|
||||||
this.add(centerSplitPane, BorderLayout.CENTER);
|
this.add(centerSplitPane, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
GridLayout barLayout = new GridLayout(0, toolBarCols);
|
||||||
|
bar.setMinimumSize(new Dimension (50,50));
|
||||||
|
bar.setBorder(new ShadowBorder());
|
||||||
|
bar.setLayout(barLayout);
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
mFrom.setText(Msg.getMsg(Env.getCtx(), "ItemMove"));
|
mFrom.setText(Msg.getMsg(Env.getCtx(), "ItemMove"));
|
||||||
mFrom.setActionCommand("From");
|
mFrom.setActionCommand("From");
|
||||||
|
@ -246,16 +293,6 @@ public final class VTreePanel extends CPanel
|
||||||
mTo.setText(Msg.getMsg(Env.getCtx(), "ItemInsert"));
|
mTo.setText(Msg.getMsg(Env.getCtx(), "ItemInsert"));
|
||||||
mTo.setActionCommand("To");
|
mTo.setActionCommand("To");
|
||||||
mTo.addActionListener(this);
|
mTo.addActionListener(this);
|
||||||
//
|
|
||||||
bar.setMinimumSize(new Dimension (50,50));
|
|
||||||
bar.setBorder(new ShadowBorder());
|
|
||||||
bar.setLayout(new FlowLayout());
|
|
||||||
((FlowLayout)bar.getLayout()).setAlignment(FlowLayout.LEFT);
|
|
||||||
bar.add(toolbar);
|
|
||||||
toolbar.setLayout(new GridBagLayout());
|
|
||||||
toolbar.setFloatable(false);
|
|
||||||
toolbar.setRollover(true);
|
|
||||||
toolbar.setBorder(BorderFactory.createEmptyBorder());
|
|
||||||
|
|
||||||
mBarAdd.setText(Msg.getMsg(Env.getCtx(), "BarAdd"));
|
mBarAdd.setText(Msg.getMsg(Env.getCtx(), "BarAdd"));
|
||||||
mBarAdd.setActionCommand("BarAdd");
|
mBarAdd.setActionCommand("BarAdd");
|
||||||
|
@ -858,43 +895,91 @@ public final class VTreePanel extends CPanel
|
||||||
{
|
{
|
||||||
MTreeNode nd = (MTreeNode)tree.getSelectionPath().getLastPathComponent();
|
MTreeNode nd = (MTreeNode)tree.getSelectionPath().getLastPathComponent();
|
||||||
if (barDBupdate(true, nd.getNode_ID()))
|
if (barDBupdate(true, nd.getNode_ID()))
|
||||||
addToBar(nd);
|
addToBar(nd,getParentToolBar(nd), false);
|
||||||
|
else if (CLogger.retrieveException().getMessage().indexOf("ORA-00001")!=-1)
|
||||||
|
ADialog.error(0, this, "", "Item is already on Bar");
|
||||||
} // barAdd
|
} // barAdd
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the top level parent JToolBar for the given MTreenode. If the parent is not on
|
||||||
|
* the CPanel yet a new one is created and added.
|
||||||
|
* @param nd
|
||||||
|
* @return top level parent JToolBar for the given MTreenode
|
||||||
|
*/
|
||||||
|
private JToolBar getParentToolBar(MTreeNode nd){
|
||||||
|
int topParentId = getTopParentId(nd);
|
||||||
|
JToolBar parent = toolbarMap.get(topParentId);
|
||||||
|
if(parent==null){
|
||||||
|
Enumeration enTop =m_root.children();
|
||||||
|
while (enTop.hasMoreElements()) {
|
||||||
|
MTreeNode ndTop = (MTreeNode)enTop.nextElement();
|
||||||
|
if(ndTop.getNode_ID()==topParentId){
|
||||||
|
log.fine("add new category: " + ndTop);
|
||||||
|
parent = new JToolBar(JToolBar.VERTICAL);
|
||||||
|
addToBar(ndTop, parent, true);
|
||||||
|
toolbarMap.put(ndTop.getNode_ID(), parent);
|
||||||
|
toolbar.add(parent);
|
||||||
|
parent.setOpaque(false);
|
||||||
|
parent.setFloatable(false);
|
||||||
|
parent.setRollover(true);
|
||||||
|
parent.setBorder(BorderFactory.createEmptyBorder());
|
||||||
|
CPanel barPart = new CPanel();
|
||||||
|
barPart.setLayout(new BorderLayout());
|
||||||
|
barPart.add(parent, BorderLayout.NORTH);
|
||||||
|
barPart.setBorder(new ShadowBorder());
|
||||||
|
bar.add(barPart);
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.fine("parent found: " + parent);
|
||||||
|
}
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the id of the top level parent of the given MTreenode
|
||||||
|
* @param nd
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private int getTopParentId(MTreeNode nd) {
|
||||||
|
MTreeNode parent = (MTreeNode) nd.getParent();
|
||||||
|
if(parent!=null && parent.getNode_ID()!=0){
|
||||||
|
return getTopParentId(parent);
|
||||||
|
}
|
||||||
|
return nd.getNode_ID();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add TreeNode to Bar
|
* Add TreeNode to Bar
|
||||||
* @param nd node
|
* @param nd node
|
||||||
*/
|
*/
|
||||||
private void addToBar(MTreeNode nd)
|
private void addToBar(MTreeNode nd, JToolBar currentToolBar, boolean isLabel)
|
||||||
{
|
{
|
||||||
// Only first word of Label
|
// Only first word of Label
|
||||||
String label = nd.toString().trim();
|
String label = nd.toString().trim();
|
||||||
int space = label.indexOf(' ');
|
// int space = label.indexOf(' ');
|
||||||
// if (space != -1)
|
// if (space != -1)
|
||||||
// label = label.substring(0, space);
|
// label = label.substring(0, space);
|
||||||
|
|
||||||
|
if (!isLabel) {
|
||||||
CButton button = new CButton(label);
|
CButton button = new CButton(label);
|
||||||
button.setOpaque(false);
|
button.setOpaque(false);
|
||||||
button.setHorizontalAlignment(JButton.LEFT);
|
button.setHorizontalAlignment(JButton.LEFT);
|
||||||
button.setToolTipText(nd.getDescription());
|
|
||||||
button.setActionCommand(String.valueOf(nd.getNode_ID()));
|
|
||||||
//
|
|
||||||
button.setMargin(new Insets(0, 0, 0, 0));
|
button.setMargin(new Insets(0, 0, 0, 0));
|
||||||
button.setIcon(nd.getIcon());
|
button.setIcon(nd.getIcon());
|
||||||
//button.setBorderPainted(false);
|
|
||||||
button.setRequestFocusEnabled(false);
|
button.setRequestFocusEnabled(false);
|
||||||
//
|
button.setToolTipText(nd.getDescription());
|
||||||
|
button.setActionCommand(String.valueOf(nd.getNode_ID()));
|
||||||
button.addActionListener(this);
|
button.addActionListener(this);
|
||||||
button.addMouseListener(mouseListener);
|
button.addMouseListener(mouseListener);
|
||||||
//
|
currentToolBar.add(button);
|
||||||
toolbar.add(button,
|
} else {
|
||||||
new GridBagConstraints(0, GridBagConstraints.RELATIVE,
|
currentToolBar.add(new JLabel("<html><u><b>" +label+"</b></u></html>"));
|
||||||
1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST,
|
}
|
||||||
GridBagConstraints.HORIZONTAL, new Insets(1,0,1,0), 4,2));
|
|
||||||
bar.validate();
|
bar.validate();
|
||||||
|
//if (centerSplitPane.getDividerLocation() == -1)
|
||||||
if (centerSplitPane.getDividerLocation() == -1)
|
// centerSplitPane.setDividerLocation(button.getPreferredSize().width);
|
||||||
centerSplitPane.setDividerLocation(button.getPreferredSize().width);
|
|
||||||
bar.repaint();
|
bar.repaint();
|
||||||
} // addToBar
|
} // addToBar
|
||||||
|
|
||||||
|
@ -903,7 +988,23 @@ public final class VTreePanel extends CPanel
|
||||||
*/
|
*/
|
||||||
private void barRemove()
|
private void barRemove()
|
||||||
{
|
{
|
||||||
toolbar.remove(m_buttonSelected);
|
//the button in on a JToolBar which is on a CPanel
|
||||||
|
JToolBar parentBar = (JToolBar) m_buttonSelected.getParent();
|
||||||
|
Container parentPanel = null;
|
||||||
|
if(parentBar!=null){
|
||||||
|
parentPanel = parentBar.getParent();
|
||||||
|
}
|
||||||
|
for (JToolBar jt : toolbar) {
|
||||||
|
jt.remove(m_buttonSelected);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(parentPanel != null && parentBar.getComponentCount()==1){
|
||||||
|
//only label left
|
||||||
|
bar.remove(parentPanel);
|
||||||
|
//remove from toolBarMap..
|
||||||
|
toolbarMap.values().remove(parentBar);
|
||||||
|
|
||||||
|
}
|
||||||
bar.validate();
|
bar.validate();
|
||||||
bar.repaint();
|
bar.repaint();
|
||||||
barDBupdate(false, Integer.parseInt(m_buttonSelected.getActionCommand()));
|
barDBupdate(false, Integer.parseInt(m_buttonSelected.getActionCommand()));
|
||||||
|
@ -934,7 +1035,7 @@ public final class VTreePanel extends CPanel
|
||||||
sql.append("DELETE AD_TreeBar WHERE AD_Tree_ID=").append(m_AD_Tree_ID)
|
sql.append("DELETE AD_TreeBar WHERE AD_Tree_ID=").append(m_AD_Tree_ID)
|
||||||
.append(" AND AD_User_ID=").append(AD_User_ID)
|
.append(" AND AD_User_ID=").append(AD_User_ID)
|
||||||
.append(" AND Node_ID=").append(Node_ID);
|
.append(" AND Node_ID=").append(Node_ID);
|
||||||
int no = DB.executeUpdate(sql.toString(), true, null);
|
int no = DB.executeUpdate(sql.toString(), false, null);
|
||||||
return no == 1;
|
return no == 1;
|
||||||
} // barDBupdate
|
} // barDBupdate
|
||||||
|
|
||||||
|
@ -1021,3 +1122,5 @@ class VTreePanel_keyAdapter extends java.awt.event.KeyAdapter
|
||||||
m_adaptee.keyPressed(e);
|
m_adaptee.keyPressed(e);
|
||||||
}
|
}
|
||||||
} // VTreePanel_keyAdapter
|
} // VTreePanel_keyAdapter
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue