Skip to content

Commit

Permalink
Replace 'SubProgressmonitor' with 'SubMonitor' in 'udig.tool' (#567)
Browse files Browse the repository at this point in the history
* Replace 'SubProgressmonitor' with 'SubMonitor' in 'udig.tool'
  • Loading branch information
sschulz92 authored Nov 1, 2021
1 parent 27ae9df commit 9f34503
Show file tree
Hide file tree
Showing 13 changed files with 739 additions and 603 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* uDig - User Friendly Desktop Internet GIS client
/**
* uDig - User Friendly Desktop Internet GIS client
* http://udig.refractions.net
* (C) 2004, Refractions Research Inc.
*
Expand All @@ -12,73 +13,76 @@
import java.util.LinkedList;
import java.util.List;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubMonitor;
import org.locationtech.udig.project.command.AbstractCommand;
import org.locationtech.udig.project.command.PostDeterminedEffectCommand;
import org.locationtech.udig.project.command.UndoableMapCommand;
import org.locationtech.udig.tool.edit.internal.Messages;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;

/**
* Command used by (@link org.locationtech.udig.tools.edit.EditToolHandler} and
* {@link org.locationtech.udig.tools.edit.OrderedCompositeEventBehavior} for executing the
* Command used by (@link org.locationtech.udig.tools.edit.EditToolHandler} and
* {@link org.locationtech.udig.tools.edit.OrderedCompositeEventBehavior} for executing the
* behaviours in a tool.
*
*
* @author jones
* @since 1.1.0
*/
public class BehaviourCommand extends AbstractCommand implements PostDeterminedEffectCommand {

private List<Behaviour> behaviours;
private List<UndoableMapCommand> commandsRan=new LinkedList<UndoableMapCommand>();

private List<UndoableMapCommand> commandsRan = new LinkedList<>();

private EditToolHandler handler;

public BehaviourCommand(List<Behaviour> behaviours, EditToolHandler handler) {
this.behaviours=behaviours;
this.handler=handler;
this.behaviours = behaviours;
this.handler = handler;
}

public boolean execute( IProgressMonitor monitor ) throws Exception {
if( commandsRan.isEmpty() ){
monitor.beginTask(getName(), commandsRan.size()*12);

@Override
public boolean execute(IProgressMonitor monitor) throws Exception {
if (commandsRan.isEmpty()) {
monitor.beginTask(getName(), commandsRan.size() * 12);
monitor.worked(2);
for( Behaviour behaviour : behaviours ) {
monitor.beginTask(getName(), behaviours.size()*12);
for (Behaviour behaviour : behaviours) {
monitor.beginTask(getName(), behaviours.size() * 12);
monitor.worked(2);
if( behaviour.isValid(handler)){
UndoableMapCommand c=null;
try{
c=behaviour.getCommand(handler);
if( c==null )
if (behaviour.isValid(handler)) {
UndoableMapCommand c = null;
try {
c = behaviour.getCommand(handler);
if (c == null)
continue;
c.setMap(getMap());
IProgressMonitor submonitor = new SubProgressMonitor(monitor, 10);
IProgressMonitor submonitor = SubMonitor.convert(monitor, 10);
if (c instanceof PostDeterminedEffectCommand) {
PostDeterminedEffectCommand command = (PostDeterminedEffectCommand) c;
if( command.execute(submonitor) )
if (command.execute(submonitor))
commandsRan.add(command);
}else{
c.run(submonitor);
commandsRan.add(c);
} else {
c.run(submonitor);
commandsRan.add(c);
}
submonitor.done();
}catch(Exception e){
EditPlugin.trace( e.getClass().getName()+" executing "+c+":"+e.getMessage(), e);
} catch (Exception e) {
EditPlugin.trace(
e.getClass().getName() + " executing " + c + ":" + e.getMessage(), //$NON-NLS-1$ //$NON-NLS-2$
e);
behaviour.handleError(handler, e, c);
}
}
}
}else{
monitor.beginTask(getName(), commandsRan.size()*12);
} else {
monitor.beginTask(getName(), commandsRan.size() * 12);
monitor.worked(2);
for( UndoableMapCommand command : commandsRan ) {
for (UndoableMapCommand command : commandsRan) {
command.setMap(getMap());
IProgressMonitor submonitor = new SubProgressMonitor(monitor, 10);
IProgressMonitor submonitor = SubMonitor.convert(monitor, 10);
if (command instanceof PostDeterminedEffectCommand) {
((PostDeterminedEffectCommand)command).execute(submonitor);
}else{
((PostDeterminedEffectCommand) command).execute(submonitor);
} else {
command.run(submonitor);
}
submonitor.done();
Expand All @@ -87,32 +91,34 @@ public boolean execute( IProgressMonitor monitor ) throws Exception {
return !commandsRan.isEmpty();
}

String name=Messages.EventBehaviourCommand_name;
String name = Messages.EventBehaviourCommand_name;

@Override
public String getName() {
return name;
}
public void setName( String name ) {

public void setName(String name) {
this.name = name;
}

public void rollback( IProgressMonitor monitor ) throws Exception {
monitor.beginTask(getName(), commandsRan.size()*12);
@Override
public void rollback(IProgressMonitor monitor) throws Exception {
monitor.beginTask(getName(), commandsRan.size() * 12);
monitor.worked(2);
for(int i = commandsRan.size()-1; i>=0; i--)
{
for (int i = commandsRan.size() - 1; i >= 0; i--) {
UndoableMapCommand command = commandsRan.get(i);
command.setMap(getMap());
IProgressMonitor submonitor = new SubProgressMonitor(monitor, 10);
IProgressMonitor submonitor = SubMonitor.convert(monitor, 10);
command.rollback(submonitor);
submonitor.done();
}
}


public void run( IProgressMonitor monitor ) throws Exception {
throw new UnsupportedOperationException("PostDeterminedEffectCommands do not use the run method"); //$NON-NLS-1$
@Override
public void run(IProgressMonitor monitor) throws Exception {
throw new UnsupportedOperationException(
"PostDeterminedEffectCommands do not use the run method"); //$NON-NLS-1$
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* uDig - User Friendly Desktop Internet GIS client
/**
* uDig - User Friendly Desktop Internet GIS client
* http://udig.refractions.net
* (C) 2004, Refractions Research Inc.
*
Expand All @@ -12,76 +13,80 @@
import java.util.LinkedList;
import java.util.List;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubMonitor;
import org.locationtech.udig.project.command.AbstractCommand;
import org.locationtech.udig.project.command.PostDeterminedEffectCommand;
import org.locationtech.udig.project.command.UndoableMapCommand;
import org.locationtech.udig.project.ui.render.displayAdapter.MapMouseEvent;
import org.locationtech.udig.tool.edit.internal.Messages;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;

/**
* Command used by (@link org.locationtech.udig.tools.edit.EditToolHandler} and
* {@link org.locationtech.udig.tools.edit.OrderedCompositeEventBehavior} for executing the
* Command used by (@link org.locationtech.udig.tools.edit.EditToolHandler} and
* {@link org.locationtech.udig.tools.edit.OrderedCompositeEventBehavior} for executing the
* behaviours in a tool.
*
*
* @author jones
* @since 1.1.0
*/
public class EventBehaviourCommand extends AbstractCommand implements PostDeterminedEffectCommand {

private List<EventBehaviour> behaviours;
private List<UndoableMapCommand> commandsRan=new LinkedList<UndoableMapCommand>();

private List<UndoableMapCommand> commandsRan = new LinkedList<>();

private EditToolHandler handler;

private MapMouseEvent event;

private EventType eventType;

public EventBehaviourCommand(List<EventBehaviour> behaviours, EditToolHandler handler,
MapMouseEvent event, EventType eventType) {
this.behaviours=behaviours;
this.handler=handler;
this.event=event;
this.eventType=eventType;
this.behaviours = behaviours;
this.handler = handler;
this.event = event;
this.eventType = eventType;
}

public boolean execute( IProgressMonitor monitor ) throws Exception {
if( commandsRan.isEmpty() ){
monitor.beginTask(getName(), commandsRan.size()*12);

@Override
public boolean execute(IProgressMonitor monitor) throws Exception {
if (commandsRan.isEmpty()) {
monitor.beginTask(getName(), commandsRan.size() * 12);
monitor.worked(2);
for( EventBehaviour behaviour : behaviours ) {
for (EventBehaviour behaviour : behaviours) {

if( canUnlock(behaviour) && behaviour.isValid(handler, event, eventType)){
UndoableMapCommand c=null;
try{
c=behaviour.getCommand(handler, event, eventType);
if( c==null )
if (canUnlock(behaviour) && behaviour.isValid(handler, event, eventType)) {
UndoableMapCommand c = null;
try {
c = behaviour.getCommand(handler, event, eventType);
if (c == null)
continue;
IProgressMonitor submonitor = new SubProgressMonitor(monitor, 10);
IProgressMonitor submonitor = SubMonitor.convert(monitor, 10);
c.setMap(getMap());
if (c instanceof PostDeterminedEffectCommand) {
PostDeterminedEffectCommand command = (PostDeterminedEffectCommand) c;
if( command.execute(submonitor) )
if (command.execute(submonitor))
commandsRan.add(command);
}else{
c.run(submonitor);
commandsRan.add(c);
} else {
c.run(submonitor);
commandsRan.add(c);
}
submonitor.done();
}catch(Exception e){
} catch (Exception e) {
behaviour.handleError(handler, e, c);
}
}
}
}else{
monitor.beginTask(getName(), commandsRan.size()*12);
} else {
monitor.beginTask(getName(), commandsRan.size() * 12);
monitor.worked(2);
for( UndoableMapCommand command : commandsRan ) {
for (UndoableMapCommand command : commandsRan) {
command.setMap(getMap());
IProgressMonitor submonitor = new SubProgressMonitor(monitor, 10);
IProgressMonitor submonitor = SubMonitor.convert(monitor, 10);
if (command instanceof PostDeterminedEffectCommand) {
((PostDeterminedEffectCommand)command).execute(submonitor);
}else{
((PostDeterminedEffectCommand) command).execute(submonitor);
} else {
command.run(submonitor);
}
submonitor.done();
Expand All @@ -93,44 +98,49 @@ public boolean execute( IProgressMonitor monitor ) throws Exception {

/**
* Returns true if the handler is unlocked or the behaviour has the correct key.
*
*
* @param behaviour trying to run
* @return Returns true if the handler is unlocked or the behaviour has the correct key.
*/
private boolean canUnlock( EventBehaviour behaviour ) {
if( !handler.isLocked() )
private boolean canUnlock(EventBehaviour behaviour) {
if (!handler.isLocked())
return true;
if (behaviour instanceof LockingBehaviour) {
LockingBehaviour locker = (LockingBehaviour) behaviour;

EditPlugin.trace(EditPlugin.HANDLER_LOCK, "Can unlock: "+(handler.behaviourLock==locker.getKey(handler)), null); //$NON-NLS-1$
return handler.behaviourLock==locker.getKey(handler);
EditPlugin.trace(EditPlugin.HANDLER_LOCK,
"Can unlock: " + (handler.behaviourLock == locker.getKey(handler)), null); //$NON-NLS-1$
return handler.behaviourLock == locker.getKey(handler);
}
return false;
}

String name=Messages.EventBehaviourCommand_name;
String name = Messages.EventBehaviourCommand_name;

@Override
public String getName() {
return name;
}
public void setName( String name ) {

public void setName(String name) {
this.name = name;
}

public void rollback( IProgressMonitor monitor ) throws Exception {
monitor.beginTask(getName(), commandsRan.size()*12);
@Override
public void rollback(IProgressMonitor monitor) throws Exception {
monitor.beginTask(getName(), commandsRan.size() * 12);
monitor.worked(2);
for( UndoableMapCommand command : commandsRan ) {
for (UndoableMapCommand command : commandsRan) {
command.setMap(getMap());
IProgressMonitor submonitor = new SubProgressMonitor(monitor, 10);
IProgressMonitor submonitor = SubMonitor.convert(monitor, 10);
command.rollback(submonitor);
submonitor.done();
}
}

public void run( IProgressMonitor monitor ) throws Exception {
throw new UnsupportedOperationException("PostDeterminedEffectCommands do not use the run method"); //$NON-NLS-1$
@Override
public void run(IProgressMonitor monitor) throws Exception {
throw new UnsupportedOperationException(
"PostDeterminedEffectCommands do not use the run method"); //$NON-NLS-1$
}
}
Loading

0 comments on commit 9f34503

Please sign in to comment.