@Override
    public final void update(final AnActionEvent event) {
      final Presentation presentation = event.getPresentation();

      final DataContext dataContext = event.getDataContext();
      final HierarchyBrowserBaseEx browser =
          (HierarchyBrowserBaseEx) dataContext.getData(myBrowserDataKey);
      if (browser == null) {
        presentation.setVisible(false);
        presentation.setEnabled(false);
        return;
      }

      presentation.setVisible(true);

      final PsiElement selectedElement = browser.getSelectedElement();
      if (selectedElement == null || !browser.isApplicableElement(selectedElement)) {
        presentation.setEnabled(false);
        presentation.setVisible(false);
        return;
      }

      presentation.setEnabled(isEnabled(browser, selectedElement));
      String nonDefaultText = getNonDefaultText(browser, selectedElement);
      if (nonDefaultText != null) {
        presentation.setText(nonDefaultText);
      }
    }
    @Override
    public final void actionPerformed(final AnActionEvent event) {
      final DataContext dataContext = event.getDataContext();
      final HierarchyBrowserBaseEx browser =
          (HierarchyBrowserBaseEx) dataContext.getData(myBrowserDataKey);
      if (browser == null) return;

      final PsiElement selectedElement = browser.getSelectedElement();
      if (selectedElement == null || !browser.isApplicableElement(selectedElement)) return;

      final String currentViewType = browser.myCurrentViewType;
      Disposer.dispose(browser);
      final HierarchyProvider provider =
          BrowseHierarchyActionBase.findProvider(
              myProviderLanguageExtension,
              selectedElement,
              selectedElement.getContainingFile(),
              event.getDataContext());
      final HierarchyBrowser newBrowser =
          BrowseHierarchyActionBase.createAndAddToPanel(
              selectedElement.getProject(), provider, selectedElement);
      ApplicationManager.getApplication()
          .invokeLater(
              () ->
                  ((HierarchyBrowserBaseEx) newBrowser)
                      .changeView(correctViewType(browser, currentViewType)));
    }
Ejemplo n.º 3
0
 // @Test
 public void numberFunctions() throws IOException {
   ServiceLocator locator = container;
   DataContext db = locator.resolve(DataContext.class);
   LocalDate ld = LocalDate.now();
   Clicked cl = new Clicked().setDate(ld);
   db.submit(cl);
   Query<Clicked> query = db.query(Clicked.class);
   String uri = cl.getURI();
   // TODO: produces incorrect queries
   boolean found1 =
       query.anyMatch(
           it ->
               Long.valueOf(3).equals(it.getBigint()) && it.getEn() == En.A
                   || it.getURI().toUpperCase().equals(uri));
   boolean found2 =
       query.anyMatch(
           it ->
               3L >= it.getBigint() && it.getDate() == LocalDate.now()
                   || Integer.valueOf(it.getURI()).equals(Integer.valueOf(uri)));
   boolean found3 =
       query.anyMatch(
           it ->
               Long.valueOf(3).equals(it.getBigint()) && it.getEn() == En.B
                   || it.getURI().toUpperCase().equals(uri));
   En b = En.B;
   boolean found4 = query.anyMatch(it -> it.getEn() == b || it.getURI().toUpperCase().equals(uri));
   Assert.assertTrue(found1);
   Assert.assertTrue(found2);
   Assert.assertTrue(found3);
   Assert.assertTrue(found4);
 }
  public void update(final AnActionEvent event) {
    super.update(event);

    final Presentation presentation = event.getPresentation();
    final DataContext context = event.getDataContext();
    Module module = (Module) context.getData(LangDataKeys.MODULE.getName());
    PsiFile currentFile = (PsiFile) context.getData(LangDataKeys.PSI_FILE.getName());
    Editor editor = (Editor) context.getData(PlatformDataKeys.EDITOR.getName());
    // VirtualFile currentFile = (VirtualFile)
    // context.getData(PlatformDataKeys.VIRTUAL_FILE.getName());
    if (currentFile != null && editor != null) {
      boolean isSSFile =
          currentFile
              .getFileType()
              .getDefaultExtension()
              .equals(SilverStripeFileType.DEFAULT_EXTENSION);
      SelectionModel selectionModel = editor.getSelectionModel();
      String selectedText = selectionModel.getSelectedText();
      this.selectedText = selectedText;
      this.selectonModel = selectionModel;
      this.editor = editor;
      this.currentFile = currentFile;
      if (selectedText == null) {
        presentation.setEnabled(false);
      }
      if (!isSSFile) {
        presentation.setEnabled(false);
        presentation.setVisible(false);
      }
    } else {
      presentation.setEnabled(false);
      presentation.setVisible(false);
    }
  }
