예제 #1
0
 private String tranCH2En(String[] urls, IARESProject project) throws Exception {
   StringBuffer sb = new StringBuffer();
   IARESModuleRoot root = project.getModuleRoot(getModuleRootByCHName(urls[0], project));
   if (root != null) {
     for (int i = 1; i < urls.length; i++) {
       for (IARESModule module : root.getModules()) {
         IARESResource property = module.getARESResource(IARESModule.MODULE_PROPERTY_FILE);
         if (property != null && property.exists()) {
           try {
             ModuleProperty info = property.getInfo(ModuleProperty.class);
             if (info != null) {
               Object obj = info.getValue(ICommonModel.CNAME);
               if (obj != null) {
                 if (StringUtils.equals(urls[i], obj.toString())) {
                   sb.append("/");
                   sb.append(module.getShortName());
                   break;
                 }
               }
             }
           } catch (Exception e) {
             e.printStackTrace();
           }
         }
       }
     }
     for (String enname : urls) {
       root.getModule(enname);
     }
   }
   return sb.toString();
 }
예제 #2
0
 /* (non-Javadoc)
  * @see com.hundsun.ares.studio.core.IARESModule#findResource(java.lang.String, java.lang.String)
  */
 public IARESResource findResource(String name, String type) {
   for (IARESResource res : getARESResources()) {
     if (res.getName().equalsIgnoreCase(name) && res.getType().equalsIgnoreCase(type)) {
       return res;
     }
   }
   return null;
 }
 /* (non-Javadoc)
  * @see com.hundsun.ares.studio.reference.IReferenceInfoProvider#getReferenceInfos(com.hundsun.ares.studio.core.IARESResource, java.util.Map)
  */
 @Override
 public List<ReferenceInfo> getReferenceInfos(
     IARESResource resource, Map<Object, Object> context) {
   List<ReferenceInfo> infoList = new ArrayList<ReferenceInfo>();
   ReferenceInfo info = ReferenceFactory.eINSTANCE.createReferenceInfo();
   info.setRefName(resource.getFullyQualifiedName());
   info.setRefType(ResourceTypeMapping.getInstance().getReferenceType(resource.getType()));
   info.setRefNamespace(StringUtils.EMPTY);
   info.setResource(resource);
   info.setObjectProvider(ARESResourceObjectProvider.INSTANCE);
   infoList.add(info);
   return infoList;
 }
예제 #4
0
 public static List<IAction> getSampleActions(
     ColumnViewer viewer, EditingDomain editingDomain, EObject info, IARESResource res) {
   IARESProject project = res.getARESProject();
   if (info instanceof ConstantList) {
     return getConstantSampleAction(viewer, editingDomain, (ConstantList) info, project);
   }
   if (info instanceof BusinessDataTypeList) {
     return getBizSampleAction(viewer, editingDomain, (BusinessDataTypeList) info, project);
   }
   if (info instanceof DictionaryList) {
     return getDicSampleAction(viewer, editingDomain, (DictionaryList) info, project);
   }
   if (info instanceof ErrorNoList) {
     return getErrorSampleAction(viewer, editingDomain, (ErrorNoList) info, project);
   }
   if (info instanceof StandardDataTypeList) {
     return getStdTypeSampleAction(viewer, editingDomain, (StandardDataTypeList) info, project);
   }
   if (info instanceof StandardFieldList) {
     return getStdfldSampleAction(viewer, editingDomain, (StandardFieldList) info, project);
   }
   if (info instanceof TypeDefaultValueList) {
     return getDefvalueSampleAction(viewer, editingDomain, (TypeDefaultValueList) info, project);
   }
   if (info instanceof MenuList) {
     return getMenuSampleAction(viewer, editingDomain, (MenuList) info, project);
   }
   return new ArrayList<IAction>();
 }
 protected String getParameterDefaultValue(String defValue, StandardField field) {
   if (StringUtils.isBlank(defValue)) {
     try {
       TypeDefaultValue tdv =
           MetadataServiceProvider.getTypeDefaultValueOfStdFieldByName(project, field.getName());
       if (tdv != null) {
         if (resource != null && StringUtils.equals(resource.getType(), "procedure")) {
           String dt =
               (String)
                   ((ARESProjectProperty) project.getProjectProperty())
                       .getProperties()
                       .get("dbType");
           if (StringUtils.isNotBlank(dt)) {
             return tdv.getData().get(dt.toLowerCase());
           }
         } else {
           return tdv.getData().get(dataType);
         }
       }
     } catch (Exception e) {
       // e.printStackTrace();
     }
   }
   return defValue;
 }
