本文整理汇总了Java中org.eclipse.e4.ui.workbench.modeling.EModelService.findElements方法的典型用法代码示例。如果您正苦于以下问题:Java EModelService.findElements方法的具体用法?Java EModelService.findElements怎么用?Java EModelService.findElements使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.e4.ui.workbench.modeling.EModelService
的用法示例。
在下文中一共展示了EModelService.findElements方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.eclipse.e4.ui.workbench.modeling.EModelService; //导入方法依赖的package包/类
@Execute
public void execute(MWindow window, EPartService partService,
EModelService modelService) {
// assumes you have only two perspectives
List<MPerspective> perspectives = modelService.findElements(window,
null, MPerspective.class, null);
if (perspectives.size() != 2) {
System.out.println("works only for exactly two perspectives");
}
MPerspective activePerspective = modelService
.getActivePerspective(window);
if (activePerspective.equals(perspectives.get(0))) {
partService.switchPerspective(perspectives.get(1));
} else {
partService.switchPerspective(perspectives.get(0));
}
}
示例2: getPerspectiveStack
import org.eclipse.e4.ui.workbench.modeling.EModelService; //导入方法依赖的package包/类
private MPerspectiveStack getPerspectiveStack(){
EModelService modelService = getService(EModelService.class);
MWindow window = getActiveWindow();
List<MPerspectiveStack> theStack =
modelService.findElements(window, null, MPerspectiveStack.class, null);
if (theStack.size() > 0) {
return theStack.get(0);
}
for (MWindowElement child : window.getChildren()) {
if (child instanceof MPerspectiveStack) {
return (MPerspectiveStack) child;
}
}
return null;
}
示例3: openNewWindowPerspective
import org.eclipse.e4.ui.workbench.modeling.EModelService; //导入方法依赖的package包/类
/**
* Opens the specified perspective in a new window.
*
* @param perspectiveId
* The perspective to open; must not be <code>null</code>
* @throws ExecutionException
* If the perspective could not be opened.
*/
private void openNewWindowPerspective(IEclipseContext context, String perspectiveID) {
MApplication application = context.get(MApplication.class);
EPartService partService = context.get(EPartService.class);
EModelService modelService = context.get(EModelService.class);
List<MPerspective> perspectives = modelService.findElements(application, perspectiveID, MPerspective.class, null);
partService.switchPerspective(perspectives.get(0));
}
示例4: openPerspective
import org.eclipse.e4.ui.workbench.modeling.EModelService; //导入方法依赖的package包/类
/**
* Opens the perspective with the given identifier.
*
* @param perspectiveId
* The perspective to open; must not be <code>null</code>
* @throws ExecutionException
* If the perspective could not be opened.
*/
private final void openPerspective(IEclipseContext context, String perspectiveID) {
MApplication application = context.get(MApplication.class);
EPartService partService = context.get(EPartService.class);
EModelService modelService = context.get(EModelService.class);
List<MPerspective> perspectives = modelService.findElements(application, perspectiveID, MPerspective.class, null);
partService.switchPerspective(perspectives.get(0));
}
示例5: findPlaceholder
import org.eclipse.e4.ui.workbench.modeling.EModelService; //导入方法依赖的package包/类
/** Find the MPlaceholder corresponding to this MPart in the MPerspective. This
* may have persisted information relevant to loading this view.
* @return corresponding placeholder or <code>null</code>
*/
private MPlaceholder findPlaceholder()
{
final IEclipseContext localContext = getViewSite().getService(IEclipseContext.class);
final MPart part = localContext.get(MPart.class);
final EModelService service = PlatformUI.getWorkbench().getService(EModelService.class);
final IEclipseContext globalContext = PlatformUI.getWorkbench().getService(IEclipseContext.class);
final MApplication app = globalContext.get(MApplication.class);
final List<MPlaceholder> phs = service.findElements(app, null, MPlaceholder.class, null);
for (MPlaceholder ph : phs)
if (ph.getRef() == part)
return ph;
return null;
}
示例6: findPartsById
import org.eclipse.e4.ui.workbench.modeling.EModelService; //导入方法依赖的package包/类
public static void findPartsById(MApplication application, EModelService service) {
List<MPart> findElements = service.findElements(application, "mypart", //$NON-NLS-1$
MPart.class, null);
if (log.isInfoEnabled()) {
log.info("Found part(s) : " + findElements.size()); //$NON-NLS-1$
}
}
示例7: findObjectsByTag
import org.eclipse.e4.ui.workbench.modeling.EModelService; //导入方法依赖的package包/类
public static void findObjectsByTag(MApplication application, EModelService service) {
List<String> tags = new ArrayList<String>();
tags.add("justatag"); //$NON-NLS-1$
List<MUIElement> elementsWithTags = service.findElements(application, null, null, tags);
if (log.isInfoEnabled()) {
log.info("Found parts(s) : " + elementsWithTags.size()); //$NON-NLS-1$
}
}
示例8: execute
import org.eclipse.e4.ui.workbench.modeling.EModelService; //导入方法依赖的package包/类
@Execute
public void execute(@Named("PerspectiveId") String perspectiveId, EModelService service, final MApplication application,
final EPartService partService)
{
// Finding main perspective by ID fails for Main perspectives. Eclipse add '.<main_perspective>' to the ID
// WORKAROUND: Get all perspectives and find element which ID starts with passed perspectiveId
MPerspective element = null;
List<MPerspective> elements = service.findElements(application, null, MPerspective.class, null);
for (MPerspective p : elements)
{
if (p.getElementId().startsWith(perspectiveId))
{
element = p;
break;
}
}
// Switch perspective
if (element != null)
{
final MPerspective fElement = element;
BusyIndicator.showWhile(Display.getDefault(), new Runnable()
{
@Override
public void run()
{
switchPerspective(application, partService, fElement);
}
});
} else
{
throw new IllegalArgumentException("Perspective with perspectiveId: " + perspectiveId + " does not exist!");
}
}
示例9: preSave
import org.eclipse.e4.ui.workbench.modeling.EModelService; //导入方法依赖的package包/类
/**
* Called before the application model is saved when the application is
* closing.
*
* @param application The application.
* @param modelService
* @param partService
*/
@PreSave
public void preSave(MApplication application, EModelService modelService,
EPartService partService){
LinkedList<String> tags = new LinkedList<String>();
tags.add(REMOVE_ON_EXIT_TAG);
//Remove all Parts from the model which have the REMOVE_ON_EXIT_TAG
for(MPart part: modelService.findElements(application, null,
MPart.class, tags)){
part.getParent().getChildren().remove(part);
}
}
示例10: clonePerspectiveWithWorkaround
import org.eclipse.e4.ui.workbench.modeling.EModelService; //导入方法依赖的package包/类
/**
* Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=481996 Set the references of the
* placeholder to the corresponding parts again in the copy.
*/
private static MPerspective clonePerspectiveWithWorkaround(EModelService modelService,
MPerspective original){
MPerspective clone = (MPerspective) modelService.cloneElement(original, null);
clone.setElementId(original.getElementId());
List<MPlaceholder> placeholderClones = modelService.findElements(clone, null,
MPlaceholder.class, null, EModelService.IN_ANY_PERSPECTIVE);
// For each placeholder in the new perspective, set the reference value to the one from the old perspective
for (MPlaceholder placeholderClone : placeholderClones) {
// Search for the corresponding placeholder in the "old" perspective
List<MPlaceholder> placeholderOriginal =
modelService.findElements(original, placeholderClone.getElementId(),
MPlaceholder.class, null, EModelService.IN_ANY_PERSPECTIVE);
if (placeholderOriginal.size() == 1) {
// We found only one corresponding placeholder element. Set reference of old element to the new element
placeholderClone.setRef((placeholderOriginal.get(0).getRef()));
} else if (placeholderOriginal.isEmpty()) {
System.out.println("NO PLACEHOLDER");
} else {
System.out.println("MORE THEN ONE PLACEHOLDER" + " " //$NON-NLS-1$
+ placeholderOriginal.toString());
placeholderClone.setRef((placeholderOriginal.get(0).getRef()));
}
}
return clone;
}
示例11: findParts
import org.eclipse.e4.ui.workbench.modeling.EModelService; //导入方法依赖的package包/类
public static void findParts(MApplication application, EModelService service) {
List<MPart> parts = service.findElements(application, null, MPart.class, null);
if (log.isInfoEnabled()) {
log.info("Found parts(s) : " + parts.size()); //$NON-NLS-1$
}
}
示例12: execute
import org.eclipse.e4.ui.workbench.modeling.EModelService; //导入方法依赖的package包/类
@Execute
public void execute(EPartService partService, EModelService modelService, MWindow window) throws IOException {
// create a resource, which is able to store e4 model elements
E4XMIResourceFactory e4xmiResourceFactory = new E4XMIResourceFactory();
Resource resource = e4xmiResourceFactory.createResource(null);
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream("/home/simon/simon.xmi");
// load the stored model element
resource.load(inputStream, null);
if (!resource.getContents().isEmpty()) {
// after the model element is loaded it can be obtained from the
// contents of the resource
MPerspective loadedPerspective = (MPerspective) resource.getContents().get(0);
// get the parent perspective stack, so that the loaded
// perspective can be added to it.
MPerspective activePerspective = modelService.getActivePerspective(window);
MElementContainer<MUIElement> perspectiveParent = activePerspective.getParent();
// remove the current perspective, which should be replaced by
// the loaded one
List<MPerspective> alreadyPresentPerspective = modelService.findElements(window,
loadedPerspective.getElementId(), MPerspective.class, null);
for (MPerspective perspective : alreadyPresentPerspective) {
modelService.removePerspectiveModel(perspective, window);
}
// add the loaded perspective and switch to it
perspectiveParent.getChildren().add(loadedPerspective);
partService.switchPerspective(loadedPerspective);
}
} finally {
if (inputStream != null) {
inputStream.close();
}
}
}
示例13: savePerspectiveAs
import org.eclipse.e4.ui.workbench.modeling.EModelService; //导入方法依赖的package包/类
@SuppressWarnings("restriction")
@Override
public void savePerspectiveAs(String perspectiveId, String newName){
EModelService modelService = getService(EModelService.class);
MApplication mApplication = getService(MApplication.class);
PerspectiveRegistry perspectiveRegistry =
(PerspectiveRegistry) PlatformUI.getWorkbench().getPerspectiveRegistry();
PerspectiveDescriptor existingPerspectiveDescriptor =
(PerspectiveDescriptor) perspectiveRegistry.findPerspectiveWithId(perspectiveId);
if (existingPerspectiveDescriptor != null) {
int idx = isPerspectiveInsideStack(existingPerspectiveDescriptor);
// loads the mapplication from the orginal descriptor
openPerspective(existingPerspectiveDescriptor);
// the model must be loaded
List<MPerspective> modelPerspective = modelService.findElements(mApplication,
existingPerspectiveDescriptor.getId(), MPerspective.class, null);
// check if the model is loaded
if (!modelPerspective.isEmpty()) {
// create a new pd
PerspectiveDescriptor newPd =
perspectiveRegistry.createPerspective(newName, existingPerspectiveDescriptor);
// saves an opens the new perspective
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.savePerspectiveAs(newPd);
// close the new created one
closePerspective(newPd);
if (idx > -1) {
// opens the original descriptor if it was already opened
openPerspective(existingPerspectiveDescriptor);
}
}
}
}