@Override protected CompositeWidget layoutCategorizedEditors( Category category, List<PropertyEditor> editors) { if (((TypeCategory) category).isDatatype) { CompositeWidgetType compositeType = ConfigurationManager.instance.getDefaultCompositeType(); CompositeWidget container = UiFactory.eINSTANCE.createCompositeWidget(); container.setWidgetType(compositeType); Layout layout = createLayout(category.getNumColumns()); container.setLayout(layout); for (PropertyEditor editor : editors) { CompositeWidget group = createDataTypeGroup(editor.getProperty()); PropertyEditor viewEditor = UiFactory.eINSTANCE.createPropertyEditor(); viewEditor.setWidgetType(getViewEditor()); viewEditor.setProperty(editor.getProperty()); ValueAttribute view = UiFactory.eINSTANCE.createValueAttribute(); view.setName("view"); view.setValue(getViewName(editor.getProperty())); viewEditor.getAttributes().add(view); group.getWidgets().add(viewEditor); container.getWidgets().add(group); } return container; } return super.layoutCategorizedEditors(category, editors); }
protected Layout createLayout(Integer columns) { LayoutType propertiesLayoutType = ConfigurationManager.instance.getDefaultLayoutType(); Layout layout = UiFactory.eINSTANCE.createLayout(); ValueAttribute numColumns = UiFactory.eINSTANCE.createValueAttribute(); numColumns.setName("numColumns"); // $NON-NLS-1$ numColumns.setValue(columns.toString()); layout.getAttributes().add(numColumns); layout.setLayoutType(propertiesLayoutType); return layout; }
protected CompositeWidget createDataTypeGroup(Property property) { CompositeWidgetType groupType = getGroupComposite(); CompositeWidget group = UiFactory.eINSTANCE.createCompositeWidget(); group.setWidgetType(groupType); ValueAttribute text = UiFactory.eINSTANCE.createValueAttribute(); text.setName("text"); text.setValue(PropertiesUtil.getLabel(property)); group.getAttributes().add(text); Layout layout = createLayout(1); group.setLayout(layout); return group; }
private CompositeWidget createWidget() { CompositeWidget newWidget = UiFactory.eINSTANCE.createCompositeWidget(); for (Map.Entry<String, String> entry : getNamespaces().entrySet()) { ValueAttribute attribute = UiFactory.eINSTANCE.createValueAttribute(); attribute.setName(entry.getKey()); attribute.setValue(entry.getValue()); newWidget.getAttributes().add(attribute); } newWidget.setWidgetType(ConfigurationManager.instance.getDefaultCompositeType()); Layout layout = UiFactory.eINSTANCE.createLayout(); layout.setLayoutType(ConfigurationManager.instance.getDefaultLayoutType()); newWidget.setLayout(layout); return newWidget; }
@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; }