Search in sources :

Example 1 with ProgressEvent

use of org.eclipse.zest.layouts.progress.ProgressEvent in project archi by archimatetool.

the class SimpleSWTExample method performLayout.

private void performLayout(boolean placeRandomly) {
    if (!continuous) {
    }
    if (currentLayoutAlgorithm.isRunning()) {
        throw new RuntimeException("Layout is already running");
    }
    if (placeRandomly) {
        placeRandomly();
    }
    ProgressListener progressListener = new ProgressListener() {

        int lastStep = 0;

        class progressSync implements Runnable {

            public static final int PROGRESS_UPDATED = 1;

            public static final int PROGRESS_STARTED = 2;

            public static final int PROGRESS_ENDED = 3;

            public static final int UPDATE_GUI = 4;

            private int progressState = -1;

            private ProgressEvent e;

            public progressSync(int progressState, final ProgressEvent e) {
                this.progressState = progressState;
                this.e = e;
            }

            @Override
            public void run() {
                switch(progressState) {
                    case PROGRESS_STARTED:
                        if (!continuous) {
                            pmd = new ProgressMonitorDialog(getShell());
                            progressMonitor = pmd.getProgressMonitor();
                            pmd.open();
                            progressMonitor.beginTask("Layout Running...", e.getTotalNumberOfSteps());
                        }
                        break;
                    case PROGRESS_UPDATED:
                        if (!continuous) {
                            progressMonitor.worked(e.getStepsCompleted() - lastStep);
                            lastStep = e.getStepsCompleted();
                        }
                        break;
                    case PROGRESS_ENDED:
                        if (!continuous) {
                            progressMonitor.done();
                            pmd.close();
                        }
                        updateGUI();
                        mainShell.redraw();
                        break;
                    case UPDATE_GUI:
                        updateGUI();
                        GUI_UPDATING = false;
                        break;
                }
                mainComposite.redraw();
            }
        }

        @Override
        public void progressUpdated(final ProgressEvent e) {
            if (asynchronously) {
                if (!mainComposite.isDisposed()) {
                    Display.getDefault().asyncExec(new progressSync(progressSync.PROGRESS_UPDATED, e));
                    if (!GUI_UPDATING) {
                        GUI_UPDATING = true;
                        Display.getDefault().asyncExec(new progressSync(progressSync.UPDATE_GUI, e));
                    }
                }
            } else {
                if (!mainComposite.isDisposed()) {
                    new progressSync(progressSync.PROGRESS_UPDATED, e).run();
                }
            }
        }

        @Override
        public void progressStarted(ProgressEvent e) {
            if (asynchronously) {
                if (!mainComposite.isDisposed()) {
                    Display.getDefault().asyncExec(new progressSync(progressSync.PROGRESS_STARTED, e));
                }
            } else {
                if (!mainComposite.isDisposed()) {
                    new progressSync(progressSync.PROGRESS_STARTED, e).run();
                }
            }
        }

        @Override
        public void progressEnded(ProgressEvent e) {
            if (asynchronously) {
                if (!mainComposite.isDisposed()) {
                    Display.getDefault().asyncExec(new progressSync(progressSync.PROGRESS_ENDED, e));
                }
            } else {
                if (!mainComposite.isDisposed()) {
                    new progressSync(progressSync.PROGRESS_ENDED, e).run();
                }
            }
            currentLayoutAlgorithm.removeProgressListener(this);
            Display.getDefault().asyncExec(new progressSync(progressSync.PROGRESS_UPDATED, e));
        }
    };
    currentLayoutAlgorithm.addProgressListener(progressListener);
    try {
        LayoutEntity[] layoutEntities = new LayoutEntity[entities.size()];
        entities.toArray(layoutEntities);
        LayoutRelationship[] layoutRelationships = new LayoutRelationship[relationships.size()];
        relationships.toArray(layoutRelationships);
        currentLayoutAlgorithm.applyLayout(layoutEntities, layoutRelationships, 0, 0, mainComposite.getClientArea().width - 30, mainComposite.getClientArea().height - 17, asynchronously, continuous);
        if (!animate) {
            updateGUI();
        }
    } catch (InvalidLayoutConfiguration e) {
        e.printStackTrace();
    }
}
Also used : ProgressListener(org.eclipse.zest.layouts.progress.ProgressListener) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) LayoutEntity(org.eclipse.zest.layouts.LayoutEntity) ProgressEvent(org.eclipse.zest.layouts.progress.ProgressEvent) Point(org.eclipse.swt.graphics.Point) LayoutBendPoint(org.eclipse.zest.layouts.LayoutBendPoint) LayoutRelationship(org.eclipse.zest.layouts.LayoutRelationship) InvalidLayoutConfiguration(org.eclipse.zest.layouts.InvalidLayoutConfiguration)

