コード例 #1
0
  @Override
  public void run() {
    if (!MessageDialog.openConfirm(
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
        getText(),
        "Are you sure you want to delete?")) {
      return;
    }

    for (SimpleUserNode node : viewer.getSelectedTreeNodes()) {
      SimpleUserNode project = node.getAncestorOfType(ServoyProject.class);
      if (project == null) {
        continue;
      }

      Pair<Solution, String> pair = (Pair<Solution, String>) node.getRealObject();
      String scopeName = pair.getRight();

      WorkspaceFileAccess wsfa =
          new WorkspaceFileAccess(
              ((IProjectNature) project.getRealObject()).getProject().getWorkspace());
      String scriptPath =
          SolutionSerializer.getRelativePath(
                  ((((ServoyProject) project.getRealObject()).getSolution())), false)
              + scopeName
              + SolutionSerializer.JS_FILE_EXTENSION;
      try {
        wsfa.delete(scriptPath);
      } catch (IOException e) {
        ServoyLog.logError(
            "Could not delete scope '" + scopeName + "' from project '" + project.getName() + "'",
            e);
      }
    }
  }
コード例 #2
0
  public static void loadMethodTemplatesFromXML() {
    synchronized (ClientMethodTemplatesLoader.getLock()) {
      // even if it was loaded before with
      // "ClientMethodTemplatesLoader.loadClientMethodTemplatesIfNeeded" we must load the XML, as we
      // are in developer and we need all the method template info
      ClientMethodTemplatesLoader.setLoaded();

      InputStream is = MethodTemplatesLoader.class.getResourceAsStream("doc/methodtemplates.xml");
      try {
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = builder.parse(is);
        Element rootElement = doc.getDocumentElement();
        NodeList eventElements = rootElement.getElementsByTagName("event");
        int counter = 0;
        for (int i = 0; i < eventElements.getLength(); i++) {
          Element eventElem = (Element) eventElements.item(i);
          String name = eventElem.getAttribute("name");
          NodeList templElements = eventElem.getElementsByTagName("methodtemplate");
          if (templElements.getLength() > 0) {
            Element methTempl = (Element) templElements.item(0);
            MethodTemplate mt = MethodTemplate.fromXML(methTempl);
            MethodTemplate.COMMON_TEMPLATES.put(name, mt);
            counter++;
          }
        }
        System.out.println("Loaded " + counter + " method templates.");
      } catch (Throwable e) {
        ServoyLog.logError("Exception while loading method templates.", e);
      }
    }
  }
コード例 #3
0
 public void setPaletteCustomization(PaletteCustomization prefs) {
   try {
     JSONObject jsonObject = null;
     if (prefs != null) {
       jsonObject = new JSONObject();
       if (prefs.drawers != null) {
         jsonObject.put(PaletteCustomization.DRAWERS, prefs.drawers);
       }
       if (prefs.drawerEntries != null && prefs.drawerEntries.size() > 0) {
         jsonObject.put(PaletteCustomization.DRAWER_ENTRIES, prefs.drawerEntries);
       }
       if (prefs.entryProperties != null && prefs.entryProperties.size() > 0) {
         jsonObject.put(PaletteCustomization.ENTRY_PROPERTIES, prefs.entryProperties);
       }
     }
     if (jsonObject != null && jsonObject.keys().hasNext()) {
       setProperty(
           PALETTE_CUSTOMIZATION_SETTING,
           ServoyJSONObject.toString(jsonObject, false, false, false));
     } else {
       removeProperty(PALETTE_CUSTOMIZATION_SETTING);
     }
   } catch (JSONException e) {
     ServoyLog.logError("Could not save palette preferences", e);
   }
 }
