Project

General

Profile

« Previous | Next » 

Revision 42c4238c

Added by Cherian Mathew over 7 years ago

#5297 Integrate remoting monitor cancel functionality in ui

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/ClassificationChooserWizardPage.java
29 29
import org.eclipse.wb.swt.ResourceManager;
30 30

  
31 31
import eu.etaxonomy.cdm.model.taxon.Classification;
32
import eu.etaxonomy.taxeditor.store.CdmStore;
32 33
import eu.etaxonomy.taxeditor.ui.dialog.selection.SelectionDialogFactory;
33 34

  
34 35
/**
......
105 106
		btnClear.setImage(ResourceManager.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/trash.gif"));
106 107
		btnClear.addListener(SWT.Selection, this);
107 108

  
108
		//report
109
		Label labelReportFile = new Label(composite, SWT.NONE);
110
        labelReportFile.setText("Report File");
109
		if(!CdmStore.getCurrentSessionManager().isRemoting()) {
110
		    //report
111
		    Label labelReportFile = new Label(composite, SWT.NONE);
112
		    labelReportFile.setText("Report File");
111 113

  
112
        fileDialogReport = new FileDialog(parent.getShell());
114
		    fileDialogReport = new FileDialog(parent.getShell());
113 115

  
114
        fileDialogReport.setFilterExtensions(new String[]{"*.*"});
116
		    fileDialogReport.setFilterExtensions(new String[]{"*.*"});
115 117

  
116
        textFileReport = new Text(composite, SWT.BORDER);
117
        textFileReport.setEditable(false);
118
        textFileReport.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
118
		    textFileReport = new Text(composite, SWT.BORDER);
119
		    textFileReport.setEditable(false);
120
		    textFileReport.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
119 121

  
120 122

  
121
        Button buttonReport = new Button(composite, SWT.PUSH);
122
        buttonReport.setText("Browse...");
123
		    Button buttonReport = new Button(composite, SWT.PUSH);
124
		    buttonReport.setText("Browse...");
123 125

  
124
        buttonReport.addSelectionListener(new SelectionAdapter(){
126
		    buttonReport.addSelectionListener(new SelectionAdapter(){
125 127

  
126
            /* (non-Javadoc)
127
             * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
128
             */
129
            @Override
130
            public void widgetSelected(SelectionEvent e) {
131
                String path = fileDialogReport.open();
132
                if(path!=null){
133
                    textFileReport.setText(path);
134
                    setPageComplete(true);
135
                }
136
            }
137

  
138
        });
128
		        /* (non-Javadoc)
129
		         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
130
		         */
131
		        @Override
132
		        public void widgetSelected(SelectionEvent e) {
133
		            String path = fileDialogReport.open();
134
		            if(path!=null){
135
		                textFileReport.setText(path);
136
		                setPageComplete(true);
137
		            }
138
		        }
139 139

  
140
		    });
141
		}
140 142
		setControl(composite);
141 143
	}
142 144

  
......
165 167
    }
166 168

  
167 169
    public URI getReportUri(){
170
        if(textFileReport == null) {
171
            return null;
172
        }
168 173
        String text = textFileReport.getText();
169 174
        if(text==null || text.isEmpty()){
170 175
            return null;
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java
34 34
import org.eclipse.core.runtime.Status;
35 35
import org.eclipse.core.runtime.SubProgressMonitor;
36 36
import org.eclipse.core.runtime.jobs.ISchedulingRule;
37
import org.eclipse.core.runtime.jobs.Job;
37 38
import org.eclipse.jface.action.IStatusLineManager;
38
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
39 39
import org.eclipse.jface.operation.IRunnableWithProgress;
40 40
import org.eclipse.jface.resource.ColorRegistry;
41 41
import org.eclipse.jface.resource.FontRegistry;
......
55 55
import org.eclipse.ui.handlers.IHandlerService;
56 56
import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
57 57
import org.eclipse.ui.part.EditorPart;
58
import org.eclipse.ui.progress.IProgressConstants;
58 59
import org.eclipse.ui.progress.IProgressService;
59 60
import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
60 61
import org.eclipse.ui.themes.ITheme;
......
430 431
                throw new IllegalStateException("Remoting progress monitor is null");
431 432
            }
432 433

  
433
            final ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(getShell());
434
            IRunnableWithProgress runnable = new IRunnableWithProgress() {
434
            Job job = new Job(label) {
435

  
435 436

  
436 437
                @Override
437
                public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
438
                    // run the monitor untilthe operation is finished
439
                    IRemotingProgressMonitor remotingMonitor = CdmStore.getProgressMonitorClientManager().pollMonitor(label, uuid, pollInterval, postOp, monitor);
438
                public IStatus run(IProgressMonitor monitor) {
439
                    // run the monitor until the operation is finished
440
                    IRemotingProgressMonitor remotingMonitor;
441
                    try {
442
                        remotingMonitor = CdmStore.getProgressMonitorClientManager().pollMonitor(label, uuid, pollInterval, postOp, monitor);
443
                    } catch (InterruptedException ie) {
444
                        return new Status(Status.ERROR, TaxeditorStorePlugin.PLUGIN_ID, "Operation Interrupted", ie);
445
                    }
440 446
                    final StringBuilder reportSb = new StringBuilder();
441 447
                    // collect reports
442 448
                    for(String report : remotingMonitor.getReports()) {
......
447 453
                            @Override
448 454
                            public void run() {
449 455
                                // display reports with possibility to save
450
                                ReportTextDialog dialog = new ReportTextDialog(progressDialog.getShell());
456
                                ReportTextDialog dialog = new ReportTextDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
451 457
                                dialog.setTitle(label + " Report");
452 458
                                dialog.setReportText(reportSb.toString());
453 459
                                dialog.open();
454 460
                            }
455 461
                        });
456 462
                    }
463
                    return Status.OK_STATUS;
464
                }
465

  
466
                @Override
467
                protected void canceling() {
468
                    CdmStore.getCurrentApplicationConfiguration().getProgressMonitorService().cancel(uuid);
457 469
                }
458 470
            };