Example 2 with ProgressEvent

use of org.eclipse.zest.layouts.progress.ProgressEvent in project archi by archimatetool.

the class SimpleSwingExample method performLayout.

protected void performLayout() {
    stop();
    final Cursor cursor = mainFrame.getCursor();
    updateGUICount = 0;
    placeRandomly();
    final boolean continuous = btnContinuous.isSelected();
    final boolean asynchronous = btnAsynchronous.isSelected();
    ProgressListener progressListener = new ProgressListener() {

        @Override
        public void progressUpdated(final ProgressEvent e) {
            // if (asynchronous) {
            updateGUI();
            // }
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            lblProgress.setText("Progress: " + e.getStepsCompleted() + " of " + e.getTotalNumberOfSteps() + " completed ...");
            lblProgress.paintImmediately(0, 0, lblProgress.getWidth(), lblProgress.getHeight());
        }

        @Override
        public void progressStarted(ProgressEvent e) {
            if (!asynchronous) {
                mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            }
            // $NON-NLS-1$
            lblProgress.setText("Layout started ...");
            lblProgress.paintImmediately(0, 0, lblProgress.getWidth(), lblProgress.getHeight());
        }

        @Override
        public void progressEnded(ProgressEvent e) {
            // $NON-NLS-1$
            lblProgress.setText("Layout completed ...");
            lblProgress.paintImmediately(0, 0, lblProgress.getWidth(), lblProgress.getHeight());
            currentLayoutAlgorithm.removeProgressListener(this);
            if (!asynchronous) {
                mainFrame.setCursor(cursor);
            }
        }
    };
    currentLayoutAlgorithm.addProgressListener(progressListener);
    try {
        final LayoutEntity[] layoutEntities = new LayoutEntity[entities.size()];
        entities.toArray(layoutEntities);
        final LayoutRelationship[] layoutRelationships = new LayoutRelationship[relationships.size()];
        relationships.toArray(layoutRelationships);
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                try {
                    currentLayoutAlgorithm.applyLayout(layoutEntities, layoutRelationships, 0, 0, mainPanel.getWidth(), mainPanel.getHeight(), asynchronous, continuous);
                } catch (InvalidLayoutConfiguration e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        });
        // if (!animate) {
        updateGUI();
        // }
        // reset
        currentNodeShape = DEFAULT_NODE_SHAPE;
    } catch (StackOverflowError e) {
        e.printStackTrace();
    } finally {
    }
}
Also used : ProgressListener(org.eclipse.zest.layouts.progress.ProgressListener) LayoutEntity(org.eclipse.zest.layouts.LayoutEntity) Cursor(java.awt.Cursor) ProgressEvent(org.eclipse.zest.layouts.progress.ProgressEvent) LayoutRelationship(org.eclipse.zest.layouts.LayoutRelationship) InvalidLayoutConfiguration(org.eclipse.zest.layouts.InvalidLayoutConfiguration)

Example 3 with ProgressEvent

use of org.eclipse.zest.layouts.progress.ProgressEvent in project archi by archimatetool.

the class AbstractLayoutAlgorithm method fireProgressStarted.

