package net.sourceforge.javydreamercsw.client.ui.components.database;

import com.validation.manager.core.api.entity.manager.VMEntityManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionReferences;
import org.openide.awt.ActionRegistration;
import org.openide.util.Lookup;
import org.openide.util.NbBundle.Messages;

@ActionID(
        category = "Tools",
        id = "net.sourceforge.javydreamercsw.client.ui.ConnectAction")
@ActionRegistration(
        iconBase = "net/sourceforge/javydreamercsw/client/ui/database/database-connect-icon.png",
        displayName = "#CTL_ConnectAction")
@ActionReferences({
    @ActionReference(path = "Toolbars/Actions", position = 300),
    @ActionReference(path = "Shortcuts", name = "D-C")
})
@Messages("CTL_ConnectAction=Connect")
public final class ConnectAction implements ActionListener {

    private static final Logger LOG
            = Logger.getLogger(ConnectAction.class.getSimpleName());

    @Override
    public void actionPerformed(ActionEvent e) {
        //Connect to database
        DataBaseTool.connect();
        //Initialize any EntityManager that needs it
        for (VMEntityManager m : Lookup.getDefault().lookupAll(VMEntityManager.class)) {
            LOG.log(Level.FINE, "{0} registered!",
                    new Object[]{m.getClass().getSimpleName(),
                        m.getEntities().size()});
        }
    }
}

@@ -269,24 +269,129 @@
 ing.Logger;%0A
+import org.netbeans.api.progress.ProgressHandle;%0Aimport org.netbeans.api.progress.ProgressHandleFactory;%0A
 import org.o
@@ -535,16 +535,53 @@
 ration;%0A
+import org.openide.util.Cancellable;%0A
 import o
@@ -646,16 +646,96 @@
 essages;
+%0Aimport org.openide.util.RequestProcessor;%0Aimport org.openide.util.TaskListener;
 %0A%0A@Actio
@@ -1354,72 +1354,837 @@
 ));%0A
-%0A    @Override%0A    public void actionPerformed(ActionEvent e) %7B%0A
+    private final RequestProcessor RP%0A            = new RequestProcessor(%22Database Connector%22, 1, true);%0A    private RequestProcessor.Task theTask = null;%0A    private ProgressHandle ph;%0A%0A    @Override%0A    public void actionPerformed(ActionEvent e) %7B%0A        java.awt.EventQueue.invokeLater(new Runnable() %7B%0A            @Override%0A            public void run() %7B%0A                ph = ProgressHandleFactory.createHandle(%22Database Connector%22,%0A                        new Cancellable() %7B%0A%0A                            @Override%0A                            public boolean cancel() %7B%0A                                return handleCancel();%0A                            %7D%0A                        %7D);%0A                Runnable runnable = new Runnable() %7B%0A%0A                    @Override%0A                    public void run() %7B%0A                
     
@@ -2209,16 +2209,32 @@
 atabase%0A
+                
         
@@ -2253,24 +2253,1194 @@
 .connect();%0A
+                    %7D%0A                %7D;%0A                theTask = RP.create(runnable); //the task is not started yet%0A%0A                theTask.addTaskListener(new TaskListener() %7B%0A                    public void taskFinished(RequestProcessor.Task task) %7B%0A                        ph.finish();%0A                        LOG.log(Level.FINE,%0A                                %22Connecting to Database done!%22);%0A                    %7D%0A%0A                    @Override%0A                    public void taskFinished(org.openide.util.Task task) %7B%0A                        ph.finish();%0A                        LOG.log(Level.FINE,%0A                                %22Connecting to Database done!%22);%0A                    %7D%0A                %7D);%0A                //start the progresshandle the progress UI will show 500s after%0A                ph.start();%0A%0A                //this actually start the task%0A                theTask.schedule(0);%0A            %7D%0A%0A            private boolean handleCancel() %7B%0A                LOG.info(%22handleCancel%22);%0A                if (null == theTask) %7B%0A                    return false;%0A                %7D%0A                return theTask.cancel();%0A            %7D%0A        %7D);%0A
         //In

Add progress indication to the database connection process.