protected Context findContext(Property property) { DataContextElement element = property.getContextElement(); if (element instanceof DataContextRoot) { // TODO : Add a container reference to Context return (Context) element.eContainer(); } return findContext(element); }
protected List<String> getPropertyPath(DataContextElement element) { List<String> result; if (element.getPackage() == null) { result = new LinkedList<String>(); } else { result = getPropertyPath(element.getPackage()); } result.add(element.getName()); return result; }
protected Context findContext(DataContextElement element) { DataContextPackage dataContextPackage = element.getPackage(); if (dataContextPackage instanceof DataContextRoot) { return (Context) dataContextPackage.eContainer(); } return findContext(dataContextPackage); }
private void getAllContextElements(DataContextElement source, Set<DataContextElement> result) { if (result.contains(source)) { return; } result.add(source); for (DataContextElement element : source.getSupertypes()) { getAllContextElements(element, result); } }
@Override public boolean performFinish() { if (generator == null || contexts == null || contexts.isEmpty() || layoutGenerator == null) { return false; } ConfigurationManager configManager = ConfigurationManager.instance; for (Context context : contexts) { Tab defaultTab = ContextsFactory.eINSTANCE.createTab(); defaultTab.setId(context.getName().toLowerCase()); defaultTab.setLabel(context.getName()); defaultTab.setPriority(100); context.getTabs().add(defaultTab); FieldSelection fieldSelection = selectFieldsPage.getFieldSelection(); // URI contextURI = context.eResource().getURI(); // Resource selectionResource = // context.eResource().getResourceSet().createResource(URI.createURI(context.getName() + // "FieldSelection.xmi").resolve(contextURI)); //$NON-NLS-1$ // selectionResource.getContents().add(fieldSelection); // try { // selectionResource.save(null); // } catch (IOException ex) { // Activator.log.error("Couldn't persist the field selection model", ex); //$NON-NLS-1$ // } layoutGenerator.setGenerator(generator); for (View view : context.getViews()) { if (view.getConstraints().size() == 0) { continue; } List<PropertyEditor> editors = new LinkedList<PropertyEditor>(); for (DataContextElement element : getAllContextElements(view.getDatacontexts())) { for (Property property : element.getProperties()) { if (isSelected(fieldSelection, property, view.getElementMultiplicity() != 1)) { PropertyEditor editor = UiFactory.eINSTANCE.createPropertyEditor(); editor.setProperty(property); editor.setWidgetType(configManager.getDefaultEditorType(property)); editors.add(editor); ValueAttribute input = UiFactory.eINSTANCE.createValueAttribute(); input.setName("input"); // $NON-NLS-1$ input.setValue("{Binding}"); // $NON-NLS-1$ editor.getAttributes().add(input); } } } List<Section> generatedSections = layoutGenerator.layoutElements(editors, view); defaultTab.getSections().addAll(generatedSections); view.getSections().addAll(generatedSections); context.getViews().add(view); } int i = 1; for (Tab tab : context.getTabs()) { i += tab.getSections().size(); } final int numberOfSections = i; try { setNeedsProgressMonitor(true); final Context currentContext = context; getContainer() .run( true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask( Messages.CreateContextWizard_propertyViewGenerationJobName + currentContext.getName(), numberOfSections + 1); monitor.worked(1); try { currentContext.eResource().save(Collections.EMPTY_MAP); monitor.worked(1); for (Tab tab : currentContext.getTabs()) { for (Section section : tab.getSections()) { if (monitor.isCanceled()) { return; } section.getWidget().eResource().save(Collections.EMPTY_MAP); monitor.worked(1); } } } catch (IOException ex) { Activator.log.error(ex); return; } monitor.done(); } }); } catch (InvocationTargetException ex) { Activator.log.error(ex); } catch (InterruptedException ex) { Activator.log.error(ex); } } return true; }