Esempio n. 1
0
 private View resolveView() {
   String contextName = viewPath.substring(0, viewPath.indexOf(":")); // $NON-NLS-1$
   String viewName = viewPath.substring(viewPath.indexOf(":") + 1); // $NON-NLS-1$
   Context context = ConfigurationManager.instance.getContext(contextName);
   for (View view : context.getViews()) {
     if (view.getName().equals(viewName)) {
       return view;
     }
   }
   return null;
 }
  @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;
  }