예제 #6
0
 /* (non-Javadoc)
  * @see com.hundsun.ares.studio.core.IARESModule#getNoneARESFiles()
  */
 public IFile[] getNonARESFiles() {
   List<IFile> result = new ArrayList<IFile>();
   IFolder folder = (IFolder) getResource();
   try {
     for (IResource res : folder.members()) {
       if (res.getType() == IResource.FILE) {
         IFile file = (IFile) res;
         IARESResource ares = getARESResource(file);
         if (ares == null || !ares.exists()) result.add((IFile) res);
       }
     }
   } catch (CoreException e) {
     e.printStackTrace();
   }
   return result.toArray(new IFile[0]);
 }
예제 #7
0
  /* (non-Javadoc)
   * @see com.hundsun.ares.studio.core.IARESModule#getARESResources(java.lang.String[], boolean)
   */
  public IARESResource[] getARESResources(String[] types, boolean recursion) {
    List<IARESResource> result = new ArrayList<IARESResource>();
    for (IARESResource element : getARESResources()) {
      if (isInArray(element.getType(), types)) result.add(element);
    }

    if (recursion) {
      try {
        for (IARESModule module : getSubModules()) {
          result.addAll(Arrays.asList(module.getARESResources(types)));
        }
      } catch (ARESModelException e) {
        e.printStackTrace();
      }
    }
    return result.toArray(new IARESResource[0]);
  }
  @Override
  public List<ReferenceInfo> getReferenceInfos(
      IARESResource resource, Map<Object, Object> context) {
    List<ReferenceInfo> infoList = new ArrayList<ReferenceInfo>();
    BasicResourceInfo basicInfo = null;
    try {
      basicInfo = resource.getInfo(BasicResourceInfo.class);
    } catch (ARESModelException e) {
      e.printStackTrace();
    }

    if (basicInfo != null) {
      ReferenceInfo cnameRefInfo = ReferenceFactory.eINSTANCE.createReferenceInfo();
      cnameRefInfo.setResource(resource);
      cnameRefInfo.setRefName(basicInfo.getChineseName());
      cnameRefInfo.setRefType(
          ResourceTypeMapping.getInstance().getReferenceType(resource.getType()));
      cnameRefInfo.setRefNamespace(resource.getBundle().getId());
      cnameRefInfo.setObjectProvider(ARESResourceObjectProvider.INSTANCE);
      infoList.add(cnameRefInfo);
    }
    return infoList;
  }
  /* (non-Javadoc)
   * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
   */
  @Override
  protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    tableViewer =
        CheckboxTableViewer.newCheckList(
            composite, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL);
    tableViewer.getTable().setLinesVisible(true);
    tableViewer.getTable().setHeaderVisible(true);

    GridDataFactory.swtDefaults()
        .hint(-1, 200)
        .grab(true, true)
        .align(SWT.FILL, SWT.FILL)
        .applyTo(tableViewer.getTable());
    tableViewer.addDoubleClickListener(
        new IDoubleClickListener() {

          @Override
          public void doubleClick(DoubleClickEvent event) {
            IStructuredSelection sel = (IStructuredSelection) event.getSelection();
            if (!sel.isEmpty()) {
              Object element = sel.getFirstElement();
              tableViewer.setChecked(element, !tableViewer.getChecked(element));
            }
          }
        });

    tableViewer.addFilter(
        new ViewerFilter() {

          @Override
          public boolean select(Viewer viewer, Object parentElement, Object element) {
            TableColumn column = (TableColumn) element;
            if (indexs instanceof List) {
              List<TableIndexColumn> inds = (List<TableIndexColumn>) indexs;
              for (TableIndexColumn indexColumn : inds) {
                if (column.getName().equals(indexColumn.getColumnName())) {
                  return false;
                }
              }
            }

            //				EList<TableIndexColumn> indexColumns = index.getColumns();
            //				column.getName() not in index.getColumns()
            return true;
          }
        });
    tableViewer.setContentProvider(
        new ReferenceContentProvider(DatabasePackage.Literals.TABLE_RESOURCE_DATA__COLUMNS));

    // 字段名
    {
      EAttribute attribute = DatabasePackage.Literals.TABLE_COLUMN__FIELD_NAME;

      final TableViewerColumn tvColumn = new TableViewerColumn(tableViewer, SWT.LEFT);
      tvColumn.getColumn().setWidth(100);
      tvColumn.getColumn().setText("字段名");

      EObjectColumnLabelProvider provider = new EObjectColumnLabelProvider(attribute);
      tvColumn.setLabelProvider(provider);
    }
    // 重命名
    {
      EAttribute attribute = DatabasePackage.Literals.TABLE_COLUMN__COLUMN_NAME;

      final TableViewerColumn tvColumn = new TableViewerColumn(tableViewer, SWT.LEFT);
      tvColumn.getColumn().setWidth(100);
      tvColumn.getColumn().setText("重命名");

      EObjectColumnLabelProvider provider = new EObjectColumnLabelProvider(attribute);
      tvColumn.setLabelProvider(provider);
    }

    // 中文名
    {
      final TableViewerColumn tvColumn = new TableViewerColumn(tableViewer, SWT.LEFT);
      tvColumn.getColumn().setWidth(100);
      tvColumn.getColumn().setText("中文名");

      TableColumnRefLabelProvider provider =
          new TableColumnRefLabelProvider(
              resource.getBundle(), TableColumnRefLabelProvider.TYPE.ChineseName);
      tvColumn.setLabelProvider(provider);
    }
    // 字段类型
    {
      final TableViewerColumn tvColumn = new TableViewerColumn(tableViewer, SWT.LEFT);
      tvColumn.getColumn().setWidth(100);
      tvColumn.getColumn().setText("字段类型");

      EAttribute attribute = DatabasePackage.Literals.TABLE_COLUMN__DATA_TYPE;
      TableColumnLabelProvider provider = new TableColumnLabelProvider(attribute, resource);
      tvColumn.setLabelProvider(provider);
    }
    // 是否主键
    {
      EAttribute attribute = DatabasePackage.Literals.TABLE_COLUMN__PRIMARY_KEY;

      final TableViewerColumn tvColumn = new TableViewerColumn(tableViewer, SWT.LEFT);
      tvColumn.getColumn().setWidth(100);
      tvColumn.getColumn().setText("是否主键");

      CheckBoxColumnLabelProvider provider = new CheckBoxColumnLabelProvider(attribute, resource);
      tvColumn.setLabelProvider(provider);
    }
    // 是否为空
    {
      EAttribute attribute = DatabasePackage.Literals.TABLE_COLUMN__NULLABLE;

      final TableViewerColumn tvColumn = new TableViewerColumn(tableViewer, SWT.LEFT);
      tvColumn.getColumn().setWidth(100);
      tvColumn.getColumn().setText("是否为空");

      CheckBoxColumnLabelProvider provider = new CheckBoxColumnLabelProvider(attribute, resource);
      tvColumn.setLabelProvider(provider);
    }

    tableViewer.setInput(info);

    return composite;
  }
  protected void createColumns(TreeViewer viewer) {
    final TreeViewer treeViewer = (TreeViewer) viewer;
    // 用于一般的列
    EObjectColumnViewerProblemView problemView = new EObjectColumnViewerProblemView(treeViewer);
    // 用于扩展列
    EObjectColumnViewerProblemView exProblemView =
        new ExtensibleModelColumnViewerProblemView(treeViewer);

    // 标记
    {
      EAttribute attribute = DatabasePackage.Literals.TABLE_COLUMN__MARK;

      final TreeViewerColumn tvColumn = new TreeViewerColumn(treeViewer, SWT.LEFT);
      tvColumn.getColumn().setWidth(90);
      tvColumn.getColumn().setText("标记");

      EObjectColumnLabelProvider provider = new TableColumnLabelProvider(attribute, resource);
      provider.setDiagnosticProvider(problemView);
      tvColumn.setLabelProvider(provider);

      tvColumn.getColumn().setMoveable(true);
    }

    // 引用的标准字段
    {
      EAttribute attribute = DatabasePackage.Literals.TABLE_COLUMN__FIELD_NAME;

      final TreeViewerColumn tvColumn = new TreeViewerColumn(treeViewer, SWT.LEFT);
      tvColumn.getColumn().setWidth(130);
      tvColumn.getColumn().setText("字段名");

      EObjectColumnLabelProvider provider = new TableColumnLabelProvider(attribute, getResource());
      provider.setDiagnosticProvider(problemView);
      tvColumn.setLabelProvider(provider);
    }

    // 中文名
    {
      final TreeViewerColumn tvColumn = new TreeViewerColumn(treeViewer, SWT.LEFT);
      tvColumn.getColumn().setWidth(100);
      tvColumn.getColumn().setText("中文名");

      TableColumnRefLabelProvider provider =
          new TableColumnRefLabelProvider(
              resource.getBundle(), TableColumnRefLabelProvider.TYPE.ChineseName) {
            @Override
            public Color getBackground(Object element) {
              if (getResource().isReadOnly()) {
                return Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
              }
              return super.getBackground(element);
            }
          };
      tvColumn.setLabelProvider(provider);
      tvColumn.getColumn().setMoveable(true);
    }
    // 字段类型
    {
      final TreeViewerColumn tvColumn = new TreeViewerColumn(treeViewer, SWT.LEFT);
      tvColumn.getColumn().setWidth(100);
      tvColumn.getColumn().setText("字段类型");

      TableColumnRefLabelProvider provider =
          new TableColumnRefLabelProvider(
              resource.getBundle(), TableColumnRefLabelProvider.TYPE.Type) {
            @Override
            public Color getBackground(Object element) {
              if (getResource().isReadOnly()) {
                return Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
              }
              return super.getBackground(element);
            }
          };
      tvColumn.setLabelProvider(provider);
      tvColumn.getColumn().setMoveable(true);
    }

    // 字段说明
    {
      final TreeViewerColumn tvColumn = new TreeViewerColumn(treeViewer, SWT.LEFT);
      tvColumn.getColumn().setWidth(150);
      tvColumn.getColumn().setText("字段说明");

      TableColumnRefLabelProvider provider =
          new TableColumnRefLabelProvider(
              resource.getBundle(), TableColumnRefLabelProvider.TYPE.Desciption) {
            @Override
            public String getToolTipText(Object element) {
              return getText(element);
            }

            @Override
            public Color getBackground(Object element) {
              if (getResource().isReadOnly()) {
                return Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
              }
              return super.getBackground(element);
            }
          };
      tvColumn.setLabelProvider(provider);
      tvColumn.getColumn().setMoveable(true);
    }

    // 默认值
    {
      EAttribute attribute = DatabasePackage.Literals.TABLE_COLUMN__DEFAULT_VALUE;

      final TreeViewerColumn tvColumn = new TreeViewerColumn(treeViewer, SWT.LEFT);
      tvColumn.getColumn().setWidth(100);
      tvColumn.getColumn().setText("默认值");

      EObjectColumnLabelProvider provider = new TableColumnLabelProvider(attribute, getResource());
      provider.setDiagnosticProvider(problemView);
      tvColumn.setLabelProvider(provider);

      tvColumn.getColumn().setMoveable(true);
    }

    // 是否为空
    {
      EAttribute attribute = DatabasePackage.Literals.TABLE_COLUMN__NULLABLE;

      final TreeViewerColumn tvColumn = new TreeViewerColumn(treeViewer, SWT.LEFT);
      tvColumn.getColumn().setWidth(80);
      tvColumn.getColumn().setText("允许空");

      CheckBoxColumnLabelProvider provider =
          new CheckBoxColumnLabelProvider(attribute, getResource()) {
            @Override
            public Color getBackground(Object element) {
              TableColumn tc = (TableColumn) element;
              // if (tc.isPrimaryKey()) {
              if (DatabaseUtils.isPrimaryKey(tc)) {
                return Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
              }
              return super.getBackground(element);
            }

            @Override
            public Image getImage(Object element) {
              TableColumn tc = (TableColumn) element;
              //					if (tc.isPrimaryKey()) {
              if (DatabaseUtils.isPrimaryKey(tc)) {
                return null;
              }
              return super.getImage(element);
            }
          };
      tvColumn.setLabelProvider(provider);
      tvColumn.getColumn().setMoveable(true);
    }

    // 备注
    {
      EAttribute attribute = DatabasePackage.Literals.TABLE_COLUMN__COMMENTS;

      final TreeViewerColumn tvColumn = new TreeViewerColumn(treeViewer, SWT.LEFT);
      tvColumn.getColumn().setWidth(150);
      tvColumn.getColumn().setText("备注");

      EObjectColumnLabelProvider provider =
          new TableColumnLabelProvider(attribute, getResource()) {

            @Override
            public String getToolTipText(Object element) {
              String text = super.getToolTipText(element);
              if (StringUtils.isBlank(text)) {
                return getText(element);
              }
              return text;
            }
          };
      provider.setDiagnosticProvider(problemView);
      tvColumn.setLabelProvider(provider);
      tvColumn.getColumn().setMoveable(true);
    }

    // 扩展信息
    ExtensibleModelUtils.createExtensibleModelTreeViewerColumns(
        treeViewer, getResource(), DatabasePackage.Literals.TABLE_COLUMN, exProblemView);
  }
  @Override
  public Color getBackground(Object element) {
    // DisplayItem 比如在接口中显示的对象的属性子节点,仅做展示用,任何属性都是只读的
    if (element instanceof DisplayItem) {
      return COLOR_GRAY;
    }

    Parameter p = (Parameter) getOwner(element);
    EStructuralFeature feature = getEStructuralFeature(element);

    switch (p.getParamType()) {
      case STD_FIELD:
        if (BizPackage.Literals.PARAMETER__NAME.equals(feature)
            || BizPackage.Literals.PARAMETER__REAL_TYPE.equals(feature)
            || BizPackage.Literals.PARAMETER__TYPE.equals(feature)
            || BizPackage.Literals.PARAMETER__DESCRIPTION.equals(feature)) {
          return COLOR_GRAY;
        }
        break;
      case NON_STD_FIELD:
        if (feature.equals(BizPackage.Literals.PARAMETER__REAL_TYPE)) return COLOR_GRAY;
        break;
      case OBJECT:
        boolean hasStdObjectList = BizUtil.hasStdObjList(project);
        if (hasStdObjectList
            && (BizPackage.Literals.PARAMETER__TYPE.equals(feature)
                || MetadataPackage.Literals.NAMED_ELEMENT__DESCRIPTION.equals(feature)
                || MetadataPackage.Literals.NAMED_ELEMENT__CHINESE_NAME.equals(feature))) {
          return COLOR_GRAY;
        }
        if (BizPackage.Literals.PARAMETER__NAME.equals(feature)
            || BizPackage.Literals.PARAMETER__REAL_TYPE.equals(feature)
            || BizPackage.Literals.PARAMETER__DESCRIPTION.equals(feature)
            || BizPackage.Literals.PARAMETER__DEFAULT_VALUE.equals(feature)) {
          return COLOR_GRAY;
        }
        break;
      case COMPONENT:
        // 组件
        if (BizPackage.Literals.PARAMETER__NAME.equals(feature)
            || BizPackage.Literals.PARAMETER__REAL_TYPE.equals(feature)
            || BizPackage.Literals.PARAMETER__DESCRIPTION.equals(feature)
            || BizPackage.Literals.PARAMETER__DEFAULT_VALUE.equals(feature)) {
          return COLOR_GRAY;
        }
        break;
      case PARAM_GROUP:
        // 参数组,只编辑类型来关联对象,其他都不可编辑
        if (BizPackage.Literals.PARAMETER__NAME.equals(feature)
            || BizPackage.Literals.PARAMETER__ID.equals(feature)
            || BizPackage.Literals.PARAMETER__REAL_TYPE.equals(feature)
            || BizPackage.Literals.PARAMETER__DESCRIPTION.equals(feature)
            || BizPackage.Literals.PARAMETER__DEFAULT_VALUE.equals(feature)) {
          return COLOR_GRAY;
        }
        break;
      default:
        break;
    }

    if (resource != null && resource.isReadOnly()) {
      return COLOR_GRAY;
    }
    return super.getBackground(element);
  }
 /**
  * @param attribute
  * @param project
  */
 public ParameterColumnLabelProvider(IARESResource resource, EStructuralFeature attribute) {
   super(attribute);
   this.resource = resource;
   this.project = resource.getARESProject();
 }