Search in sources :

Example 1 with SMAPSView

use of com.tencent.wstt.apt.ui.views.SMAPSView in project GT by Tencent.

the class APTSMAPSCTabItem method createAPTSMAPSCTablItemUI.

/**
	 * 初始化UI
	 * @param parent
	 */
private void createAPTSMAPSCTablItemUI(Composite parent) {
    int margin = 5;
    //		FormData expandBtnFD = new FormData();
    //		expandBtnFD.left = new FormAttachment(0, margin);
    //		expandBtnFD.top = new FormAttachment(0, margin);
    //		expandBtnFD.height = 16;
    //		expandBtnFD.width = 16;
    //		
    //		Button expandBtn = new Button(parent, SWT.NONE);
    //		expandBtn.setToolTipText("展开/折叠");
    //		expandBtn.setImage(AbstractUIPlugin.imageDescriptorFromPlugin(Constant.PLUGIN_ID, "icons/add.png").createImage());
    //		expandBtn.setLayoutData(expandBtnFD);
    //		/**
    //		 * TODO 折叠按钮单击响应
    //		 */
    FormData compareBtnFD = new FormData();
    compareBtnFD.left = new FormAttachment(0, margin);
    compareBtnFD.top = new FormAttachment(0, margin);
    compareBtnFD.height = 16;
    compareBtnFD.width = 16;
    Button compareBtn = new Button(parent, SWT.NONE);
    compareBtn.setToolTipText("对比其他smaps");
    compareBtn.setImage(AbstractUIPlugin.imageDescriptorFromPlugin(Constant.PLUGIN_ID, "icons/stat.png").createImage());
    compareBtn.setLayoutData(compareBtnFD);
    compareBtn.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            //首先获取当前已经打开的smaps文件
            CTabItem[] openedTabItems = APTSMAPSCTabItem.this.getParent().getItems();
            if (openedTabItems != null && openedTabItems.length > 1) {
                ArrayList<String> files = new ArrayList<String>();
                for (int i = 0; i < openedTabItems.length; i++) {
                    if (!APTSMAPSCTabItem.this.getText().equals(openedTabItems[i].getText())) {
                        files.add(openedTabItems[i].getText());
                    }
                }
                ListDialog dialog = new ListDialog(Display.getCurrent().getActiveShell());
                dialog.setContentProvider(new ArrayContentProvider());
                dialog.setLabelProvider(new LabelProvider());
                dialog.setInput(files);
                dialog.setHelpAvailable(false);
                dialog.setTitle("选择要对比的smaps文件");
                // 返回值为按钮
                dialog.open();
                Object[] selectedFiles = dialog.getResult();
                if (selectedFiles != null && selectedFiles.length > 0) {
                    String fileName = (String) selectedFiles[0];
                    Object sourceData = ((APTSMAPSCTabItem) CTabFolderItemUtil.getTabItem(openedTabItems, fileName)).getSourceData();
                    Object diffSouceData = SmapsUtil.getDiff((SMAPSSourceDataItem) (APTSMAPSCTabItem.this.getSourceData()), (SMAPSSourceDataItem) sourceData);
                    SMAPSView smapsViewPart = (SMAPSView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(SMAPSView.ID);
                    smapsViewPart.openSmapsDataInSMAPSView(diffSouceData, "diff");
                }
            } else {
                MessageDialog.openInformation(Display.getDefault().getActiveShell(), "提示", "No other smaps file opened");
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    FormData treeViewerFD = new FormData();
    treeViewerFD.left = new FormAttachment(0, margin);
    treeViewerFD.top = new FormAttachment(compareBtn, margin);
    treeViewerFD.right = new FormAttachment(100, -margin);
    treeViewerFD.bottom = new FormAttachment(100, -margin);
    viewer = new TreeViewer(parent, SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
    for (int i = 0; i < COLUMN_NAME.length; i++) {
        new TreeColumn(viewer.getTree(), SWT.LEFT).setText(COLUMN_NAME[i]);
        viewer.getTree().getColumn(i).setWidth(COLUMN_WIDTH[i]);
    }
    viewer.getControl().setLayoutData(treeViewerFD);
    //设置表头和表格线可见
    viewer.getTree().setHeaderVisible(true);
    viewer.getTree().setLinesVisible(true);
    viewer.setContentProvider(new ViewContentProvider());
    viewer.setLabelProvider(new ViewLabelProvider());
}
Also used : FormData(org.eclipse.swt.layout.FormData) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ArrayList(java.util.ArrayList) SMAPSView(com.tencent.wstt.apt.ui.views.SMAPSView) Button(org.eclipse.swt.widgets.Button) TreeColumn(org.eclipse.swt.widgets.TreeColumn) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider) FormAttachment(org.eclipse.swt.layout.FormAttachment) ListDialog(org.eclipse.ui.dialogs.ListDialog) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

SMAPSView (com.tencent.wstt.apt.ui.views.SMAPSView)1 ArrayList (java.util.ArrayList)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 ITableLabelProvider (org.eclipse.jface.viewers.ITableLabelProvider)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 FormAttachment (org.eclipse.swt.layout.FormAttachment)1 FormData (org.eclipse.swt.layout.FormData)1 Button (org.eclipse.swt.widgets.Button)1 TreeColumn (org.eclipse.swt.widgets.TreeColumn)1 ListDialog (org.eclipse.ui.dialogs.ListDialog)1