Ejemplo n.º 5
0
 @Override
 public <E extends T> E refreshAll(E entity) {
   EntityProxy<E> proxy = context.proxyOf(entity, false);
   synchronized (proxy.syncObject()) {
     return context.read(proxy.type().getClassType()).refreshAll(entity, proxy);
   }
 }
Ejemplo n.º 6
0
 @Test
 public void staticMemberAccess() throws IOException {
   ServiceLocator locator = container;
   DataContext db = locator.resolve(DataContext.class);
   Query<Document> query = db.query(Document.class);
   boolean found = query.anyMatch(it -> it.equals(Document.MEANING_OF_LIFE()));
   Assert.assertFalse(found);
 }
Ejemplo n.º 7
0
 @Test
 public void floatType() throws IOException {
   ServiceLocator locator = container;
   DataContext db = locator.resolve(DataContext.class);
   boolean notFound =
       db.query(Composite.class).anyMatch(it -> (float) it.getSimple().getNumber() == 4.2f);
   Assert.assertFalse(notFound);
 }
Ejemplo n.º 8
0
  /** @return the DataContext of DataHeaders */
  public DataContext storeDataHeaders() throws Exception {
    DataContext dataContext = new DataContext();
    for (int i = 0; dataHeaders != null && i < dataHeaders.length; i++) {
      dataContext.add(dataHeaderTag, ((DataHeader) dataHeaders[i]).store());
    }

    return dataContext;
  }
Ejemplo n.º 9
0
  /** @return the DataContext of the DataItems */
  public DataContext storeDataItems() {
    DataContext dataContext = new DataContext();
    for (int i = 0; dataItems != null && i < dataItems.length; i++) {
      dataContext.add(dataItemTag, ((DataItem) dataItems[i]).store());
    }

    return dataContext;
  }
Ejemplo n.º 10
0
 @Test
 public void willUseRewrittenSpecificationInSearch() throws IOException {
   ServiceLocator locator = container;
   DataContext db = locator.resolve(DataContext.class);
   LocalDate ld = LocalDate.now().plusDays(15);
   Clicked cl = new Clicked().setDate(ld);
   db.submit(cl);
   List<ClickedList> found = db.search(ClickedList.class, new ClickedList.FindAt(ld));
   Assert.assertTrue(found.size() > 0);
 }
Ejemplo n.º 11
0
 @Test
 public void willRecognizeSpecificationOnSql() throws IOException {
   ServiceLocator locator = container;
   DataContext db = locator.resolve(DataContext.class);
   LocalDate ld = LocalDate.now();
   Clicked cl = new Clicked().setDate(ld);
   db.submit(cl);
   long count = db.query(ClickedList.class).filter(new ClickedList.FindAt(ld)).count();
   Assert.assertTrue(count > 0);
 }
Ejemplo n.º 12
0
 @SuppressWarnings("unchecked")
 @Override
 public <E extends T> E refresh(E entity, Attribute<?, ?>... attributes) {
   EntityProxy<E> proxy = context.proxyOf(entity, false);
   synchronized (proxy.syncObject()) {
     return context
         .read(proxy.type().getClassType())
         .refresh(entity, proxy, (Attribute<E, ?>[]) attributes);
   }
 }
Ejemplo n.º 13
0
 @Test
 public void canUseQueryDirectly() throws IOException, ReflectiveOperationException {
   ServiceLocator locator = container;
   DataContext db = locator.resolve(DataContext.class);
   LocalDate ld = LocalDate.now().plusDays(15);
   Clicked cl = new Clicked().setDate(ld);
   db.submit(cl);
   List<ClickedList> found =
       locator.resolve(Query.class, ClickedList.class).filter(new ClickedList.FindAt(ld)).list();
   Assert.assertTrue(found.size() > 0);
 }
Ejemplo n.º 14
0
 @Override
 public <E extends T> Void delete(E entity) {
   try (TransactionScope transaction = new TransactionScope(transactionProvider)) {
     EntityProxy<E> proxy = context.proxyOf(entity, true);
     synchronized (proxy.syncObject()) {
       context.write(proxy.type().getClassType()).delete(entity, proxy);
       transaction.commit();
     }
   }
   return null;
 }
Ejemplo n.º 15
0
 @SuppressWarnings("unchecked")
 @Override
 public <E extends T> Iterable<E> refresh(Iterable<E> entities, Attribute<?, ?>... attributes) {
   Iterator<E> iterator = entities.iterator();
   if (iterator.hasNext()) {
     E entity = iterator.next();
     EntityProxy<E> proxy = context.proxyOf(entity, false);
     EntityReader<E, T> reader = context.read(proxy.type().getClassType());
     return reader.batchRefresh(entities, (Attribute<E, ?>[]) attributes);
   }
   return entities;
 }
