示例#1
0
 private TermFigure createContentFigure(Object path)
     throws TermVisualizationException, TermInstantiationException {
   // Query for the annotated term's visualization
   Variable vis = new Variable();
   Compound q = Compound.createCompound("cpi#visualizeDescriptor", path, projType, vis);
   // If successful, build the GUI
   try {
     Map<Variable, Object> s = PrologProxy.instance().getSolution(q);
     return (TermFigure) TermInstantiator.instance().instantiate((Compound) s.get(vis), this);
   } catch (PrologException e) {
     throw new TermVisualizationException(e);
   }
 }
示例#2
0
  /**
   * Returns a list of proposals for auto-completion. Each proposal contains a string with the
   * textual representation of the proposal, and an alias by which this proposal is to be selected
   *
   * @param substring the string to match the beginning of the alias to be matched
   * @param pos ignored
   * @return an array of proposals
   */
  public IContentProposal[] getProposals(String substring, int pos) {
    List<IContentProposal> proposals = new ArrayList<IContentProposal>();
    try {
      Variable varCompletion = new Variable();
      Variable varAlias = new Variable();
      Iterator<Map<Variable, Object>> solutions =
          PrologProxy.instance()
              .getSolutions(
                  Compound.createCompound(
                      "cpi#autocomplete", descriptor, substring, varCompletion, varAlias));
      while (solutions.hasNext()) {
        Map<Variable, Object> solution = solutions.next();
        final String completion = (String) solution.get(varCompletion);
        final String alias = (String) solution.get(varAlias);
        proposals.add(
            new IContentProposal() {

              public String getContent() {
                return completion;
              }

              public int getCursorPosition() {
                int pos;
                for (pos = 0; pos < completion.length(); pos++) {
                  if (completion.charAt(pos) == '(') return pos + 1;
                }
                return pos;
              }

              public String getDescription() {
                return null;
              }

              public String getLabel() {
                return alias + "\t[" + completion + "]";
              }
            });
      }

    } catch (PrologException e) {
      e.printStackTrace();
    }
    return proposals.toArray(new IContentProposal[] {});
  }
示例#3
0
  private void applyShortcut(int keyCode, int stateMask) {
    String key = keyDescription(keyCode, stateMask);

    // Query the command, if exists.
    Variable procVar = new Variable();
    Compound query = new Compound("cpi#shortcutKey", descriptor, key, procVar);
    try {
      Iterator<Map<Variable, Object>> solutions = PrologProxy.instance().getSolutions(query);
      while (solutions.hasNext()) {
        ExecutionContext exe = new ExecutionContext();
        exe.runProcedure((Compound) solutions.next().get(procVar));
      }
    } catch (PrologException e) {
      e.printStackTrace();
    } catch (TermInstantiationException e) {
      e.printStackTrace();
    } catch (ExecutionContextException e) {
      e.printStackTrace();
    }
  }
示例#4
0
 private void createContextMenu(MouseEvent me) throws TermInstantiationException {
   System.out.println("Right button click");
   Display display = context.getCanvas().getDisplay();
   Menu menu = new Menu(context.getCanvas().getShell(), SWT.POP_UP);
   try {
     Variable varAction = new Variable("Action");
     Iterator<Map<Variable, Object>> results =
         PrologProxy.instance()
             .getSolutions(Compound.createCompound("cpi#contextMenuEntry", descriptor, varAction));
     int count = 0;
     while (results.hasNext()) {
       Map<Variable, Object> result = (Map<Variable, Object>) results.next();
       Compound action = (Compound) result.get(varAction);
       TermInstantiator.instance().instantiate(action, menu, context);
       if (count++ > MAX_MENU_ENTRIES) {
         MenuItem errItem = new MenuItem(menu, SWT.NONE);
         errItem.setText("<too many results>");
         break;
       }
     }
   } catch (PrologException e1) {
     e1.printStackTrace();
   }
   Point absLocation = me.getLocation().getCopy();
   translateToAbsolute(absLocation);
   org.eclipse.swt.graphics.Point point =
       display.map(
           context.getCanvas(),
           null,
           new org.eclipse.swt.graphics.Point(absLocation.x, absLocation.y));
   menu.setLocation(point);
   menu.setVisible(true);
   while (!menu.isDisposed() && menu.isVisible()) {
     if (!display.readAndDispatch()) display.sleep();
   }
 }