protected void fireProgressStarted(int totalNumberOfSteps) {
    ProgressEvent event = new ProgressEvent(0, totalNumberOfSteps);
    for (int i = 0; i < progressListeners.size(); i++) {
        ProgressListener listener = (ProgressListener) progressListeners.get(i);
        listener.progressStarted(event);
    }
}
Also used : ProgressListener(org.eclipse.zest.layouts.progress.ProgressListener) ProgressEvent(org.eclipse.zest.layouts.progress.ProgressEvent) BasicEntityConstraint(org.eclipse.zest.layouts.constraints.BasicEntityConstraint) BendPoint(org.eclipse.zest.layouts.dataStructures.BendPoint) DisplayIndependentPoint(org.eclipse.zest.layouts.dataStructures.DisplayIndependentPoint)

Example 4 with ProgressEvent

use of org.eclipse.zest.layouts.progress.ProgressEvent in project archi by archimatetool.

the class AbstractLayoutAlgorithm method fireProgressEnded.

protected void fireProgressEnded(int totalNumberOfSteps) {
    ProgressEvent event = new ProgressEvent(totalNumberOfSteps, totalNumberOfSteps);
    for (int i = 0; i < progressListeners.size(); i++) {
        ProgressListener listener = (ProgressListener) progressListeners.get(i);
        listener.progressEnded(event);
    }
}
Also used : ProgressListener(org.eclipse.zest.layouts.progress.ProgressListener) ProgressEvent(org.eclipse.zest.layouts.progress.ProgressEvent) BasicEntityConstraint(org.eclipse.zest.layouts.constraints.BasicEntityConstraint) BendPoint(org.eclipse.zest.layouts.dataStructures.BendPoint) DisplayIndependentPoint(org.eclipse.zest.layouts.dataStructures.DisplayIndependentPoint)

Example 5 with ProgressEvent

use of org.eclipse.zest.layouts.progress.ProgressEvent in project archi by archimatetool.

the class AbstractLayoutAlgorithm method fireProgressEvent.

/**
 * Fires an event to notify all of the registered ProgressListeners that another step
 * has been completed in the algorithm.
 * @param currentStep The current step completed.
 * @param totalNumberOfSteps The total number of steps in the algorithm.
 */
protected void fireProgressEvent(int currentStep, int totalNumberOfSteps) {
    // Update the layout locations to the external nodes
    Calendar now = Calendar.getInstance();
    now.add(Calendar.MILLISECOND, -MIN_TIME_DELAY_BETWEEN_PROGRESS_EVENTS);
    if (now.after(lastProgressEventFired) || currentStep == totalNumberOfSteps) {
        ProgressEvent event = new ProgressEvent(currentStep, totalNumberOfSteps);
        for (int i = 0; i < progressListeners.size(); i++) {
            ProgressListener listener = (ProgressListener) progressListeners.get(i);
            listener.progressUpdated(event);
        }
        lastProgressEventFired = Calendar.getInstance();
    }
}
Also used : ProgressListener(org.eclipse.zest.layouts.progress.ProgressListener) Calendar(java.util.Calendar) ProgressEvent(org.eclipse.zest.layouts.progress.ProgressEvent) BasicEntityConstraint(org.eclipse.zest.layouts.constraints.BasicEntityConstraint) BendPoint(org.eclipse.zest.layouts.dataStructures.BendPoint) DisplayIndependentPoint(org.eclipse.zest.layouts.dataStructures.DisplayIndependentPoint)

Aggregations

ProgressEvent (org.eclipse.zest.layouts.progress.ProgressEvent)5 ProgressListener (org.eclipse.zest.layouts.progress.ProgressListener)5 BasicEntityConstraint (org.eclipse.zest.layouts.constraints.BasicEntityConstraint)3 BendPoint (org.eclipse.zest.layouts.dataStructures.BendPoint)3 DisplayIndependentPoint (org.eclipse.zest.layouts.dataStructures.DisplayIndependentPoint)3 InvalidLayoutConfiguration (org.eclipse.zest.layouts.InvalidLayoutConfiguration)2 LayoutEntity (org.eclipse.zest.layouts.LayoutEntity)2 LayoutRelationship (org.eclipse.zest.layouts.LayoutRelationship)2 Cursor (java.awt.Cursor)1 Calendar (java.util.Calendar)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 Point (org.eclipse.swt.graphics.Point)1 LayoutBendPoint (org.eclipse.zest.layouts.LayoutBendPoint)1