当前位置: 首页>>代码示例>>Java>>正文


Java RunnableWithResult类代码示例

本文整理汇总了Java中org.eclipse.emf.transaction.RunnableWithResult的典型用法代码示例。如果您正苦于以下问题:Java RunnableWithResult类的具体用法?Java RunnableWithResult怎么用?Java RunnableWithResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


RunnableWithResult类属于org.eclipse.emf.transaction包,在下文中一共展示了RunnableWithResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeExternal

import org.eclipse.emf.transaction.RunnableWithResult; //导入依赖的package包/类
public static void writeExternal(final ObjectOutput out, final EPlanElement eObject) throws IOException {
	IOException result = TransactionUtils.reading(eObject, new RunnableWithResult.Impl<IOException>() {
		@Override
		public void run() {
			try {
				out.writeObject(eObject);
			} catch (IOException e) {
				Logger.getLogger(WrapperUtils.class).error("writeExternal", e);
				setResult(e);
			}
		}
	});
	if (result != null) {
		throw result;
	}
}
 
开发者ID:nasa,项目名称:OpenSPIFe,代码行数:17,代码来源:WrapperUtils.java

示例2: initialize

import org.eclipse.emf.transaction.RunnableWithResult; //导入依赖的package包/类
@Override
protected List<? extends Violation> initialize() {
	return TransactionUtils.reading(plan, new RunnableWithResult.Impl<List<? extends Violation>>() {
		@Override
		public void run() {
			if (isQuit()) {
				return;
			}
			final List<EPlanElement> affectedElements = new ArrayList<EPlanElement>();
			new PlanVisitor() {
				@Override
				protected void visit(EPlanElement element) {
				    affectedElements.add(element);
				}
			}.visitAll(plan);
			List<Violation> violations = findViolations(affectedElements);
			setResult(violations);
		}
	});
}
 
开发者ID:nasa,项目名称:OpenSPIFe,代码行数:21,代码来源:ConstraintsPlanAdvisor.java

示例3: writing

import org.eclipse.emf.transaction.RunnableWithResult; //导入依赖的package包/类
public static <T extends Throwable> void writing(final Object object, final Class<T> throwableClass, final RunnableWithThrowable runnable) throws T {
	final Option<T> exception = TransactionUtils.writing(object, new RunnableWithResult.Impl<Option<T>>() {
		@Override
		public void run() {
			try {
				runnable.run();
				setResult(Option.<T> none());
			} catch (Throwable throwable) {
				if (throwableClass.isAssignableFrom(throwable.getClass())) {
					setResult(some((T) throwable));
					return;
				}
				if (throwable instanceof RuntimeException)
					throw (RuntimeException) throwable;
				if (throwable instanceof Error)
					throw (Error) throwable;
				throw new RuntimeException(throwable);
			}
		}
	});
	if (exception.isSome())
		throw exception.some();
}
 
开发者ID:nasa,项目名称:OpenSPIFe,代码行数:24,代码来源:TransactionUtils.java

示例4: getString

import org.eclipse.emf.transaction.RunnableWithResult; //导入依赖的package包/类
public static String getString(EPlanElement element) {
	if (element instanceof EPlanChild) {
		final EPlanChild child = (EPlanChild) element;
		if (child.getParent() == null) {
			return TransactionUtils.writing(DUMMY_PLAN, new RunnableWithResult.Impl<String>() {
				public void run() {
					EList<EPlanChild> children = DUMMY_PLAN.getChildren();
					children.add(child);
					setResult(EMFUtils.convertToXML(child, OPTIONS));
					children.remove(child);
				}
			});
		}
	}
	return EMFUtils.convertToXML(element, OPTIONS);
}
 
开发者ID:nasa,项目名称:OpenSPIFe,代码行数:17,代码来源:PlanElementXMLUtils.java

示例5: unloadModelResource