Ejemplo n.º 16
0
  /** Stores a DataSet into a DataContext */
  public DataContext store() throws Exception {

    DataContext dataContext = new DataContext();

    dataContext.add(new NodePair(titleTag, this.title));

    dataContext.add(dataHeadersTag, storeDataHeaders());

    dataContext.add(dataItemsTag, storeDataItems());

    return dataContext;
  }
Ejemplo n.º 17
0
 @Override
 public <E extends T> E upsert(E entity) {
   try (TransactionScope transaction = new TransactionScope(transactionProvider)) {
     EntityProxy<E> proxy = context.proxyOf(entity, true);
     synchronized (proxy.syncObject()) {
       EntityWriter<E, T> writer = context.write(proxy.type().getClassType());
       writer.upsert(entity, proxy);
       transaction.commit();
       return entity;
     }
   }
 }
Ejemplo n.º 18
0
 @Test
 public void willUseRewrittenSpecificationInBulk() throws Exception {
   ServiceLocator locator = container;
   DataContext db = locator.resolve(DataContext.class);
   RepositoryBulkReader reader = locator.resolve(RepositoryBulkReader.class);
   LocalDate ld = LocalDate.now().plusDays(44);
   Clicked cl = new Clicked().setDate(ld).setNumber(BigDecimal.valueOf(111));
   db.submit(cl);
   Callable<List<ClickedSeq>> found =
       reader.search(ClickedSeq.class, new ClickedSeq.OnDateOrNumber(ld, 111));
   reader.execute();
   Assert.assertTrue(found.call().size() > 0);
 }
Ejemplo n.º 19
0
 // @Test
 public void nestedSubqueryWithStream() throws IOException {
   ServiceLocator locator = container;
   DataContext db = locator.resolve(DataContext.class);
   // TODO: does not work yet
   boolean notFound =
       db.query(Composite.class)
           .anyMatch(
               it ->
                   it.getEntities()
                       .stream()
                       .anyMatch(e -> e.getDetail1().stream().anyMatch(d -> d.getFf() == 4.2f)));
   Assert.assertFalse(notFound);
 }
Ejemplo n.º 20
0
 @Override
 public <E extends T> Void delete(Iterable<E> entities) {
   Iterator<E> iterator = entities.iterator();
   if (iterator.hasNext()) {
     try (TransactionScope transaction = new TransactionScope(transactionProvider)) {
       E entity = iterator.next();
       EntityProxy<E> proxy = context.proxyOf(entity, false);
       EntityWriter<E, T> writer = context.write(proxy.type().getClassType());
       writer.delete(entities);
       transaction.commit();
     }
   }
   return null;
 }
Ejemplo n.º 21
0
 @SuppressWarnings("unchecked")
 @Override
 public <E extends T> E update(E entity, Attribute<?, ?>... attributes) {
   try (TransactionScope transaction = new TransactionScope(transactionProvider)) {
     EntityProxy<E> proxy = context.proxyOf(entity, true);
     synchronized (proxy.syncObject()) {
       context
           .write(proxy.type().getClassType())
           .update(entity, proxy, (Attribute<E, ?>[]) attributes);
       transaction.commit();
       return entity;
     }
   }
 }
  private static boolean isEnabled(DataContext dataContext) {
    Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (project == null
        || EditorGutter.KEY.getData(dataContext) != null
        || Boolean.TRUE.equals(dataContext.getData(CommonDataKeys.EDITOR_VIRTUAL_SPACE))) {
      return false;
    }

    Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
    if (editor == null) {
      UsageTarget[] target = UsageView.USAGE_TARGETS_KEY.getData(dataContext);
      return target != null && target.length > 0;
    } else {
      PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
      if (file == null) {
        return false;
      }

      Language language = PsiUtilBase.getLanguageInEditor(editor, project);
      if (language == null) {
        language = file.getLanguage();
      }
      return !(LanguageFindUsages.INSTANCE.forLanguage(language)
          instanceof EmptyFindUsagesProvider);
    }
  }
Ejemplo n.º 23
0
 @Override
 public <K, E extends T> Iterable<K> insert(Iterable<E> entities, @Nullable Class<K> keyClass) {
   Iterator<E> iterator = entities.iterator();
   if (iterator.hasNext()) {
     try (TransactionScope transaction = new TransactionScope(transactionProvider)) {
       E entity = iterator.next();
       EntityProxy<E> proxy = context.proxyOf(entity, true);
       EntityWriter<E, T> writer = context.write(proxy.type().getClassType());
       GeneratedKeys<E> keys = writer.batchInsert(entities, keyClass != null);
       transaction.commit();
       @SuppressWarnings("unchecked")
       Iterable<K> result = (Iterable<K>) keys;
       return result;
     }
   }
   return null;
 }
