예제 #1
0
 private void replaceContent() {
   try {
     setContentFromString(context.getTextEditor().getText());
   } catch (TermVisualizationException e) {
     ErrorDialog.openError(
         context.getTextEditor().getShell(),
         "Error Updating Element",
         "The following error has occured: " + e.getMessage(),
         Status.OK_STATUS);
   } catch (PrologException e) {
     e.printStackTrace();
   } catch (TermInstantiationException e) {
     e.printStackTrace();
   } catch (ExecutionContextException e) {
     e.printStackTrace();
   }
 }
예제 #2
0
  public void focusGained(org.eclipse.swt.events.FocusEvent event) {
    VisualTerm previousFocused = context.getFocused();
    if (previousFocused != null) previousFocused.lostFocus();
    context.setFocused(this);

    LineBorder focusBorder = new LineBorder();
    focusBorder.setStyle(Graphics.LINE_DASH);
    focusBorder.setColor(getColor());
    focusBorder.setWidth(1);
    setBorder(focusBorder);
    context.selectionChanged(this);
    if (canModify()) {
      try {
        String text = termToText();
        context.getTextEditor().setText(text);
        context.getTextEditor().setEnabled(true);
        context.getTextEditor().setSelection(0, text.length());
        context.getTextEditor().addKeyListener(this);
        context.getTextEditor().setFocus();
        Viewport viewport = ((FigureCanvas) getCanvas()).getViewport();
        Point p = viewport.getViewLocation();
        if (p.y > getLocation().y) {
          viewport.setViewLocation(new Point(p.x, getLocation().y));
        } else if (p.y + viewport.getSize().height < getLocation().y + getSize().height
            && viewport.getSize().height > getSize().height) {
          viewport.setViewLocation(
              new Point(p.x, getLocation().y + getSize().height - viewport.getSize().height));
        }
        if (p.x > getLocation().x) {
          viewport.setViewLocation(new Point(getLocation().x, p.y));
        } else if (p.x + viewport.getSize().width < getLocation().x + getSize().width
            && viewport.getSize().width > getSize().width) {
          viewport.setViewLocation(
              new Point(getLocation().x + getSize().width - viewport.getSize().width, p.y));
        }
      } catch (IOException e) {
        e.printStackTrace();
      } catch (PrologException e) {
        e.printStackTrace();
      } catch (TermInstantiationException e) {
        e.printStackTrace();
      } catch (ExecutionContextException e) {
        e.printStackTrace();
      }
    }
  }
예제 #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();
    }
  }