459 471

  
460
            progressDialog.run(true, cancelable, runnable);
472
//            job.addJobChangeListener(new JobChangeAdapter() {
473
//                @Override
474
//                public void done(IJobChangeEvent event) {
475
//                    if(event.getJob().) {
476
//                        logger.warn("in jobc change listener");
477
//                    }
478
//                }
479
//            });
480

  
481
            // configure the job
482
            job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
483
            job.setUser(true);
484
            // schedule job
485
            job.schedule();
486

  
461 487
        } catch (Exception e) {
462 488
            MessagingUtils.errorDialog("Error executing operation",
463 489
                    AbstractUtility.class,
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/CdmProgressMonitorAdapter.java
1 1
/**
2
 * 
2
 *
3 3
 */
4 4
package eu.etaxonomy.taxeditor.model;
5 5

  
......
16 16
 * @version 1.0
17 17
 */
18 18
public class CdmProgressMonitorAdapter implements eu.etaxonomy.cdm.common.monitor.IProgressMonitor {
19
	
19

  
20 20
	private IProgressMonitor progressMonitor;
21 21

  
22 22
	private CdmProgressMonitorAdapter (IProgressMonitor monitor){
23 23
		if(monitor == null){
24 24
			monitor = new NullProgressMonitor();
25 25
		}
26
		
26

  
27 27
		this.progressMonitor = monitor;
28 28
	}
29
	
29

  
30 30
	/**
31 31
	 * <p>CreateMonitor</p>
32 32
	 *
......
36 36
	public static CdmProgressMonitorAdapter CreateMonitor (IProgressMonitor monitor){
37 37
		return new CdmProgressMonitorAdapter(monitor);
38 38
	}
39
	
39

  
40 40
	/**
41 41
	 * <p>CreateSubMonitor</p>
42 42
	 *
......
48 48
		IProgressMonitor subMonitor = StoreUtil.getSubProgressMonitor(monitor, ticks);
49 49
		return new CdmProgressMonitorAdapter(subMonitor);
50 50
	}
51
	
51

  
52 52
	/** {@inheritDoc} */
53 53
	@Override
54 54
	public void beginTask(String name, int totalWork) {
......
107 107
	public void internalWorked(double arg0) {
108 108
		progressMonitor.internalWorked(arg0);
109 109
	}
110

  
111
    /**
112
     * {@inheritDoc}
113
     */
114
    @Override
115
    public void waitForFeedback() {
116
        // TODO Auto-generated method stub
117

  
118
    }
110 119
}
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/service/ProgressMonitorServiceTest.java
88 88
    }
89 89

  
90 90
    @Test
91
    public void testMonitLongRunningMethodWithCancellation() throws InterruptedException {
92
        IllegalStateException ise = new IllegalStateException("Cancelled Exception");
91
    public void testMonitLongRunningMethodWithInterrupt() throws InterruptedException {
92
        IllegalStateException ise = new IllegalStateException("Interrupted Exception");
93 93
        final UUID uuid = testService.monitLongRunningMethod(ise);
94 94
        final int pollInterval = 1000;
95 95
        final RemotingProgressMonitor expectedMonitor = new RemotingProgressMonitor();
......
125 125

  
126 126
    }
127 127

  
128
    @Test
129
    public void testMonitLongRunningMethodWithCancellation() throws InterruptedException {
130

  
131
        final UUID uuid = testService.monitLongRunningMethod(null);
132
        final int pollInterval = 1000;
133
        final RemotingProgressMonitor expectedMonitor = new RemotingProgressMonitor();
134
        expectedMonitor.setResult("Cancelled");
135
        expectedMonitor.setCanceled(true);
136
        expectedMonitor.done();
137

  
138
        Thread thread = new Thread() {
139
            @Override
140
            public void run() {
141
                try {
142
                    IRemotingProgressMonitor remotingMonitor = CdmStore.getProgressMonitorClientManager().pollMonitor("Testing Progress Monitor",
143
                            uuid,
144
                            pollInterval,
145
                            null,
146
                            new NullProgressMonitor());
147
                } catch (InterruptedException e) {
148

  
149
                }
150
            }
151

  
152
        };
153
        thread.start();
154
        while(!progressMonitorService.isMonitorThreadRunning(uuid)) {}
155
        progressMonitorService.cancel(uuid);
156
        while(progressMonitorService.isMonitorThreadRunning(uuid)) {}
157
        IRemotingProgressMonitor remotingMonitor = progressMonitorService.getRemotingMonitor(uuid);
158
        new MockPostMoniteredOperationEnabled(expectedMonitor, uuid).postOperation(remotingMonitor);
159

  
160
    }
161

  
128 162

  
129 163
    class MockPostMoniteredOperationEnabled implements IPostMoniteredOperationEnabled {
130 164

  

Also available in: Unified diff