Ejemplo n.º 24
0
 @Test
 public void offsetDateTimeFunctions() throws IOException {
   ServiceLocator locator = container;
   DataContext db = locator.resolve(DataContext.class);
   Clicked cl = new Clicked();
   db.submit(cl);
   Query<Clicked> query = db.query(Clicked.class);
   OffsetDateTime dt = cl.getQueuedAt();
   boolean found =
       query.anyMatch(
           it -> it.getURI().equals(cl.getURI()) && it.getProcessedAt().compareTo(dt) == 0);
   boolean notFound =
       query.anyMatch(
           it -> it.getURI().equals(cl.getURI()) && it.getProcessedAt().compareTo(dt) != 0);
   Assert.assertTrue(found);
   Assert.assertFalse(notFound);
 }
Ejemplo n.º 25
0
  /**
   * Loads a DataSet from a DataContext
   *
   * @throws UnsupportedDataContextException
   */
  public void load(DataContext dataSetContext) throws Exception {

    try {
      this.title = (String) dataSetContext.getElements2(titleTag).get(0);
    } catch (Exception e) {
      this.title = "defaultRelation";
    }

    DataContext dataHeadersContext = dataSetContext.getNode(dataHeadersTag);

    loadDataHeaders(dataHeadersContext);

    DataContext dataItemsContext = dataSetContext.getNode(dataItemsTag);

    loadDataItems(dataItemsContext);

    DataContext virtualHeadersContext = dataSetContext.getNode(virtualHeadersTag);
  }
Ejemplo n.º 26
0
 /** Returns a {@link Queryable}, given a fully-qualified table name. */
 public static <E> Queryable<E> queryable(DataContext root, Class<E> clazz, String... names) {
   SchemaPlus schema = root.getRootSchema();
   for (int i = 0; i < names.length - 1; i++) {
     String name = names[i];
     schema = schema.getSubSchema(name);
   }
   final String tableName = names[names.length - 1];
   return queryable(root, schema, clazz, tableName);
 }
Ejemplo n.º 27
0
 @Override
 public <K, E extends T> K insert(E entity, @Nullable Class<K> keyClass) {
   try (TransactionScope transaction = new TransactionScope(transactionProvider)) {
     EntityProxy<E> proxy = context.proxyOf(entity, true);
     synchronized (proxy.syncObject()) {
       EntityWriter<E, T> writer = context.write(proxy.type().getClassType());
       GeneratedKeys<E> key = null;
       if (keyClass != null) {
         key = new GeneratedKeys<>(proxy.type().isImmutable() ? null : proxy);
       }
       writer.insert(entity, proxy, key);
       transaction.commit();
       if (key != null && key.size() > 0) {
         return keyClass.cast(key.get(0));
       }
     }
   }
   return null;
 }
Ejemplo n.º 28
0
 @Override
 public Object getData(@NonNls String dataId) {
   if (MPSCommonDataKeys.NODE.getName().equals(dataId)) {
     return mySelectedNode;
   }
   if (MPSEditorDataKeys.EDITOR_CELL.getName().equals(dataId)) {
     return myNodeCell;
   }
   return myEditorDataContext.getData(dataId);
 }
Ejemplo n.º 29
0
 @Test
 public void localDateFunctions() throws IOException {
   ServiceLocator locator = container;
   DataContext db = locator.resolve(DataContext.class);
   LocalDate ld = LocalDate.now();
   Clicked cl = new Clicked().setDate(ld);
   db.submit(cl);
   Query<Clicked> query = db.query(Clicked.class);
   String uri = cl.getURI();
   boolean found1 =
       query.anyMatch(it -> it.getURI().equals(uri) && ld.compareTo(it.getDate()) == 0);
   boolean found2 =
       query.anyMatch(
           it -> it.getURI().equals(uri) && ld.equals(it.getDate()) && ld.isEqual(it.getDate()));
   boolean notFound =
       query.anyMatch(it -> it.getURI().equals(uri) && ld.compareTo(it.getDate()) != 0);
   Assert.assertTrue(found1);
   Assert.assertTrue(found2);
   Assert.assertFalse(notFound);
 }
Ejemplo n.º 30
0
 @Override
 public <E extends T> Insertion<? extends Result<Tuple>> insert(Class<E> type) {
   checkClosed();
   Type<E> entityType = context.getModel().typeOf(type);
   Set<Expression<?>> keySelection = new LinkedHashSet<>();
   for (Attribute<E, ?> attribute : entityType.getKeyAttributes()) {
     keySelection.add((Expression<?>) attribute);
   }
   InsertReturningOperation operation = new InsertReturningOperation(context, keySelection);
   return new QueryElement<>(INSERT, entityModel, operation).from(type);
 }