コード例 #4
0
  public void saveCoolbarLayout(CoolbarLayout coolbarLayout) {
    if (coolbarLayout == null) {
      removeProperty(FORM_COOLBAR_LAYOUT_SETTING);
    } else {
      Map<String, Object> map = new HashMap<String, Object>();
      if (coolbarLayout.itemOrder.length > 0) map.put("itemOrder", coolbarLayout.itemOrder);
      if (coolbarLayout.wrapIndices.length > 0) map.put("wrapIndices", coolbarLayout.wrapIndices);
      if (coolbarLayout.hiddenBars.length > 0) map.put("hiddenBars", coolbarLayout.hiddenBars);
      if (coolbarLayout.ids.length > 0) map.put("ids", coolbarLayout.ids);
      if (coolbarLayout.sizes.length > 0) {
        int[] sizesX = new int[coolbarLayout.sizes.length];
        int[] sizesY = new int[coolbarLayout.sizes.length];
        for (int i = 0; i < coolbarLayout.sizes.length; i++) {
          sizesX[i] = coolbarLayout.sizes[i].x;
          sizesY[i] = coolbarLayout.sizes[i].y;
        }
        map.put("sizesX", sizesX);
        map.put("sizesY", sizesY);
      }

      JSONSerializer serializer = new JSONSerializer();
      try {
        serializer.registerDefaultSerializers();
        setProperty(FORM_COOLBAR_LAYOUT_SETTING, serializer.toJSON(map));
      } catch (Exception e) {
        ServoyLog.logError(e);
      }
    }
    save();
  }
コード例 #5
0
 public void save() {
   try {
     eclipsePreferences.flush();
   } catch (BackingStoreException e) {
     ServoyLog.logError(e);
   }
 }
コード例 #6
0
 public PaletteCustomization getPaletteCustomization() {
   String property = getProperty(PALETTE_CUSTOMIZATION_SETTING, null);
   if (property != null) {
     try {
       Map map = (Map) ServoyJSONObject.toJava(new ServoyJSONObject(property, false));
       return new PaletteCustomization(
           (List<String>) map.get(PaletteCustomization.DRAWERS),
           (Map<String, List<String>>) map.get(PaletteCustomization.DRAWER_ENTRIES),
           (Map<String, Object>) map.get(PaletteCustomization.ENTRY_PROPERTIES));
     } catch (JSONException e) {
       ServoyLog.logError("Could not read palette preferences", e);
     }
   }
   return null;
 }
コード例 #7
0
  public void run(IMarker marker) {
    if (uuid == null) return;

    UUID id = UUID.fromString(uuid);
    ServoyProject servoyProject =
        ServoyModelManager.getServoyModelManager().getServoyModel().getServoyProject(solutionName);
    if (servoyProject == null) return;

    try {
      IPersist persist = servoyProject.getEditingPersist(id);
      if (persist == null) return;

      IPersist parent = persist.getAncestor(parentTypeId);
      if (parent == null && parentTypeId == IRepository.TABLENODES && dataSource != null) {
        parent = servoyProject.getEditingSolution().getOrCreateTableNode(dataSource);
      }
      if (parent == null) return;

      MethodTemplate template = MethodTemplate.getTemplate(ScriptMethod.class, eventName);
      if (template == null) return;

      MethodArgument signature = template.getSignature();
      if (signature == null) return;

      Map<String, String> substitutions = null;
      if (dataSource != null) substitutions = Collections.singletonMap("dataSource", dataSource);
      ScriptMethod method =
          NewMethodAction.createNewMethod(
              UIUtils.getActiveShell(),
              parent,
              eventName,
              true,
              null,
              null,
              substitutions,
              null,
              null);
      if (method != null) {
        PropertyDescriptor descriptor = new PropertyDescriptor(eventName, persist.getClass());
        descriptor.getWriteMethod().invoke(persist, new Integer(method.getID()));
        servoyProject.saveEditingSolutionNodes(new IPersist[] {parent}, true);
      }
    } catch (Exception e) {
      ServoyLog.logError(e);
    }
  }
コード例 #8
0
 public void run(IMarker marker) {
   if (solutionName != null) {
     ServoyProject servoyProject =
         ServoyModelManager.getServoyModelManager()
             .getServoyModel()
             .getServoyProject(solutionName);
     if (servoyProject != null) {
       Solution solution = servoyProject.getEditingSolution();
       if (solution != null) {
         solution.setSolutionType(SolutionMetaData.WEB_CLIENT_ONLY);
         try {
           servoyProject.saveEditingSolutionNodes(new IPersist[] {solution}, false);
         } catch (RepositoryException e) {
           ServoyLog.logError(e);
         }
       }
     }
   }
 }