import org.eclipse.emf.transaction.RunnableWithResult; //导入依赖的package包/类
private void unloadModelResource(final IFile file){

		logger.info("Alternative '"+ getName() +"' is unloading model resource: " + file.getFullPath().toString());

		try {
			TransactionUtil.runExclusive(editingDomain, new RunnableWithResult.Impl<Resource>(){

				@Override
				public void run() {
					Resource resource = getModelResource(file);
					if(resource != null){
						resource.unload();
						resSet.getResources().remove(resource);
					}
				}
			});
		} 
		catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
 
开发者ID:CloudScale-Project,项目名称:Environment,代码行数:22,代码来源:EditorInputEMF.java

示例6: loadExternalModel

import org.eclipse.emf.transaction.RunnableWithResult; //导入依赖的package包/类
/**
 * Loads the EMF resource under specified file into the editing domain.
 * 
 * @param file
 * @return EMF Resource
 */
public Resource loadExternalModel(final IFile file){
	
	Resource resource = null;
	
	try {
		resource = TransactionUtil.runExclusive(editingDomain, new RunnableWithResult.Impl<Resource>(){
			
			@Override
			public void run() {
				
				Resource res = getModelResource(file);
				if(res == null){
					res = loadModelResource(file);
				}
				setResult(res);
				
			}
		});
	} catch (InterruptedException e) {
		e.printStackTrace();
	}
	
	return resource;
}
 
开发者ID:CloudScale-Project,项目名称:Environment,代码行数:31,代码来源:EditorInputEMF.java

示例7: getEditTextValidator

import org.eclipse.emf.transaction.RunnableWithResult; //导入依赖的package包/类
/**
 * @generated
 */
public ICellEditorValidator getEditTextValidator() {
	return new ICellEditorValidator() {

		public String isValid(final Object value) {
			if (value instanceof String) {
				final EObject element = getParserElement();
				final IParser parser = getParser();
				try {
					IParserEditStatus valid = (IParserEditStatus) getEditingDomain()
							.runExclusive(
									new RunnableWithResult.Impl<IParserEditStatus>() {

										public void run() {
											setResult(parser
													.isValidEditString(
															new EObjectAdapter(
																	element),
															(String) value));
										}
									});
					return valid.getCode() == ParserEditStatus.EDITABLE ? null
							: valid.getMessage();
				} catch (InterruptedException ie) {
					ie.printStackTrace();
				}
			}

			// shouldn't get here
			return null;
		}
	};
}
 
开发者ID:spoenemann,项目名称:xtext-gef,代码行数:36,代码来源:StateNameEditPart.java

示例8: testLocalVariable

import org.eclipse.emf.transaction.RunnableWithResult; //导入依赖的package包/类
public void testLocalVariable() throws Exception {
	load(URI.createURI("platform:/plugin/gov.nasa.ensemble.core.plan.resources/datafiles/test/TestLocalVariable.dictionary"));
	
	EActivityDef activityDef = getActivityDef("LocalVariableTest");
	
	final EActivity activity = PLAN_FACTORY.createActivity(activityDef);
	plan = createPlan(activity);
	
	assertEquals(Integer.valueOf(0), ADParameterUtils.getParameterObject(activity, "baseParameter"));
	
	ResourceUpdater.recompute(plan);
	
	assertEquals(Integer.valueOf(10), ADParameterUtils.getParameterObject(activity, "variableParameter"));

	Exception exception = TransactionUtils.writing(activity, new RunnableWithResult.Impl<Exception>() {
		@Override
		public void run() {
			try {
                ADParameterUtils.setParameterObject(activity, "baseParameter", 10);
               } catch (UndefinedParameterException e) {
               	setResult(e);
               }
		}
	});
	if (exception != null) {
		throw exception;
	}
	
	ResourceUpdater.recompute(plan);
	
	assertEquals(Integer.valueOf(20), ADParameterUtils.getParameterObject(activity, "variableParameter"));
}
 
开发者ID:nasa,项目名称:OpenSPIFe,代码行数:33,代码来源:TestLocalVariable.java

示例9: createPlan

import org.eclipse.emf.transaction.RunnableWithResult; //导入依赖的package包/类
public static EPlan createPlan() {
	// clear the activity dictionary of previous definitions
	final ActivityDictionary adict = ActivityDictionary.getInstance();
	adict.clearCache();
	
	// create some activity definitions
	EActivityDef actDef1 = createActivityDef(0, "actDef1", "group 1");
	EActivityDef actDef2 = createActivityDef(1, "actDef2", "group 2");
	EActivityDef actDef3 = createActivityDef(3, "actDef3", "group 1");
	
	adict.addDefinition(actDef1);
	adict.addDefinition(actDef2);
	adict.addDefinition(actDef3);
	
	// hack to re-initialize any members that may have cached a previous version of the AD
	adict.fireActivityDictionaryLoadedEvent();
	
	final EPlan plan = PlanFactory.getInstance().createPlan(TestPlanUtils.TEST_PLAN_NAME);
	Exception exception = TransactionUtils.writing(plan, new RunnableWithResult.Impl<Exception>() {
		@Override
		public void run() {
			try {
                constructPlan(adict, plan);
               } catch (Exception e) {
                setResult(e);
               }
		}
	});
	if (exception != null) {
		throw new RuntimeException("exception in constructPlan: ", exception);
	}

	trace.debug("createPlan: After multiArgActivity");
	return plan;
}
 
开发者ID:nasa,项目名称:OpenSPIFe,代码行数:36,代码来源:TestPlanUtils.java

示例10: createActivityGroup

import org.eclipse.emf.transaction.RunnableWithResult; //导入依赖的package包/类
/**
 * Creates an {@link EActivityGroup} within the given parent.
 */
public EActivityGroup createActivityGroup(final EPlanParent parent) {
	String nameOfPlan = "Unnamed";
	if (parent != null) {
		nameOfPlan = TransactionUtils.reading(parent, new RunnableWithResult.Impl<String>() {
			@Override
			public void run() {
				setResult(createName(parent, EPlanUtils.getActivityGroupDisplayName()));
			}
		});
	}
	final String name = nameOfPlan; 
	final EActivityGroup group = createActivityGroupInstance();
	TransactionUtils.writeIfNecessary(group, new Runnable() {
		@Override
		public void run() {
			group.setData(ADParameterMemberFactory.FACTORY.createData(PlanPackage.Literals.EACTIVITY_GROUP));
			group.setName(name);
			TemporalMember temporalMember = group.getMember(TemporalMember.class);
			temporalMember.setUseChildTimes(true);
			CommonMember commonMember = group.getMember(CommonMember.class);
			commonMember.setNotes("");
			RGB randomColor = ColorUtils.getRandomColor();
			commonMember.setColor(ColorUtils.getAsERGB(randomColor));
		}
	});
	return group;
}
 
开发者ID:nasa,项目名称:OpenSPIFe,代码行数:31,代码来源:PlanFactory.java

示例11: check

import org.eclipse.emf.transaction.RunnableWithResult; //导入依赖的package包/类
@Override
protected List<? extends Violation> check(final List<Notification> notifications) {
	return TransactionUtils.reading(plan, new RunnableWithResult.Impl<List<? extends Violation>>() {
		@Override
		public void run() {
			Set<EPlanElement> affectedElements = getAffectedElements(notifications);
			List<Violation> violations = findViolations(affectedElements);
			setResult(violations);
		}
	});
}
 
开发者ID:nasa,项目名称:OpenSPIFe,代码行数:12,代码来源:ConstraintsPlanAdvisor.java

示例12: displayRunnable

import org.eclipse.emf.transaction.RunnableWithResult; //导入依赖的package包/类
private Runnable displayRunnable(final Control control, final Runnable runnable) {
	return new Runnable() {
		@Override
		public void run() {
			if (control.isDisposed()) {
				return;
			}
			Display display = control.getDisplay();
			if (display.isDisposed()) {
				return;
			}
			final RunnableWithResult<?> privilegedRunnable = domain.createPrivilegedRunnable(runnable);
			display.syncExec(new Runnable() {
				@Override
				public void run() {
					if (!control.isDisposed()) {
						privilegedRunnable.run();
					}
				}
			});
		}
		@Override
		public String toString() {
			return runnable.toString();
		}
	};
}
 
开发者ID:nasa,项目名称:OpenSPIFe,代码行数:28,代码来源:TransactionDisplayThread.java

示例13: reading

import org.eclipse.emf.transaction.RunnableWithResult; //导入依赖的package包/类
public static void reading(Object object, final Runnable runnable) {
	reading(object, new RunnableWithResult.Impl<Object>() {
		@Override
		public void run() {
			runnable.run();
		}

		@Override
		public String toString() {
			return runnable.toString();
		}
	});
}
 
开发者ID:nasa,项目名称:OpenSPIFe,代码行数:14,代码来源:TransactionUtils.java

示例14: checkedWriting

import org.eclipse.emf.transaction.RunnableWithResult; //导入依赖的package包/类
public static <T> T checkedWriting(Object object, final RunnableWithResult<T> runnable, Map<Object, Object> options) throws InterruptedException, RollbackException {

		final EditingDomain domain = EMFUtils.getAnyDomain(object);
		if (domain instanceof TransactionalEditingDomain) {
			TransactionalEditingDomain transactionDomain = (TransactionalEditingDomain) domain;
			checkForDeadlock(transactionDomain);
			InternalTransaction transaction = ((TransactionalEditingDomainImpl) transactionDomain).getActiveTransaction();
			if ((transaction != null) && (transaction.getOwner() == Thread.currentThread()) && !transaction.isReadOnly()) {
				// nested writing
				runnable.run();
				return runnable.getResult();
			}
			TransactionalCommandStack stack = (TransactionalCommandStack) domain.getCommandStack();
			if (stack != null) {
				Map writingOptions = getWritingOptions(domain);
				Map newOptions = new HashMap();
				if (options != null) {
					newOptions.putAll(options);
				}
				if (writingOptions != null) {
					newOptions.putAll(writingOptions);
				}
				writingOptions = newOptions;
				stack.execute(new RunnableRecordingCommand("writing", runnable), writingOptions);
			} else {
				runnable.run();
			}
		} else {
			runnable.run();
		}
		return runnable.getResult();
	}
 
开发者ID:nasa,项目名称:OpenSPIFe,代码行数:33,代码来源:TransactionUtils.java

示例15: getReachableObjectsOfType

import org.eclipse.emf.transaction.RunnableWithResult; //导入依赖的package包/类
public static Collection<EObject> getReachableObjectsOfType(final EObject object, final EClassifier type) {
	if (object == null) {
		return Collections.emptyList();
	}
	Resource resource = object.eResource();
	if (resource != null) {
		ResourceSet resourceSet = resource.getResourceSet();
		if (resourceSet != null) {
			Map<EClassifier, Collection<EObject>> cache = TYPES_BY_RESOURCE_SET_CACHE.get(resourceSet);
			if (cache == null) {
				cache = new HashMap<EClassifier, Collection<EObject>>();
				TYPES_BY_RESOURCE_SET_CACHE.put(resourceSet, cache);
			}
			Collection<EObject> collection = cache.get(type);
			if (collection == null) {
				TransactionalEditingDomain domain = TransactionUtils.getDomain(resourceSet);
				if (domain != null) {
					collection = TransactionUtils.reading(domain, new RunnableWithResult.Impl<Collection<EObject>>() {
						@Override
						public void run() {
							try {
								setResult(ItemPropertyDescriptor.getReachableObjectsOfType(object, type));
								setStatus(Status.OK_STATUS);
							} catch (Exception e) {
								setStatus(new ExceptionStatus(Activator.PLUGIN_ID, "failed in reading", e));
							}
						}
					});
				} else {
					collection = ItemPropertyDescriptor.getReachableObjectsOfType(object, type);
				}
				cache.put(type, collection);
			}
			return collection;
		}
	}
	return ItemPropertyDescriptor.getReachableObjectsOfType(object, type);
}
 
开发者ID:nasa,项目名称:OpenSPIFe,代码行数:39,代码来源:EMFUtils.java


注:本文中的org.eclipse.emf.transaction.RunnableWithResult类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。