Ejemplo n.º 1
0
  /**
   * Checks if data can be updated.
   *
   * @param n node instance
   * @param no disallowed node types
   * @return result of check
   */
  static boolean updatable(final Nodes n, final int... no) {
    if (n == null || (no.length == 0 ? n.size() < 1 : n.size() != 1)) return false;

    final int k = n.data.kind(n.pres[0]);
    for (final int i : no) if (k == i) return false;
    return true;
  }
Ejemplo n.º 2
0
 @Override
 public void refreshMark() {
   final EditorArea edit = getEditor();
   go.setEnabled(edit.script || edit.xquery && !gui.gprop.is(GUIProp.EXECRT));
   final Nodes mrk = gui.context.marked;
   filter.setEnabled(!gui.gprop.is(GUIProp.FILTERRT) && mrk != null && mrk.size() != 0);
 }
Ejemplo n.º 3
0
 /**
  * Notifies all views of a selection change.
  *
  * @param mark marked nodes
  * @param vw the calling view
  */
 public void mark(final Nodes mark, final View vw) {
   final Context ctx = gui.context;
   ctx.marked = mark;
   for (final View v : view) if (v != vw && v.visible()) v.refreshMark();
   gui.filter.setEnabled(mark.size() != 0);
   gui.refreshControls();
 }
Ejemplo n.º 4
0
 @Override
 public void execute(final GUI gui) {
   final Context ctx = gui.context;
   Nodes marked = ctx.marked;
   if (marked.size() == 0) {
     final int pre = gui.context.focused;
     if (pre == -1) return;
     marked = new Nodes(pre, ctx.data());
   }
   gui.notify.context(marked, false, null);
 }
Ejemplo n.º 5
0
 @Override
 public void execute(final GUI gui) {
   final StringBuilder sb = new StringBuilder();
   final Nodes n = gui.context.copied;
   for (int i = 0; i < n.size(); ++i) {
     if (i > 0) sb.append(',');
     sb.append(openPre(n, i));
   }
   gui.context.copied = null;
   gui.execute(new XQuery("insert nodes (" + sb + ") into " + openPre(gui.context.marked, 0)));
 }
Ejemplo n.º 6
0
 @Override
 public void execute(final GUI gui) {
   if (!BaseXDialog.confirm(gui, DELETE_NODES)) return;
   final StringBuilder sb = new StringBuilder();
   final Nodes n = gui.context.marked;
   for (int i = 0; i < n.size(); ++i) {
     if (i > 0) sb.append(',');
     sb.append(openPre(n, i));
   }
   gui.context.marked = new Nodes(n.data);
   gui.context.copied = null;
   gui.context.focused = -1;
   gui.execute(new XQuery("delete nodes (" + sb + ')'));
 }
Ejemplo n.º 7
0
  public void loadLocationsAsync(String kml) {
    List<LotLocation> locations = new ArrayList<LotLocation>();

    try {
      XMLReader parser = XMLReaderFactory.createXMLReader("org.ccil.cowan.tagsoup.Parser");
      InputStream is = new ByteArrayInputStream(kml.getBytes());

      // build out an XML document using TagSoup
      Document doc = new Builder(parser).build(is);

      // set the ns of the document as the XPathContext or we will not find the elements when we
      // attempt to parse
      XPathContext context = new XPathContext("ns", "http://www.w3.org/1999/xhtml");

      // get the Placemark nodes within the data
      Nodes nodes = doc.query(".//ns:Placemark", context);

      for (int index = 0; index < nodes.size(); index++) {
        LotLocation placemark = new LotLocation();
        Node placemarkNode = nodes.get(index);

        Node nameNode = placemarkNode.query("ns:name", context).get(0);
        if (nameNode != null) placemark.setLocation(nameNode.getValue());

        Node descriptionNode = placemarkNode.query("ns:description", context).get(0);
        if (descriptionNode != null) placemark.setDescription(descriptionNode.getValue());

        Node lnglatNode = placemarkNode.query("ns:Point/ns:coordinates", context).get(0);
        if (lnglatNode != null) {
          // get longitude,latitude,altitude, per KML spec
          String[] points = lnglatNode.getValue().split(",");
          placemark.setPoint(
              new LatLng(
                  Double.parseDouble(points[1].trim()), Double.parseDouble(points[0].trim())));
        }

        locations.add(placemark);
      }

      // spin off a new thread and load locations
      new LoadLocationsTask().execute(locations);

    } catch (Exception e) {
      Log.e("LoadLocationsTask", "Failure attempting to load locations", e);
    }
  }
Ejemplo n.º 8
0
 @Override
 public void refresh(final GUI gui, final AbstractButton b) {
   final Nodes marked = gui.context.marked;
   b.setEnabled(marked != null && marked.size() != 0);
 }
Ejemplo n.º 9
0
 @Override
 public void refresh(final GUI gui, final AbstractButton b) {
   // disallow copy of empty node set or root node
   final Nodes marked = gui.context.marked;
   b.setEnabled(marked != null && marked.size() != 0);
 }