コード例 #9
0
  public CoolbarLayout getCoolbarLayout() {
    String property = getProperty(FORM_COOLBAR_LAYOUT_SETTING, null);
    if (property != null) {
      JSONSerializer serializer = new JSONSerializer();
      try {
        serializer.registerDefaultSerializers();
        Map map = (Map) serializer.fromJSON(property);

        Integer[] ints = (Integer[]) map.get("itemOrder");

        int[] itemOrder = new int[ints == null ? 0 : ints.length];
        for (int i = 0; i < itemOrder.length; i++) {
          itemOrder[i] = ints[i].intValue();
        }

        ints = (Integer[]) map.get("wrapIndices");
        int[] wrapIndices = new int[ints == null ? 0 : ints.length];
        for (int i = 0; i < wrapIndices.length; i++) {
          wrapIndices[i] = ints[i].intValue();
        }
        Integer[] sizesX = (Integer[]) map.get("sizesX");
        Integer[] sizesY = (Integer[]) map.get("sizesY");
        Point[] sizes = new Point[sizesX == null ? 0 : sizesX.length];
        for (int i = 0; i < sizesX.length; i++) {
          sizes[i] = new Point(sizesX[i].intValue(), sizesY[i].intValue());
        }
        String[] hiddenBars = (String[]) map.get("hiddenBars");
        String[] ids = (String[]) map.get("ids");
        return new CoolbarLayout(
            itemOrder,
            wrapIndices,
            sizes,
            hiddenBars == null ? new String[0] : hiddenBars,
            ids == null ? new String[0] : ids);
      } catch (Exception e) {
        ServoyLog.logError(e);
      }
    }
    return null;
  }
