@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); }