|
|
|
|
@ -29,19 +29,14 @@ public class DnDRiscosListener implements DropTargetListener
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void dragEnter(DropTargetDragEvent dtde)
|
|
|
|
|
public void dragEnter( DropTargetDragEvent dtde )
|
|
|
|
|
{
|
|
|
|
|
DefaultMutableTreeNode node = ( ( DefaultMutableTreeNode ) tree.getSelectionPath().getParentPath().getLastPathComponent() );
|
|
|
|
|
if ( node.getUserObject() == null )
|
|
|
|
|
DefaultMutableTreeNode node = ( ( DefaultMutableTreeNode ) tree.getSelectionPath().getParentPath().getLastPathComponent() );
|
|
|
|
|
drag = node.getUserObject() != null;
|
|
|
|
|
if ( ! drag )
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
drag = false;
|
|
|
|
|
dtde.rejectDrag();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
drag = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@ -50,92 +45,90 @@ public class DnDRiscosListener implements DropTargetListener
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void dragOver(DropTargetDragEvent dtde)
|
|
|
|
|
public void dragOver( DropTargetDragEvent dtde )
|
|
|
|
|
{
|
|
|
|
|
Point pt = dtde.getLocation();
|
|
|
|
|
|
|
|
|
|
tree.autoscroll( pt );
|
|
|
|
|
|
|
|
|
|
if( drag )
|
|
|
|
|
if ( drag )
|
|
|
|
|
{
|
|
|
|
|
TreePath parentpath = tree.getClosestPathForLocation(pt.x, pt.y);
|
|
|
|
|
Object destObject = ( (DefaultMutableTreeNode )parentpath.getLastPathComponent() ).getUserObject();
|
|
|
|
|
TreePath sourcePath = tree.getClosestPathForLocation( pt.x, pt.y );
|
|
|
|
|
Object destObject = ( ( DefaultMutableTreeNode ) sourcePath.getLastPathComponent() ).getUserObject();
|
|
|
|
|
|
|
|
|
|
if( tree.getSelectedMedida() != null && ( destObject instanceof HsRiscoTemaData ) )
|
|
|
|
|
if ( tree.getSelectedMedida() != null && ( destObject instanceof HsRiscoTemaData ) )
|
|
|
|
|
{
|
|
|
|
|
tree.expandPath( parentpath );
|
|
|
|
|
tree.expandPath( sourcePath );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void drop(DropTargetDropEvent dtde)
|
|
|
|
|
public void drop( DropTargetDropEvent dtde )
|
|
|
|
|
{
|
|
|
|
|
System.out.println( "Drop" );
|
|
|
|
|
|
|
|
|
|
Point pt = dtde.getLocation();
|
|
|
|
|
TreePath destinyPath = tree.getClosestPathForLocation(pt.x, pt.y);
|
|
|
|
|
TreePath destinationPath = tree.getClosestPathForLocation( pt.x, pt.y );
|
|
|
|
|
|
|
|
|
|
Object destinyComponent = destinyPath.getLastPathComponent();
|
|
|
|
|
System.out.println( destinyPath );
|
|
|
|
|
Object destinationComponent = destinationPath.getLastPathComponent();
|
|
|
|
|
System.out.println( destinationPath );
|
|
|
|
|
System.out.println( );
|
|
|
|
|
|
|
|
|
|
if( destinyComponent instanceof DefaultMutableTreeNode )
|
|
|
|
|
if( destinationComponent instanceof DefaultMutableTreeNode )
|
|
|
|
|
{
|
|
|
|
|
System.out.println("moving node ...");
|
|
|
|
|
DefaultMutableTreeNode destinyNode = ( DefaultMutableTreeNode ) destinyComponent;
|
|
|
|
|
Object destinyObject = destinyNode.getUserObject();
|
|
|
|
|
DefaultMutableTreeNode destinationNode = ( DefaultMutableTreeNode ) destinationComponent;
|
|
|
|
|
Object destinationObject = destinationNode.getUserObject();
|
|
|
|
|
|
|
|
|
|
TreePath parentPath = tree.getSelectionPath();
|
|
|
|
|
Object parentComponent = parentPath.getLastPathComponent();
|
|
|
|
|
TreePath sourcePath = tree.getSelectionPath();
|
|
|
|
|
Object sourceComponent = sourcePath.getLastPathComponent();
|
|
|
|
|
|
|
|
|
|
if( parentComponent instanceof DefaultMutableTreeNode )
|
|
|
|
|
if( sourceComponent instanceof DefaultMutableTreeNode )
|
|
|
|
|
{
|
|
|
|
|
DefaultMutableTreeNode parentNode = ( DefaultMutableTreeNode ) parentComponent;
|
|
|
|
|
Object parentObject = parentNode.getUserObject();
|
|
|
|
|
DefaultMutableTreeNode sourceNode = ( DefaultMutableTreeNode ) sourceComponent;
|
|
|
|
|
Object sourceObject = sourceNode.getUserObject();
|
|
|
|
|
|
|
|
|
|
if( destinyObject instanceof HsRiscoTemaData )
|
|
|
|
|
{
|
|
|
|
|
System.out.println("\tmove risco -> tema");
|
|
|
|
|
HsRiscoTemaData destTema = ( HsRiscoTemaData ) destinyObject;
|
|
|
|
|
|
|
|
|
|
if ( parentObject instanceof HsRiscoData )
|
|
|
|
|
{
|
|
|
|
|
moveRisco( destinyNode, parentNode, parentObject, destTema );
|
|
|
|
|
if( destinationObject instanceof HsRiscoTemaData )
|
|
|
|
|
{ // something -> tema
|
|
|
|
|
if ( sourceObject instanceof HsRiscoData )
|
|
|
|
|
{ // risco -> tema
|
|
|
|
|
System.out.println("\tmove risco -> tema");
|
|
|
|
|
|
|
|
|
|
HsRiscoTemaData destTema = ( HsRiscoTemaData ) destinationObject;
|
|
|
|
|
moveRisco( destinationNode, sourceNode, sourceObject, destTema );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if( destinyObject instanceof HsRiscoData )
|
|
|
|
|
{
|
|
|
|
|
if ( parentObject instanceof HsRiscoData )
|
|
|
|
|
{
|
|
|
|
|
destinyComponent = destinyPath.getParentPath().getLastPathComponent();
|
|
|
|
|
destinyNode = ( DefaultMutableTreeNode )destinyComponent;
|
|
|
|
|
destinyObject = destinyNode.getUserObject();
|
|
|
|
|
HsRiscoTemaData destTema = ( HsRiscoTemaData ) destinyObject;
|
|
|
|
|
else if( destinationObject instanceof HsRiscoData )
|
|
|
|
|
{ // something -> risco
|
|
|
|
|
if ( sourceObject instanceof HsRiscoMedidaData )
|
|
|
|
|
{ // medida -> risco
|
|
|
|
|
System.out.println("\tmove medida -> risco");
|
|
|
|
|
HsRiscoData destRisco = ( HsRiscoData ) destinationObject;
|
|
|
|
|
|
|
|
|
|
moveRisco( destinyNode, parentNode, parentObject, destTema );
|
|
|
|
|
moveMedida( destinationNode, sourceNode, sourceObject, destRisco );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if( destinyObject instanceof HsRiscoData )
|
|
|
|
|
{
|
|
|
|
|
System.out.println("\tmove medida -> risco");
|
|
|
|
|
HsRiscoData destRisco = ( HsRiscoData ) destinyObject;
|
|
|
|
|
|
|
|
|
|
if ( parentObject instanceof HsRiscoMedidaData )
|
|
|
|
|
{
|
|
|
|
|
moveMedida( destinyNode, parentNode, parentObject, destRisco );
|
|
|
|
|
else if( sourceObject instanceof HsRiscoData )
|
|
|
|
|
{ // risco -> risco ( risco -> tema )
|
|
|
|
|
System.out.println( "\tmove risco -> risco ( risco -> tema )" );
|
|
|
|
|
|
|
|
|
|
destinationComponent = destinationPath.getParentPath().getLastPathComponent();
|
|
|
|
|
destinationNode = ( DefaultMutableTreeNode )destinationComponent;
|
|
|
|
|
destinationObject = destinationNode.getUserObject();
|
|
|
|
|
HsRiscoTemaData destTema = ( HsRiscoTemaData ) destinationObject;
|
|
|
|
|
|
|
|
|
|
moveRisco( destinationNode, sourceNode, sourceObject, destTema );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if( destinyObject instanceof HsRiscoMedidaData )
|
|
|
|
|
{
|
|
|
|
|
destinyComponent = destinyPath.getParentPath().getLastPathComponent();
|
|
|
|
|
destinyNode = ( DefaultMutableTreeNode ) destinyComponent;
|
|
|
|
|
destinyObject = destinyNode.getUserObject();
|
|
|
|
|
HsRiscoData destRisco = ( HsRiscoData ) destinyObject;
|
|
|
|
|
|
|
|
|
|
if ( parentObject instanceof HsRiscoMedidaData )
|
|
|
|
|
{
|
|
|
|
|
moveMedida( destinyNode, parentNode, parentObject, destRisco );
|
|
|
|
|
}
|
|
|
|
|
else if( destinationObject instanceof HsRiscoMedidaData )
|
|
|
|
|
{ // something -> medida
|
|
|
|
|
if ( sourceObject instanceof HsRiscoMedidaData )
|
|
|
|
|
{ // medida -> medida ( medida -> risco )
|
|
|
|
|
System.out.println( "\tmove medida -> medida parent ( risco )" );
|
|
|
|
|
|
|
|
|
|
destinationComponent = destinationPath.getParentPath().getLastPathComponent();
|
|
|
|
|
destinationNode = ( DefaultMutableTreeNode ) destinationComponent;
|
|
|
|
|
destinationObject = destinationNode.getUserObject();
|
|
|
|
|
HsRiscoData destRisco = ( HsRiscoData ) destinationObject;
|
|
|
|
|
|
|
|
|
|
moveMedida( destinationNode, sourceNode, sourceObject, destRisco );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -147,15 +140,15 @@ public class DnDRiscosListener implements DropTargetListener
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void moveMedida( DefaultMutableTreeNode destinyNode, DefaultMutableTreeNode parentNode, Object parentObject, HsRiscoData destRisco )
|
|
|
|
|
private void moveMedida( DefaultMutableTreeNode destinationNode, DefaultMutableTreeNode sourceNode, Object sourceObject, HsRiscoData destRisco )
|
|
|
|
|
{
|
|
|
|
|
HsRiscoMedidaData parent = ( HsRiscoMedidaData ) parentObject;
|
|
|
|
|
parent.setToRisco_id( destRisco );
|
|
|
|
|
HsRiscoMedidaData source = ( HsRiscoMedidaData ) sourceObject;
|
|
|
|
|
source.setToRisco_id( destRisco );
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
parent.save();
|
|
|
|
|
destinyNode.add( parentNode );
|
|
|
|
|
source.save();
|
|
|
|
|
destinationNode.add( sourceNode );
|
|
|
|
|
tree.updateUI();
|
|
|
|
|
}
|
|
|
|
|
catch ( EvoDataException e )
|
|
|
|
|
@ -164,14 +157,14 @@ public class DnDRiscosListener implements DropTargetListener
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void moveRisco( DefaultMutableTreeNode destinyNode, DefaultMutableTreeNode parentNode, Object parentObject, HsRiscoTemaData destTema )
|
|
|
|
|
private void moveRisco( DefaultMutableTreeNode destinationNode, DefaultMutableTreeNode sourceNode, Object soruceObject, HsRiscoTemaData destTema )
|
|
|
|
|
{
|
|
|
|
|
HsRiscoData parent = ( HsRiscoData ) parentObject;
|
|
|
|
|
parent.setToTema_id( destTema );
|
|
|
|
|
HsRiscoData source = ( HsRiscoData ) soruceObject;
|
|
|
|
|
source.setToTema_id( destTema );
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
parent.save();
|
|
|
|
|
destinyNode.add( parentNode );
|
|
|
|
|
source.save();
|
|
|
|
|
destinationNode.add( sourceNode );
|
|
|
|
|
tree.updateUI();
|
|
|
|
|
}
|
|
|
|
|
catch ( EvoDataException e )
|
|
|
|
|
|