コード例 #10
0
    public List<RelationData> loadData(IServerInternal server, IProgressMonitor monitor) {
      List<RelationData> relations = new ArrayList<RelationData>();
      try {
        List<String> tableNames = server.getTableAndViewNames(true, true);
        // plus 1 for sorting at the end
        monitor.beginTask("Loading relations", tableNames.size() + 1);
        for (String tableName : tableNames) {
          if (isCanceled()) {
            return null;
          }
          Table table = server.getTable(tableName);
          Connection connection = null;
          ResultSet resultSet = null;
          try {
            connection = server.getConnection();
            DatabaseMetaData dbmd = connection.getMetaData();
            Map<String, List<List<String[]>>> relationInfo =
                new HashMap<String, List<List<String[]>>>();

            resultSet =
                dbmd.getExportedKeys(
                    server.getConfig().getCatalog(),
                    server.getConfig().getSchema(),
                    table.getSQLName());
            while (resultSet.next()) {
              String pcolumnName = resultSet.getString("PKCOLUMN_NAME");
              String ftableName = resultSet.getString("FKTABLE_NAME");
              String fcolumnName = resultSet.getString("FKCOLUMN_NAME");
              String fkname = resultSet.getString("FK_NAME");

              String relname = fkname;
              if (relname == null) relname = table.getSQLName() + "_to_" + ftableName;

              int keySeq = resultSet.getInt("KEY_SEQ");
              Debug.trace(
                  "Found (export) rel: name: "
                      + relname
                      + "  keyseq = "
                      + keySeq
                      + ' '
                      + table.getSQLName()
                      + ' '
                      + pcolumnName
                      + " -> "
                      + ftableName
                      + ' '
                      + fcolumnName);

              List<List<String[]>> rel_items_list = relationInfo.get(relname);
              if (rel_items_list == null) {
                rel_items_list = new ArrayList<List<String[]>>();
                relationInfo.put(relname, rel_items_list);
                rel_items_list.add(new ArrayList<String[]>());
              }
              // rel_items_list is a list of items-lists, we are adding items to the last of this
              // list
              rel_items_list
                  .get(rel_items_list.size() - 1)
                  .add(
                      new String[] {
                        table.getSQLName(), pcolumnName, ftableName, fcolumnName, fkname
                      });
            }
            resultSet = Utils.closeResultSet(resultSet);

            resultSet =
                dbmd.getImportedKeys(
                    server.getConfig().getCatalog(),
                    server.getConfig().getSchema(),
                    table.getSQLName());
            int lastKeySeq = Integer.MAX_VALUE;
            List<List<String[]>> fk_rel_items_list = new ArrayList<List<String[]>>();
            while (resultSet.next()) {
              String pcolumnName = resultSet.getString("PKCOLUMN_NAME");
              String ptableName = resultSet.getString("PKTABLE_NAME");
              String fcolumnName = resultSet.getString("FKCOLUMN_NAME");

              int keySeq = resultSet.getInt("KEY_SEQ");
              Debug.trace(
                  "Found (import) rel: name: "
                      + table.getSQLName()
                      + "_to_"
                      + ptableName
                      + " keyseq = "
                      + keySeq
                      + ' '
                      + table.getSQLName()
                      + ' '
                      + pcolumnName
                      + " -> "
                      + ptableName
                      + ' '
                      + fcolumnName);

              // assume KEY_SEQ ascending ordered, do not assume 0 or 1 based (jdbc spec is not
              // clear on this).
              // when KEY_SEQ is not increasing, we have a separate constraint between the same
              // tables.
              if (fk_rel_items_list.size() == 0 || keySeq <= lastKeySeq) {
                fk_rel_items_list.add(new ArrayList<String[]>());
              }
              lastKeySeq = keySeq;

              // add the item to the last list of rel_items_list
              fk_rel_items_list
                  .get(fk_rel_items_list.size() - 1)
                  .add(
                      new String[] {
                        table.getSQLName(), fcolumnName, ptableName, pcolumnName, null
                      });
            }

            // generate relation names for the inversed fk constraints
            for (List<String[]> rel_items_list : fk_rel_items_list) {
              String relationName = createInversedFKRelationName(table, rel_items_list);
              List<List<String[]>> rel_items = relationInfo.get(relationName);
              if (rel_items == null) {
                relationInfo.put(relationName, rel_items = new ArrayList<List<String[]>>());
              }
              rel_items.add(rel_items_list);
            }
            resultSet = Utils.closeResultSet(resultSet);

            for (Map.Entry<String, List<List<String[]>>> entry : relationInfo.entrySet()) {
              String rname = entry.getKey();
              List<List<String[]>> rel_items_list = entry.getValue();
              // we may have multiple lists of items defined for the same relation name
              for (int l = 0; l < rel_items_list.size(); l++) {
                List<Column> primaryColumns = new ArrayList<Column>();
                List<Column> foreignColumns = new ArrayList<Column>();

                for (String[] element : rel_items_list.get(l)) {
                  //									String ptableName = element[0];
                  String pcolumnName = element[1];
                  String ftableName = element[2];
                  String fcolumnName = element[3];
                  //									String fkname = element[4];

                  Table foreignTable = server.getTable(ftableName);
                  if (foreignTable == null || foreignTable.isMarkedAsHiddenInDeveloper()) continue;

                  Column primaryColumn = table.getColumn(pcolumnName);
                  Column foreignColumn = foreignTable.getColumn(fcolumnName);

                  if (primaryColumn == null || foreignColumn == null) continue;
                  primaryColumns.add(primaryColumn);
                  foreignColumns.add(foreignColumn);
                }

                if (primaryColumns.size() != 0) {
                  // postfix the relation name when there are multiple
                  String relationName = rname;
                  if (rel_items_list.size() > 1) {
                    relationName += "_" + (l + 1);
                  }

                  boolean defaultAdd =
                      ServoyModelManager.getServoyModelManager()
                              .getServoyModel()
                              .getFlattenedSolution()
                              .getRelation(relationName)
                          == null;

                  relations.add(
                      new RelationData(
                          relationName, table, primaryColumns, foreignColumns, defaultAdd));
                }
              }
            }
          } catch (RepositoryException e) {
            ServoyLog.logError(e);
          } catch (SQLException e) {
            ServoyLog.logError(e);
          } finally {
            Utils.closeResultSet(resultSet);
            Utils.closeConnection(connection);
          }
          monitor.worked(1);
        }
        monitor.done();
      } catch (RepositoryException ex) {
        ServoyLog.logError(ex);
      }
      return relations;
    }