com.exploitpack.scanner.ShowDialog.java Source code

Java tutorial

Introduction

Here is the source code for com.exploitpack.scanner.ShowDialog.java

Source

/**
Exploit Pack - Security Framework for Exploit Developers
Copyright 2011 Juan Sacco http://exploitpack.com
    
This program is free software: you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation, either version 3 
or any later version.
    
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License along with this program. 
If not, see http://www.gnu.org/licenses/
 **/

package com.exploitpack.scanner;

import java.lang.reflect.InvocationTargetException;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.ui.handlers.HandlerUtil;

public class ShowDialog extends AbstractHandler {

    @Override
    public Object execute(ExecutionEvent event) throws ExecutionException {
        ProgressMonitorDialog dialog = new ProgressMonitorDialog(HandlerUtil.getActiveShell(event).getShell());
        try {
            dialog.run(true, true, new IRunnableWithProgress() {
                @Override
                public void run(IProgressMonitor monitor) {
                    monitor.beginTask("Doing something timeconsuming here", 100);
                    for (int i = 0; i < 10; i++) {
                        if (monitor.isCanceled())
                            return;
                        monitor.subTask("I'm doing something here " + i);
                        sleep(1000);
                        // worked increates the monitor, the values is added to the existing ones
                        monitor.worked(1);
                    }
                    monitor.done();
                }
            });
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        return null;
    }

    private void sleep(Integer waitTime) {
        try {
            Thread.sleep(waitTime);
        } catch (Throwable t) {
            System.out.println("Wait time interrupted");
        }
    }

}