diff options
Diffstat (limited to 'rba.tool.editor.ui/src/rba/tool/editor/ui/util')
4 files changed, 152 insertions, 0 deletions
diff --git a/rba.tool.editor.ui/src/rba/tool/editor/ui/util/CharacterUtil.xtend b/rba.tool.editor.ui/src/rba/tool/editor/ui/util/CharacterUtil.xtend new file mode 100644 index 0000000..28cbe08 --- /dev/null +++ b/rba.tool.editor.ui/src/rba/tool/editor/ui/util/CharacterUtil.xtend @@ -0,0 +1,10 @@ +package rba.tool.editor.ui.util + +import org.eclipse.xtext.Keyword + +class CharacterUtil { + + def public static boolean isKeywordWorthyToPropose(Keyword keyword) { + return keyword.getValue().length() > 1 && Character.isLetter(keyword.getValue().charAt(0)); + } +} diff --git a/rba.tool.editor.ui/src/rba/tool/editor/ui/util/UnitOfProgressUtil.java b/rba.tool.editor.ui/src/rba/tool/editor/ui/util/UnitOfProgressUtil.java new file mode 100644 index 0000000..3fd41b2 --- /dev/null +++ b/rba.tool.editor.ui/src/rba/tool/editor/ui/util/UnitOfProgressUtil.java @@ -0,0 +1,84 @@ +package rba.tool.editor.ui.util; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; + +import rba.tool.editor.ui.editor.model.manager.ResourceManagerUI; +import rba.tool.editor.ui.util.concurrent.IUnitOfProgress; + +public class UnitOfProgressUtil { + + public static void doProjectSwitchProgress(final IProject project, final boolean showConfirmDialog) throws Exception { + IUnitOfProgress.Void<IProject> progress = new IUnitOfProgress.Void<IProject>() { + @Override + public void process(IProject state) throws Exception { + Job projectSwitchJob = new Job("[RBA Tool]- Switch Project") { + @Override + protected IStatus run(IProgressMonitor monitor) { + monitor.beginTask("Switch Project...", 1); //$NON-NLS-1$ + try { + ResourceManagerUI.INSTANCE.switchToProject(state, monitor); + } catch (Exception e) { + e.printStackTrace(); + return Status.CANCEL_STATUS; + } finally { + monitor.done(); + } + return Status.OK_STATUS; + } + + @Override + public boolean belongsTo(Object family) { + return IUnitOfProgress.FAMILY_UNIT_OF_PROGRESS == family; + } + }; + projectSwitchJob.schedule(); + } + }; + + if (ResourceManagerUI.INSTANCE.doConfirm(project, showConfirmDialog)) { + progress.exec(project); + } + } + + public static void doProjectSwitchProgressWithRunnable(final IProject project, final boolean showConfirmDialog, final Runnable run) throws Exception { + IUnitOfProgress.Void<IProject> progress = new IUnitOfProgress.Void<IProject>() { + @Override + public void process(IProject state) throws Exception { + Job projectSwitchJob = new Job("[RBA Tool]- Switch Project") { + @Override + protected IStatus run(IProgressMonitor monitor) { + monitor.beginTask("Switch Project...", 1); //$NON-NLS-1$ + try { + ResourceManagerUI.INSTANCE.switchToProject(state, monitor); + if (monitor.isCanceled()) { + throw new InterruptedException(); + } + run.run(); + } catch (Exception e) { + e.printStackTrace(); + return Status.CANCEL_STATUS; + } finally { + monitor.done(); + } + return Status.OK_STATUS; + } + + @Override + public boolean belongsTo(Object family) { + return IUnitOfProgress.FAMILY_UNIT_OF_PROGRESS == family; + } + }; + projectSwitchJob.schedule(); + } + }; + + if (ResourceManagerUI.INSTANCE.doConfirm(project, showConfirmDialog)) { + progress.exec(project); + } + } + +} diff --git a/rba.tool.editor.ui/src/rba/tool/editor/ui/util/concurrent/AbstractSwitchProjectProgress.java b/rba.tool.editor.ui/src/rba/tool/editor/ui/util/concurrent/AbstractSwitchProjectProgress.java new file mode 100644 index 0000000..2d640d3 --- /dev/null +++ b/rba.tool.editor.ui/src/rba/tool/editor/ui/util/concurrent/AbstractSwitchProjectProgress.java @@ -0,0 +1,40 @@ +package rba.tool.editor.ui.util.concurrent; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.SubMonitor; + +import rba.tool.editor.ui.editor.model.manager.ResourceManagerUI; + +public abstract class AbstractSwitchProjectProgress<R, P> implements IUnitOfProgress<Object, IProject> { + + private final boolean showConfirmDialog; + + public AbstractSwitchProjectProgress() { + this(true); + } + + public AbstractSwitchProjectProgress(boolean showConfirmDialog) { + this.showConfirmDialog = showConfirmDialog; + } + + @Override + public R exec(IProject state) throws Exception { + SubMonitor progress = SubMonitor.convert(null, 6); + if (!ResourceManagerUI.INSTANCE.isCurrentProject(state)) { + if (ResourceManagerUI.INSTANCE.doConfirm(state, showConfirmDialog)) { + ResourceManagerUI.INSTANCE.switchToProject(state, progress.newChild(2)); + + if (progress.isCanceled()) { + throw new InterruptedException(); + } + return internalExec(state, progress.newChild(4)); + } else { + throw new InterruptedException(); + } + } + return internalExec(state, progress.newChild(4)); + } + + protected abstract R internalExec(IProject state, IProgressMonitor monitor); +} diff --git a/rba.tool.editor.ui/src/rba/tool/editor/ui/util/concurrent/IUnitOfProgress.java b/rba.tool.editor.ui/src/rba/tool/editor/ui/util/concurrent/IUnitOfProgress.java new file mode 100644 index 0000000..f7141b1 --- /dev/null +++ b/rba.tool.editor.ui/src/rba/tool/editor/ui/util/concurrent/IUnitOfProgress.java @@ -0,0 +1,18 @@ +package rba.tool.editor.ui.util.concurrent; + +public interface IUnitOfProgress<R, P> { + + public static final Object FAMILY_UNIT_OF_PROGRESS = new Object(); + + R exec(P state) throws Exception; + + public static abstract class Void<T> implements IUnitOfProgress<Object, T> { + @Override + public final Object exec(T state) throws Exception { + process(state); + return null; + } + + public abstract void process(T state) throws Exception; + } +} |