Package com.onpositive.semantic.model.binding

Examples of com.onpositive.semantic.model.binding.Binding


  }

  public String[] openDetailDialog(String kind) {
    ApiProxy.setEnvironmentForCurrentThread(new FakeEnvironment(getAppId()));
    CompositeEditor editor = new CompositeEditor();
    final Binding bnd = new Binding(String.class);
    bnd.setName("Key details");

    editor.setBinding(bnd);

    final ListEnumeratedValueSelector<Field> vl = new ListEnumeratedValueSelector<Field>();
    final DetailsFilterDialog dlg = new DetailsFilterDialog(editor, vl);
    vl.setAsCheckBox(true);
    dlg.setResizable(true);
    editor.add(vl);
    final OrderedRealm<Field> realm = new OrderedRealm<Field>();
    bnd.setDescription("Capturing properties...");
    vl.setRealm(realm);

    DisposeBindingListener.linkBindingLifeCycle(bnd, editor);
    final BaseDataFacade baseDataFacade = new BaseDataFacade(kind,
        facade.getProject(), facade.isDebug());
View Full Code Here


      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }

    Binding bnd = new Binding(r);
    bnd.setAutoCommit(true);

    bnd.setName("Namespace list");
    bnd.setDescription("Please choose namespace");

    CompositeEditor editor = new CompositeEditor(bnd);
    Container c1 = new Container();
    c1.setLayoutManager(new OneElementOnLineLayouter());
    Container c2 = new Container();
    Container all = new Container();

    GridData c1gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    c1gd.horizontalIndent = 0;
    c1gd.verticalIndent = 0;
    c1.setLayoutData(c1gd);
    // c1.setBordered(true);

    c2.setLayout(new GridLayout(1, false));
    c2.setLayoutData(new GridData(SWT.RIGHT, SWT.BOTTOM, false, false));
    // c2.setBordered(true);

    GridLayout alll = new GridLayout(2, false);
    alll.marginWidth = 1;
    alll.marginHeight = 1;
    all.setLayout(alll);

    GridData allgd = new GridData(SWT.FILL, SWT.FILL, true, true);
    allgd.horizontalAlignment = 0;
    allgd.verticalAlignment = 0;
    all.setLayoutData(allgd);
    // all.setBordered(true);

    final Binding currNSBinding = bnd.getBinding("current");

    final OneLineTextElement<String> current = new OneLineTextElement(
        currNSBinding);
    current.setReadOnly(true);

    final Binding nsListBinding = bnd.getBinding("namespaces");
    nsListBinding.setMaxCardinality(1);
    final ListEnumeratedValueSelector<String> l = new ListEnumeratedValueSelector<String>(
        nsListBinding) {

      protected void updateSize(TableViewer newCheckList) {
        TableColumn tableColumn = (TableColumn) columnWidget;
View Full Code Here

          .create());
      GridLayout layout32 = new GridLayout(7, false);
      r.setLayout(layout32);
      layout32.marginHeight = 3;

      Binding bnd = new Binding("");

      // //\\\\
      // bnd.setValue(kind, null);
      // //\\\\\

      // bnd.setName("");
      // bnd.setRequired(true);

      Binding b = new Binding(this);
      b.setAutoCommit(true);
      OneLineTextElement<String> l = new OneLineTextElement<String>();
      l.setCaption("Display not more then:");
      Binding binding2 = b.getBinding("limit");
      binding2.setRealm(new Realm<String>("All", "10", "100", "500",
          "1000", "10000"));
      binding2.addCommitListener(new ICommitListener() {

        public void commitPerformed(ICommand command) {
          CTabItem selection = viewHolder.getSelection();
          if (selection != null) {
            BaseDataFacade bf = (BaseDataFacade) selection
                .getData();
            try {
              bf.setLimit(Integer.parseInt(limit));
            } catch (NumberFormatException e1) {
              bf.setLimit(-1);
            }
          }
        }
      });
      l.setBinding(binding2);
      l.setLayoutData(GridDataFactory.fillDefaults().hint(50, -1)
          .create());
      ComboEnumeratedValueSelector<IProject> v = new ComboEnumeratedValueSelector<IProject>();
      DisposeBindingListener.linkBindingLifeCycle(b, l);
      binding = new Binding("");
      binding.setRequired(true);

      binding.setName("Project:");
      projects = new Realm<IProject>();
      initProjects(projects);
View Full Code Here

        Link l0 = new Link(cm, SWT.NONE);
        l0.setText("<a>Customize Key</a>");
        l0.addSelectionListener(new SelectionAdapter() {

          public void widgetSelected(SelectionEvent e) {
            Binding b = new Binding("");
            b.setName("Customize Key");
            b.setDescription("Please type long or string key in 'Id or Name' field");
            final Binding id = new Binding(b.getBinding("id"));
            id.setRequired(true);
            id.setName("Id or Name:");
            id.setValue("", null);
            id.setReadOnly(false);
            OneLineTextElement<String> idel = new OneLineTextElement<String>(
                id);

            // OneLineTextElement<String>nl=new
            // OneLineTextElement<String>(name);
            CompositeEditor ed = new CompositeEditor(b);
            ed.setLayoutManager(new OneElementOnLineLayouter());
            ed.add(idel);
            // ed.add(nl);
            Container buttons = new Container();
            buttons.setLayoutManager(new HorizontalLayouter());
            ButtonSelector ba = new ButtonSelector();
            ba.setText("Ok");
            final InputElementDialog dlg = new InputElementDialog(
                ed);
            ba.setValue(new Runnable() {

              public void run() {
                String value = (String) id.getValue();
                Key k = null;
                Entity value2 = (Entity) editor.getBinding()
                    .getValue();
                Key c = (Key) value2.getKey();
                if (c != null && c.isComplete()) {
                  if (!value2.hasProperty("$$OLD_KEY_SET")) {
                    value2.setProperty("$$OLD_KEY_SET",
                        Boolean.TRUE);
                    value2.setProperty("$$OLD_KEY"
                        + Entity.KEY_RESERVED_PROPERTY,
                        c);
                  }
                }
                if (value != null && value.trim().length() != 0) {
                  String vl = value.trim();
                  try {
                    long l = Long.parseLong(vl);

                    k = KeyFactory.createKey(
                        value2.getKind(), l);
                  } catch (Exception e) {
                    k = KeyFactory.createKey(
                        ((Entity) editor.getBinding()
                            .getValue()).getKind(),
                        vl);
                  }
                } else {
                  return;
                }
                // value2.setProperty(Entity.KEY_RESERVED_PROPERTY,
                // k);
                try {
                  java.lang.reflect.Field f = value2
                      .getClass().getDeclaredField("key");
                  f.setAccessible(true);
                  f.set(value2, k);
                } catch (Exception e) {
                  Activator.log(e);
                }
                if (k != null) {
                  String string = "" + k.toString();
                  ((Binding) editor.getBinding())
                      .setName(string);
                  EditDialog.this.setTitle(string);
                  ;
                  dlg.close();
                }
              }
            });
            ButtonSelector ba1 = new ButtonSelector();
            ba1.setValue(new Runnable() {

              public void run() {
                dlg.close();
              }
            });
            ba1.setText("Cancel");
            buttons.add(ba);
            buttons.add(ba1);
            ed.add(buttons);
            DisposeBindingListener.linkBindingLifeCycle(b, ed);
            dlg.open();
            super.widgetSelected(e);
          }
        });
      }
      Link l1 = new Link(cm, SWT.NONE);
      l1.setText("<a>Add new property</a>");
      l1.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
          Binding b = new Binding("");
          b.setName("Configure new Property");
          final Binding binding = b.getBinding("name");
          binding.setName("Name");
          binding.setReadOnly(false);

          binding.addValidator(new ValidatorAdapter<String>() {

            public CodeAndMessage isValid(IBinding context,
                String object) {
              if (object == null || object.length() == 0) {
                return CodeAndMessage
                    .errorMessage("please define property name");
              }
              Binding b = (Binding) editor.getBinding();
              if (b.getKnownChilds().contains(object)) {
                return CodeAndMessage
                    .errorMessage("property with this name already exits");
              }
              return super.isValid(context, object);
            }
          });
          final Binding type = b.getBinding("type");
          final Binding kc = b.getBinding("keyKind");
          kc.setName("Kind:");
          kc.setValue(
              ((Entity) editor.getBinding().getValue()).getKind(),
              null);
          kc.setReadOnly(false);
          kc.setRequired(false);
          type.setName("Type");
          type.setReadOnly(false);
          type.setRequired(true);
          final OneLineTextElement<String> keyKind = new OneLineTextElement<String>(
              kc);
          type.setAdapter(ITextLabelProvider.class,
              new TextProviderAdapter() {

                public String getText(Object object) {
                  Class<?> c = (Class<?>) object;
                  return c.getSimpleName();
                }
              });
          type.setValue(String.class, null);
          type.setRealm(new Realm<Class<?>>(
              EditorUtility.SUPPORTED_TYPES));
          final Binding multi = b.getBinding("multi");
          multi.setReadOnly(false);
          multi.setName("Multivalue");
          type.setName("Type");
          multi.setValue(false, null);
          CompositeEditor z = new CompositeEditor(b);
          final Container m = new Container();
          m.setLayoutManager(new OneElementOnLineLayouter());
          OneLineTextElement<String> t = new OneLineTextElement<String>(
              binding);
          // t.setCaption("Name:");
          m.add(t);
          ComboEnumeratedValueSelector<Class<?>> element2 = new ComboEnumeratedValueSelector<Class<?>>(
              type);
          type.addValueListener(new IValueListener<Class<?>>() {

            public void valueChanged(Class<?> oldValue,
                Class<?> newValue) {
              if (newValue == Key.class) {
                m.add(2, keyKind);
                m.getControl().getShell().pack(true);
              } else if (oldValue == Key.class) {
                m.remove(keyKind);
                m.getControl().getShell().pack(true);
              }

            }

          });
          ButtonSelector sl = new ButtonSelector(SWT.CHECK);
          sl.setBinding(multi);
          m.add(element2);
          m.add(sl);
          z.setLayoutManager(new OneElementOnLineLayouter());
          z.add(m);
          Container m1 = new Container();
          m1.setLayoutManager(new HorizontalLayouter());
          final InputElementDialog dl = new InputElementDialog(z);
          final ButtonSelector ok = new ButtonSelector();
          ok.setText("Ok");
          ok.setValue(new Runnable() {

            public void run() {
              String value = (String) binding.getValue();
              BaseDataFacade.GAEField gaeField = facade
                  .createField(value,
                      (Class<?>) type.getValue(),
                      (Boolean) (multi.getValue()),
                      (String) kc.getValue());
              EditingBinding binding2 = (EditingBinding) editor
                  .getBinding();
              binding2.removedElements.remove(value);
              binding2.fieldsChanged = true;
              binding2.getBinding(value).setValue(null, null);
              EditorUtility.createBindingsWithButton(
                  (Entity) binding2.getValue(), editor,
                  (Binding) binding2,
                  new Field[] { gaeField }, facade, true);
              dl.close();
              editor.getControl().getShell().layout(true, true);
              editor.getControl().getShell().pack(true);
            }
          });
          ok.setEnabled(false);
          b.addStatusChangeListener(new IStatusChangeListener() {

            public void statusChanged(IBinding bnd,
                CodeAndMessage cm) {
              ok.setEnabled(cm.getCode() == 0);

            }
          });
          ButtonSelector cancel = new ButtonSelector();
          cancel.setText("Cancel");
          m1.add(ok);
          m1.add(cancel);
          cancel.setValue(new Runnable() {

            public void run() {
              dl.close();
            }
          });
          m1.getLayoutHints().setGrabHorizontal(true);
          m1.getLayoutHints().setAlignmentHorizontal(SWT.RIGHT);
          z.add(m1);
          DisposeBindingListener.linkBindingLifeCycle(b, z);
          dl.open();
        }

        public void widgetDefaultSelected(SelectionEvent e) {

        }
      });
      Link l2 = new Link(cm, SWT.NONE);
      l2.setText("<a>Remove property</a>");
      l2.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
          Binding bnd2 = new Binding("");
          bnd2.setName("Select property to remove");
          CompositeEditor ed = new CompositeEditor(bnd2);
          ed.setLayoutManager(new OneElementOnLineLayouter());
          final ListEnumeratedValueSelector<String> element2 = new ListEnumeratedValueSelector<String>();
          ed.add(element2);
          final Binding bnd = (Binding) editor.getBinding();
          Collection<String> str = bnd.getKnownChilds();
          element2.setRealm(new Realm<String>(str));
          element2.setValue(str);
          element2.getLayoutHints().setHint(new Point(200, 300));
          final InputElementDialog em = new InputElementDialog(ed);

          DisposeBindingListener.linkBindingLifeCycle(bnd2, ed);
          Container b = new Container();
          b.setLayoutManager(new HorizontalLayouter());
          final ButtonSelector ok = new ButtonSelector();
          ok.setText("Ok");
          ok.setEnabled(false);
          element2.addSelectionChangedListener(new ISelectionChangedListener() {

            public void selectionChanged(SelectionChangedEvent event) {
              ok.setEnabled(!event.getSelection().isEmpty());
            }
          });
          b.add(ok);
          ok.setValue(new Runnable() {

            public void run() {
              for (Object o : element2.getSelection().toArray()) {
                AbstractUIElement<?> findEditor = findEditor(
                    editor, o.toString());
                if (findEditor != null) {
                  Container parent2 = findEditor.getParent();
                  if (parent2.getParent() instanceof CTabFolderElement) {
                    Container parent3 = parent2.getParent();
                    parent3.remove(parent2);
                    Container p4 = parent3.getParent();

                    if (p4 instanceof CompositeEditor) {
                      CompositeEditor ce = (CompositeEditor) p4;
                      String id = ce.getId();
                      if (id != null
                          && id.equals(o.toString())) {
                        ce.getParent().remove(ce);
                      }
                    }
                  } else {
                    parent2.remove(findEditor);

                    if (parent2 instanceof CompositeEditor) {
                      CompositeEditor ce = (CompositeEditor) parent2;
                      if (ce.getId().equals(o.toString())) {
                        ce.getParent().remove(ce);
                      }
                    }
                  }

                  Binding binding = bnd.getBinding(o
                      .toString());
                  binding.dispose();
                  EditingBinding b = (EditingBinding) editor
                      .getBinding();
                  b.removedElements.add(o.toString());
                }
View Full Code Here

          .create());
      GridLayout layout32 = new GridLayout(7, false);
      r.setLayout(layout32);
      layout32.marginHeight = 3;
      kindsText = new BaseViewerOneLineTextElement<String>();
      Binding bnd = new Binding("");
      if (kind != null) {
        bnd.setValue(kind, null);
      } else {
        bnd.setValue("", null);
      }
      // bnd.setName("");
      // bnd.setRequired(true);
      kindsText.setContentAssistLabelProvider(new LabelProvider() {

        public Image getImage(Object element) {
          return imageDescriptorFromPlugin;
        }
      });

      kindsText.setBinding(bnd);
      kindsRealm = new Realm<String>();
      kindsText.addListener(SWT.FocusIn, new SWTEventListener<Text>() {

        public void handleEvent(AbstractUIElement<Text> element,
            Event event) {
          if (!isDebug()) {
            addKindsFromStats();
          } else {
            try {
              BaseDataFacade f = tableUi.getFacade();
              String ns = "";
              if (f != null) {
                ns = f.getNamespace();
                if (ns == null) {
                  ns = "";
                }
              }
              appendKInds(project, ns);
            } catch (Exception e) {
              // e.printStackTrace();
              Activator
                  .getDefault()
                  .getLog()
                  .log(new Status(0, Activator.PLUGIN_ID,
                      "Exception", e));
            }
          }
        }
      });

      bnd.setRealm(kindsRealm);
      kindsText.setContentAssistEnabled(true);
      kindsText.setLayoutData(GridDataFactory.fillDefaults()
          .grab(true, false).minSize(100, -1).create());
      r.add(kindsText);

      DisposeBindingListener.linkBindingLifeCycle(bnd, kindsText);
      Binding b = new Binding(this);
      b.setAutoCommit(true);
      OneLineTextElement<String> l = new OneLineTextElement<String>();
      l.setCaption("Display not more then:");
      Binding binding2 = b.getBinding("limit");
      binding2.setRealm(new Realm<String>("All", "10", "100", "500",
          "1000", "10000"));
      binding2.addCommitListener(new ICommitListener() {

        public void commitPerformed(ICommand command) {
          CTabItem selection = viewHolder.getSelection();
          if (selection != null) {
            BaseDataFacade bf = (BaseDataFacade) selection
                .getData();
            try {
              bf.setLimit(Integer.parseInt(limit));
            } catch (NumberFormatException e1) {
              bf.setLimit(-1);
            }
          }
        }
      });
      l.setBinding(binding2);
      l.setLayoutData(GridDataFactory.fillDefaults().hint(50, -1)
          .create());
      ComboEnumeratedValueSelector<IProject> v = new ComboEnumeratedValueSelector<IProject>();
      DisposeBindingListener.linkBindingLifeCycle(b, l);
      binding = new Binding("");
      binding.setRequired(true);

      binding.setName("Project:");
      projects = new Realm<IProject>();
      initProjects(projects);
View Full Code Here

    } else {
      bnd.setName("Store " + facade.kind);
    }
    editor.setBinding(bnd);
    for (Field f : facade.getFields()) {
      final Binding binding = bnd.getBinding(f.name);
      if (!edit) {
        binding.setName(f.getTitle());
      } else {
        binding.setName(f.getTitle());
      }
      // Object o = binding.getValue();
      if (f.name.equals(BlobStoreDataFacade.FILENAME_PROP)) {
        binding.setReadOnly(false);
        String tmpS = "";
        if (edit && false) {
          tmpS = (String) entity.getProperty(f.name);
          binding.setValue(tmpS, null);
        }
        final String fname = tmpS;

        binding.setFactory(new IFactory() {

          public Object getValue(Object context) {
            FileDialog fd = null;
            if (!edit) {
              fd = new FileDialog(Display.getCurrent()
                  .getActiveShell(), SWT.OPEN);
              fd.setText("Select file");
              String open = ((FileDialog) fd).open();
              return open;
            } else {
              DirectoryDialog dd = new DirectoryDialog(Display
                  .getCurrent().getActiveShell(), SWT.SAVE);
              dd.setText("Store file");
              String choosenDir = dd.open();

              binding.setValue(fname, null);
              if (choosenDir == null) {
              }
              return choosenDir;// + File.pathSeparator + fname;
            }
View Full Code Here

      String storedFilePath = "";
      for (String b : getKnownChilds()) {
        // if(facade.getKindsOfChildren().containsKey(b)){
        // continue;
        // }
        Binding binding = getBinding(b);
        Object value = binding.getValue();
        int count = 0;
        try {
          if (b.equals(BlobStoreDataFacade.FILENAME_PROP)) {
            storedFilePath = (String) value;// + File.pathSeparator
                            // +
View Full Code Here

    if (f.isKey()) {
      return text;
    } else {
      final Class<?> type = f.getType();
      if (type != null) {
        final Binding binding = bnd.getBinding(f.name);
        binding.setValue(e.getProperty(f.name), null);
        Object adapter = new ClassAdapterFactory().getAdapter(type,
            IValidator.class);
        if (adapter != null) {
          binding.setAdapter(IValidator.class, (IValidator) adapter);
        }
        adapter = new ClassAdapterFactory().getAdapter(type,
            ILabelLookup.class);
        if (adapter != null) {
          binding.setAdapter(ILabelLookup.class,
              (ILabelLookup) adapter);
        }
        adapter = new ClassAdapterFactory().getAdapter(type,
            IRealmProvider.class);
        if (adapter != null) {

          binding.setAdapter(IRealmProvider.class,
              (IRealmProvider) adapter);
        } else {
          IRealm<?> c = facade.getRealm(f);
          if (c != null) {
            binding.setRealm(c);
          }
        }
        binding.setReadOnly(false);
        binding.setName(f.getTitle());

        if (type == String.class) {
          OneLineTextElement<String> t = new OneLineTextElement<String>();
          t.setBinding(binding);
          ed.add(t);

          addIsNullButtonSelector(binding, ed, null);
          if (needIndexable) {
            addNotIndexableButton(binding, ed, f);
          }
        } else if (Number.class.isAssignableFrom(type)
            || type.isPrimitive()) {
         
          binding.setSubjectClass(type);
          OneLineTextElement<Number> t = new OneLineTextElement<Number>();
          binding.addValidator(new ValidatorAdapter() {

            public CodeAndMessage isValid(IBinding context,
                Object object) {
              if (object == null) {
                return CodeAndMessage.OK_MESSAGE;
              }
              try {
                if (object instanceof String) {
                  if (type == Double.class) {
                    Double.parseDouble((String) object);
                  } else if (type == Long.class) {
                    Long.parseLong((String) object);
                  } else if (type == Float.class) {
                    Float.parseFloat((String) object);
                  } else if (type == Integer.class) {
                    Integer.parseInt((String) object);
                  }
                } else {
                  if (!Number.class.isAssignableFrom(object
                      .getClass())) {
                    return CodeAndMessage
                        .errorMessage("The number should be in this place");
                  }
                }
                return CodeAndMessage.OK_MESSAGE;
              } catch (NumberFormatException e) {
                return CodeAndMessage
                    .errorMessage("The number should be in this place");
              }
              // return super.isValid(context, object);
            }

          });
          t.setBinding(binding);
          ed.add(t);

          addIsNullButtonSelector(binding, ed, null);
          if (needIndexable) {
            addNotIndexableButton(binding, ed, f);
          }
        } else if (type == Boolean.class) {
          binding.setSubjectClass(type);
          ComboEnumeratedValueSelector<Boolean> t = new ComboEnumeratedValueSelector<Boolean>();
          t.setBinding(binding);
          ed.add(t);

          addIsNullButtonSelector(binding, ed, null);
          if (needIndexable) {
            addNotIndexableButton(binding, ed, f);
          }
        } else if (type == Text.class) {
          if (text == null) {
            text = new CTabFolderElement();
            text.setBordered(true);
            ed.setData("text", text);
            ed.add(text);
          }
          createText(ed, text, binding, true);

          // addIsNullButtonSelector(binding, ed, null);
          if (needIndexable) {
            addNotIndexableButton(binding, ed, f);
          }
        } else if (type == Link.class) {
          createLink(ed, binding);

          addIsNullButtonSelector(binding, ed, null);
          if (needIndexable) {
            addNotIndexableButton(binding, ed, f);
          }
        } else if (type == Category.class) {
          createCategory(ed, binding);

          addIsNullButtonSelector(binding, ed, null);
          if (needIndexable) {
            addNotIndexableButton(binding, ed, f);
          }
        } else if (type == Email.class) {
          createEmail(ed, binding);

          addIsNullButtonSelector(binding, ed, null);
          if (needIndexable) {
            addNotIndexableButton(binding, ed, f);
          }
        } else if (type == PostalAddress.class) {
          createPostalAddress(ed, binding);

          addIsNullButtonSelector(binding, ed, null);
          if (needIndexable) {
            addNotIndexableButton(binding, ed, f);
          }
        } else if (type == PhoneNumber.class) {
          createPhoneNumber(ed, binding);

          addIsNullButtonSelector(binding, ed, null);
          if (needIndexable) {
            addNotIndexableButton(binding, ed, f);
          }
        } else if (type == Date.class) {
          createDate(ed, binding);

          addIsNullButtonSelector(binding, ed, null);
          if (needIndexable) {
            addNotIndexableButton(binding, ed, f);
          }
        } else if (type == IMHandle.class) {
          createIMHandle(ed, binding);

          addIsNullButtonSelector(binding, ed, null);
          if (needIndexable) {
            addNotIndexableButton(binding, ed, f);
          }
        } else if (type == GeoPt.class) {
          createGeoPt(ed, binding);

          addIsNullButtonSelector(binding, ed, null);
          if (needIndexable) {
            addNotIndexableButton(binding, ed, f);
          }
        } else if (type == User.class) {
          createUser(ed, binding);

          addIsNullButtonSelector(binding, ed, null);
          if (needIndexable) {
            addNotIndexableButton(binding, ed, f);
          }
        } else if (type == Blob.class || type == ShortBlob.class) {
          createBlob(ed, type, binding, facade.getProject());

          addIsNullButtonSelector(binding, ed, null);
          if (needIndexable) {
            addNotIndexableButton(binding, ed, f);
          }
        } else if (type == Rating.class) {
          createRating(ed, binding);

          addIsNullButtonSelector(binding, ed, null);
          if (needIndexable) {
            addNotIndexableButton(binding, ed, f);
          }
        } else if (type == Key.class) {
          createKey(ed, binding, f);

          addIsNullButtonSelector(binding, ed, null);
          if (needIndexable) {
            addNotIndexableButton(binding, ed, f);
          }
        }
        // editor.setId(binding.getId());
      } else {
        final Binding binding = bnd.getBinding(f.name);
        final Container txt = text;

        binding.setReadOnly(false);
        binding.setName(f.getTitle());

        final LinkElement bs = new LinkElement();
        bs.setId(binding.getId());
        ed.setId(binding.getId());
        bs.getLayoutHints().setGrabVertical(false);
        bs.setText("Specify type");
        bs.setCaption(f.getTitle());
        bs.addHyperLinkListener(new IHyperlinkListener() {

          public void linkExited(HyperlinkEvent e) {
            // TODO Auto-generated method stub

          }

          public void linkEntered(HyperlinkEvent e) {
            return;

          }

          public void linkActivated(HyperlinkEvent event) {
            final Binding tmpBinding = new Binding("");
            tmpBinding.setName("Specify type for property");

            final Binding type = tmpBinding.getBinding("type");
            type.setReadOnly(false);
            type.setRequired(true);
            type.setName("Select type");
            type.setAdapter(ITextLabelProvider.class,
                new TextProviderAdapter() {

                  public String getText(Object object) {
                    Class<?> c = (Class<?>) object;
                    return c.getSimpleName();
                  }
                });
            type.setValue(String.class, null);
            type.setRealm(new Realm<Class<?>>(
                EditorUtility.SUPPORTED_TYPES));

            final ComboEnumeratedValueSelector ce = new ComboEnumeratedValueSelector(
                type);

            final CompositeEditor c1 = new CompositeEditor();
            c1.setLayoutManager(new OneElementOnLineLayouter());
            c1.add(ce);

            final Binding multi = tmpBinding.getBinding("multi");
            multi.setReadOnly(false);
            multi.setName("Multivalue");
            multi.setValue(false, null);

            ButtonSelector multiB = new ButtonSelector(multi,
                SWT.CHECK);
            c1.add(multiB);

            final Binding kk = tmpBinding.getBinding("KeyKind");
            kk.setName("Kind");
            kk.setValue(e.getKind(), null);
            kk.setReadOnly(false);
            kk.setRequired(false);

            final OneLineTextElement<String> keyKind = new OneLineTextElement<String>(
                kk);

            type.addValueListener(new IValueListener<Class<?>>() {

              public void valueChanged(Class<?> oldValue,
                  Class<?> newValue) {
                if (newValue == Key.class) {
                  c1.add(1, keyKind);
                  c1.getControl().getShell().pack(true);
                } else if (oldValue == Key.class) {
                  c1.remove(keyKind);
                  c1.getControl().getShell().pack(true);
                }

              }

            });

            CompositeEditor c2 = new CompositeEditor();
            c2.setLayoutManager(new HorizontalLayouter());
            ButtonSelector ok = new ButtonSelector();
            ok.setText("submit");
            ButtonSelector canc = new ButtonSelector();
            canc.setText("cancel");

            c2.add(ok);
            c2.add(canc);

            CompositeEditor finall = new CompositeEditor(tmpBinding);
            finall.setLayoutManager(new OneElementOnLineLayouter());
            finall.add(c1);
            finall.add(c2);

            final InputElementDialog ied = new InputElementDialog(
                finall);

            ok.setValue(new Runnable() {

              public void run() {
                IStructuredSelection iss = ce.getSelection();
                if (!iss.isEmpty()) {
                  Object fe = iss.getFirstElement();
                  Class choosen = (Class) fe;
                  ied.close();
                  ed.getParent().remove(ed);// remove(bs);

                  // ed.setLayoutManager(new
                  // HorizontalLayouter());
                  // ed.setBordered(true);
                  f.setType(choosen);
                  Object val = multi.getValue();
                  Object kind = kk.getValue();
                  if (val != null && f instanceof GAEField) {
                    ((GAEField) f).multiplicity = (Boolean) val;
                  }
                  if (kind != null) {
                    ((GAEField) f)
View Full Code Here

                }
              });// ((Collection)((HashMap)facade.getChildren().get(cgf.getKeyKind())).get(e.getKey()));

            } else {
              Object firstElement = null;
              Binding bnd = new Binding(firstElement);
              bnd.setName("Edit");
              CompositeEditor m = new CompositeEditor(bnd);
              TitledDialog dlg = new TitledDialog(m);
              GAEField singleField = fm.getSingleField();
              ApiProxy.setEnvironmentForCurrentThread(new FakeEnvironment(
                  e.getAppId()));
              Entity c = new Entity("A");

              if (fm instanceof CGAEField) {
                c = new Entity(fm.getKeyKind(), parent);
                // Entity example =
              } else {
                c.setProperty(f.name, firstElement);
              }
              createBindingsWithButton(c, m, bnd,
                  new Field[] { singleField }, facade, false);

              int open = dlg.open();
              if (open == Dialog.OK) {
                Binding bb = bnd.getBinding(f.name);
                Object value = bb.getValue();
                if (value == null || bb.isReadOnly()) {
                  value = new NullValue();
                }
                v.addValue(value);
              }
              bnd.dispose();

            }
          }
        });
        manager.add(new Action("Edit selected") {
          {
            setImageDescriptor(AbstractUIPlugin
                .imageDescriptorFromPlugin(Activator.PLUGIN_ID,
                    "/icons/text_edit.gif"));
          }

          public void run() {
            if (f instanceof CGAEField) {
              CGAEField cgf = (CGAEField) f;

              Object[] selected = v.getSelection().toArray();
              if (selected.length == 1) {
                BaseDataFacade fac = new BaseDataFacade(
                    cgf.keyKind, facade.getProject(),
                    facade.isDebug());
                fac.setNamespace(facade.getNamespace());
                DataStoreTableUI dstui = new DataStoreTableUI();
                Object selecttedd = selected[0];
                if (selecttedd instanceof Entity) {
                  final Entity sel = (Entity) selecttedd;
                  ArrayList<Entity> select = new ArrayList();
                  select.add(sel);
                  fac.determineFields(select);
                  dstui.setFacade(fac);
                  dstui.open(sel, false, true,
                      new IUpdateList() {

                        public void update(Entity e) {
                          v.removeValue(sel);
                          v.addValue(e);
                        }
                      });
                }
              }
              return;
            } else {
              Object firstElement = v.getSelection()
                  .getFirstElement();
              Binding bnd = new Binding(firstElement);
              bnd.setName("Edit");
              CompositeEditor m = new CompositeEditor(bnd);
              TitledDialog dlg = new TitledDialog(m);
              GAEField singleField = fm.getSingleField();
              ApiProxy.setEnvironmentForCurrentThread(new FakeEnvironment(
                  e.getAppId()));
              Entity c = new Entity("A");
              if (firstElement instanceof NullValue) {
                c.setProperty(f.name, null);
              } else {
                c.setProperty(f.name, firstElement);
              }
              createBindingsWithButton(c, m, bnd,
                  new Field[] { singleField }, facade, false);
              int open = dlg.open();
              if (open == Dialog.OK) {
                StructuredViewer viewer = v.getViewer();
                if (viewer instanceof TableViewer) {
                  Binding bb = bnd.getBinding(f.name);
                  Object value = bb.getValue();
                  if (value == null || bb.isReadOnly()) {
                    value = new NullValue();
                  }
                 
                  TableViewer tv = (TableViewer)viewer;
                  int index = tv.getTable().getSelectionIndex();                 
                  v.editValue(value, index);                 
                  //tv.get
                 
                } else {
                  v.removeValue(firstElement);
                  Binding bb = bnd.getBinding(f.name);
                  Object value = bb.getValue();
                  if (value == null || bb.isReadOnly()) {
                    value = new NullValue();
                  }
                  v.addValue(value);
                }
              }
              bnd.dispose();
            }
          }
        });
        manager.add(new Action("Delete selected") {
          {
            setImageDescriptor(AbstractUIPlugin
                .imageDescriptorFromPlugin(Activator.PLUGIN_ID,
                    "/icons/delete.gif"));
          }

          @SuppressWarnings("unchecked")
          public void run() {
            final List selected = v.getSelection().toList();

            if (f instanceof CGAEField) {
              final CGAEField cgf = (CGAEField) f;
              BaseDataFacade fac = new BaseDataFacade(
                  cgf.keyKind, facade.getProject(), facade
                      .isDebug());
              fac.setNamespace(facade.getNamespace());
              fac.delete(selected.toArray(new Entity[selected
                  .size()]), new OperationCallback() {

                public void passed(Object object) {
                  Collection coll = (Collection) ((HashMap) facade
                      .getChildren()
                      .get(cgf.getKeyKind())).get(e
                      .getKey());
                  coll.removeAll(selected);
                  facade.updateChildren(e);
                  v.removeValues(selected);
                }

                public void failed(Exception exception) {
                  return;
                }
              });
              // facade.updateChildren(e);
            } else {
              v.removeValues(selected);
            }
          }
        });
        return manager.createControl(conComposite);
      }

    });

    v.setValueAsSelection(false);
    Binding binding = bnd.getBinding(f.name);
    binding.setReadOnly(false);
    Object property = null;
    if (f instanceof CGAEField) {

      HashMap hashMap = (HashMap) facade.getChildren().get(
          ((CGAEField) f).keyKind);
      if (hashMap != null) {
        Collection col = (Collection) (hashMap).get(e.getKey());
        if (col != null) {
          property = new ArrayList<Object>();
          for (Iterator i = col.iterator(); i.hasNext();) {
            Entity ent = (Entity) i.next();
            ((ArrayList<Object>) property).add(ent);
            v.setLabelProvider(new LabelProvider() {

              public String getText(Object element) {
                Entity e = (Entity) element;
                String res = "";

                String[] details = ((CGAEField) f)
                    .getKeyKindDetails();
                if (details != null && details.length != 0) {
                  StringBuilder sb = new StringBuilder();
                  int ch = 0;
                  for (String det : details) {
                    Object prop = e.getProperty(det);
                    String toStr = ((CGAEField) f)
                        .getObjectText2(e, prop);
                    sb.append(toStr);
                    if (ch != details.length - 1) {
                      sb.append(":");
                    }
                    ch++;
                  }
                  res = sb.toString();
                } else {
                  res = e.getKey().toString();
                }
                return res;
              }
            });
          }
        } else {
          property = "";// <empty>
        }
      } else {
        property = "";// <empty>
      }

    } else if (f instanceof PGAEField) {
      property = e.getProperty(f.name);
    } else {
      property = e.getProperty(f.name);
    }
    if (property instanceof Collection<?>) {
      Collection c = (Collection) property;
      boolean remove = c.remove(null);
      if (remove) {
        c.add(new NullValue());
      }
    }
    binding.setValue(property, null);
    v.setBinding(binding);
    v.setLayoutData(GridDataFactory.fillDefaults().grab(true, true)
        .create());
    m.add(v);
    if (needIndexable) {
View Full Code Here

                }
              });// ((Collection)((HashMap)facade.getChildren().get(cgf.getKeyKind())).get(e.getKey()));

            } else {
              Object firstElement = null;
              Binding bnd = new Binding(firstElement);
              bnd.setName("Edit");
              CompositeEditor m = new CompositeEditor(bnd);
              m.setLayoutManager(new HorizontalLayouter());
              TitledDialog dlg = new TitledDialog(m);
              GAEField singleField = fm.getSingleField();
              ApiProxy.setEnvironmentForCurrentThread(new FakeEnvironment(
                  e.getAppId()));
              Entity c = new Entity("A");

              if (fm instanceof CGAEField) {
                c = new Entity(fm.getKeyKind(), e.getKey());
                // Entity example =
              } else {
                c.setProperty(f.name, firstElement);
              }
              createBindings(c, m, bnd,
                  new Field[] { singleField }, facade);

              int open = dlg.open();
              if (open == Dialog.OK) {
                Object value = bnd.getBinding(f.name)
                    .getValue();
                if (value == null) {
                  value = new NullValue();
                }
                v.addValue(value);
              }
              bnd.dispose();

            }
          }
        });
        manager.add(new Action("Edit selected") {
          {
            setImageDescriptor(AbstractUIPlugin
                .imageDescriptorFromPlugin(Activator.PLUGIN_ID,
                    "/icons/text_edit.gif"));
          }

          public void run() {
            if (f instanceof CGAEField) {
              CGAEField cgf = (CGAEField) f;

              Object[] selected = v.getSelection().toArray();
              if (selected.length == 1) {
                BaseDataFacade fac = new BaseDataFacade(
                    cgf.keyKind, facade.getProject(),
                    facade.isDebug());
                fac.setNamespace(facade.getNamespace());
                DataStoreTableUI dstui = new DataStoreTableUI();
                final Entity sel = (Entity) selected[0];
                ArrayList<Entity> select = new ArrayList();
                select.add(sel);
                fac.determineFields(select);
                dstui.setFacade(fac);
                dstui.open(sel, false, new IUpdateList() {

                  public void update(Entity e) {
                    v.removeValue(sel);
                    v.addValue(e);
                  }
                });
              }
              return;
            } else {
              Object firstElement = v.getSelection()
                  .getFirstElement();
              Binding bnd = new Binding(firstElement);
              bnd.setName("Edit");
              CompositeEditor m = new CompositeEditor(bnd);
              TitledDialog dlg = new TitledDialog(m);
              GAEField singleField = fm.getSingleField();
              ApiProxy.setEnvironmentForCurrentThread(new FakeEnvironment(
                  e.getAppId()));
              Entity c = new Entity("A");
              if (firstElement instanceof NullValue) {
                c.setProperty(f.name, null);
              } else {
                c.setProperty(f.name, firstElement);
              }
              createBindings(c, m, bnd,
                  new Field[] { singleField }, facade);
              int open = dlg.open();
              if (open == Dialog.OK) {
                v.removeValue(firstElement);
                Object value = bnd.getBinding(f.name)
                    .getValue();
                if (value == null) {
                  value = new NullValue();
                }
                v.addValue(value);
              }
              bnd.dispose();
            }
          }
        });
        manager.add(new Action("Delete selected") {
          {
            setImageDescriptor(AbstractUIPlugin
                .imageDescriptorFromPlugin(Activator.PLUGIN_ID,
                    "/icons/delete.gif"));
          }

          @SuppressWarnings("unchecked")
          public void run() {
            final List selected = v.getSelection().toList();

            if (f instanceof CGAEField) {
              final CGAEField cgf = (CGAEField) f;
              BaseDataFacade fac = new BaseDataFacade(
                  cgf.keyKind, facade.getProject(), facade
                      .isDebug());
              fac.setNamespace(facade.getNamespace());
              fac.delete(selected.toArray(new Entity[selected
                  .size()]), new OperationCallback() {

                public void passed(Object object) {
                  Collection coll = (Collection) ((HashMap) facade
                      .getChildren()
                      .get(cgf.getKeyKind())).get(e
                      .getKey());
                  coll.removeAll(selected);
                  facade.updateChildren(e);
                  v.removeValues(selected);
                }

                public void failed(Exception exception) {
                  return;
                }
              });
              // facade.updateChildren(e);
            } else {
              v.removeValues(selected);
            }
          }
        });
        return manager.createControl(conComposite);
      }

    });

    v.setValueAsSelection(false);
    Binding binding = bnd.getBinding(f.name);
    binding.setReadOnly(false);
    Object property = null;
    if (f instanceof CGAEField) {

      HashMap hashMap = (HashMap) facade.getChildren().get(
          ((CGAEField) f).keyKind);
      if (hashMap != null) {
        Collection col = (Collection) (hashMap).get(e.getKey());
        if (col != null) {
          property = new ArrayList<Object>();
          for (Iterator i = col.iterator(); i.hasNext();) {
            Entity ent = (Entity) i.next();
            ((ArrayList<Object>) property).add(ent);
            v.setLabelProvider(new LabelProvider() {

              public String getText(Object element) {
                Entity e = (Entity) element;
                String res = "";

                String[] details = ((CGAEField) f)
                    .getKeyKindDetails();
                if (details != null && details.length != 0) {
                  StringBuilder sb = new StringBuilder();
                  int ch = 0;
                  for (String det : details) {
                    Object prop = e.getProperty(det);
                    String toStr = ((CGAEField) f)
                        .getObjectText2(e, prop);
                    sb.append(toStr);
                    if (ch != details.length - 1) {
                      sb.append(":");
                    }
                    ch++;
                  }
                  res = sb.toString();
                } else {
                  res = e.getKey().toString();
                }
                return res;
              }
            });
          }
        } else {
          property = new NullValue();// "<empty>";
        }
      } else {
        property = new NullValue();// "<empty>";
      }

    } else if (f instanceof PGAEField) {
      property = e.getProperty(f.name);
    } else {
      property = e.getProperty(f.name);
    }
    if (property instanceof Collection<?>) {
      Collection c = (Collection) property;
      boolean remove = c.remove(null);
      if (remove) {
        c.add(new NullValue());
      }
    }
    binding.setValue(property, null);
    v.setBinding(binding);
    v.setLayoutData(GridDataFactory.fillDefaults().grab(true, true)
        .create());
    m.add(v);
    text.add(m);
View Full Code Here

TOP

Related Classes of com.onpositive.semantic.model.binding.Binding

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.