Search in sources :

Example 11 with LabelProvider

use of org.eclipse.jface.viewers.LabelProvider in project translationstudio8 by heartsome.

the class NewTmDbBaseInfoPage method createControl.

/**
	 * Create contents of the wizard.
	 * @param parent
	 */
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    container.setLayout(new GridLayout(1, false));
    setControl(container);
    int labelWidth = 100;
    GridData gdLabel = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gdLabel.widthHint = labelWidth;
    Group dbGroup1 = new Group(container, SWT.NONE);
    dbGroup1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    dbGroup1.setLayout(new GridLayout(2, false));
    dbGroup1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 4, 1));
    dbGroup1.setText(Messages.getString("wizard.NewTmDbBaseInfoPage.dbGroup1"));
    Label label = new Label(dbGroup1, SWT.RIGHT);
    label.setLayoutData(gdLabel);
    label.setText(Messages.getString("wizard.NewTmDbBaseInfoPage.lblType"));
    dbTypeComboViewer = new ComboViewer(dbGroup1, SWT.READ_ONLY);
    Combo combo = dbTypeComboViewer.getCombo();
    combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    // //
    label = new Label(dbGroup1, SWT.RIGHT);
    label.setLayoutData(gdLabel);
    label.setText(Messages.getString("wizard.NewTmDbBaseInfoPage.dbNameText"));
    dbNameText = new Text(dbGroup1, SWT.BORDER);
    dbNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    label = new Label(dbGroup1, SWT.RIGHT);
    label.setLayoutData(gdLabel);
    label.setText(Messages.getString("wizard.NewTmDbBaseInfoPage.instanceText"));
    instanceText = new Text(dbGroup1, SWT.BORDER);
    instanceText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    dbTypeComboViewer.setContentProvider(new ArrayContentProvider());
    dbTypeComboViewer.setInput(dbTypeList);
    dbTypeComboViewer.setLabelProvider(new LabelProvider() {

        public String getText(Object element) {
            SystemDBOperator dbOp = (SystemDBOperator) element;
            String dbType = dbOp.getDBConfig().getDefaultType();
            if (dbType.equals(Constants.DBTYPE_MYSQL)) {
                dbType = Constants.DBTYPE_MYSQL_FOR_UI;
            } else if (dbType.equals(Constants.DBTYPE_MSSQL2005)) {
                dbType = Constants.DBTYPE_MSSQL2005_FOR_UI;
            } else if (dbType.equals(Constants.DBTYPE_SQLITE)) {
                dbType = Messages.getString("tm.dbtype.sqlite");
            }
            return dbType;
        }
    });
    dbTypeComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            if (selection != null && selection instanceof IStructuredSelection) {
                IStructuredSelection sel = (IStructuredSelection) selection;
                Object selObj = sel.getFirstElement();
                if (selObj != null && selObj instanceof SystemDBOperator) {
                    SystemDBOperator selDbOp = (SystemDBOperator) selObj;
                    dbTypeChangeEvent(selDbOp);
                }
            }
        }
    });
    Group dbGroup = new Group(container, SWT.NONE);
    dbGroup.setLayout(new GridLayout(5, false));
    dbGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 4, 1));
    dbGroup.setText(Messages.getString("wizard.NewTmDbBaseInfoPage.dbGroup"));
    label = new Label(dbGroup, SWT.RIGHT);
    label.setLayoutData(gdLabel);
    label.setText(Messages.getString("wizard.NewTmDbBaseInfoPage.hostText"));
    hostText = new Text(dbGroup, SWT.BORDER);
    hostText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    label = new Label(dbGroup, SWT.RIGHT);
    label.setLayoutData(gdLabel);
    label.setText(Messages.getString("wizard.NewTmDbBaseInfoPage.portText"));
    portText = new Text(dbGroup, SWT.BORDER);
    new Label(dbGroup, SWT.NONE);
    label = new Label(dbGroup, SWT.RIGHT);
    label.setLayoutData(gdLabel);
    label.setText(Messages.getString("wizard.NewTmDbBaseInfoPage.locationText"));
    locationText = new Text(dbGroup, SWT.BORDER);
    locationText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
    locationText.setEnabled(false);
    borwserBtn = new Button(dbGroup, SWT.NONE);
    borwserBtn.setText(Messages.getString("wizard.NewTmDbBaseInfoPage.borwserBtn"));
    borwserBtn.setEnabled(false);
    borwserBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            DirectoryDialog dlg = new DirectoryDialog(getShell());
            String path = dlg.open();
            if (path != null) {
                locationText.setText(path);
            }
        }
    });
    Group authorityGroup = new Group(container, SWT.NONE);
    authorityGroup.setLayout(new GridLayout(2, false));
    authorityGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1));
    authorityGroup.setText(Messages.getString("wizard.NewTmDbBaseInfoPage.authorityGroup"));
    label = new Label(authorityGroup, SWT.RIGHT);
    label.setLayoutData(gdLabel);
    label.setText(Messages.getString("wizard.NewTmDbBaseInfoPage.usernameText"));
    usernameText = new Text(authorityGroup, SWT.BORDER);
    usernameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    label = new Label(authorityGroup, SWT.RIGHT);
    label.setLayoutData(gdLabel);
    label.setText(Messages.getString("wizard.NewTmDbBaseInfoPage.passwordText"));
    passwordText = new Text(authorityGroup, SWT.BORDER | SWT.PASSWORD);
    passwordText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    initDataBindings();
    if (this.dbOp != null) {
        dbTypeComboViewer.setSelection(new StructuredSelection(this.dbOp));
    } else {
        dbTypeComboViewer.setSelection(new StructuredSelection(dbTypeList.get(0)));
    }
    IStatus state = validator();
    if (!state.isOK()) {
        setErrorMessage(state.getMessage());
        setPageComplete(false);
    }
}
Also used : Group(org.eclipse.swt.widgets.Group) IStatus(org.eclipse.core.runtime.IStatus) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Combo(org.eclipse.swt.widgets.Combo) Text(org.eclipse.swt.widgets.Text) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) SystemDBOperator(net.heartsome.cat.database.SystemDBOperator) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ISelection(org.eclipse.jface.viewers.ISelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) LabelProvider(org.eclipse.jface.viewers.LabelProvider) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Example 12 with LabelProvider

use of org.eclipse.jface.viewers.LabelProvider 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)

Example 13 with LabelProvider

use of org.eclipse.jface.viewers.LabelProvider in project GT by Tencent.

the class StubAnalysisView method makeActions.

/**
	 * 初始化各种Action
	 */
private void makeActions() {
    openLogOnPCAction = new Action() {

        public void run() {
            FileDialog dialog = new FileDialog(Display.getDefault().getActiveShell(), SWT.OPEN);
            //设置初始路径
            dialog.setFilterPath(Constant.LOG_FOLDER_ON_PC);
            //返回的全路径(路径+文件名)
            String fileName = dialog.open();
            if (fileName == null) {
                return;
            }
            openFileInAPT(fileName);
        }
    };
    openLogOnPCAction.setText("打开APT插桩文件");
    openLogOnPCAction.setToolTipText("打开APT插桩文件");
    openLogOnPCAction.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Constant.PLUGIN_ID, "icons/open_pc.png"));
    openLogOnPhoneAction = new Action() {

        public void run() {
            List<String> fileOnPhoneList = FileOperatorUtil.getLogFilesOnPhone();
            //APTConsoleFactory.getInstance().APTPrint("size=" + fileOnPhoneList.size());
            ListDialog dialog = new ListDialog(Display.getCurrent().getActiveShell());
            dialog.setContentProvider(new ArrayContentProvider());
            dialog.setLabelProvider(new LabelProvider());
            dialog.setInput(fileOnPhoneList);
            dialog.setHelpAvailable(false);
            dialog.setTitle("请选择一个手机上的文件");
            // 返回值为按钮
            dialog.open();
            Object[] selectedFiles = dialog.getResult();
            if (selectedFiles != null && selectedFiles.length > 0) {
                String fileName = (String) selectedFiles[0];
                FileOperatorUtil.pullLogFileWithNameFromSDCard(fileName, Constant.LOG_FOLDER_ON_PC);
                // 解析刚刚拉取的文件作为数据源
                // TODO 获取耗时数据
                String fileNameWithPath = Constant.LOG_FOLDER_ON_PC + File.separator + fileName;
                openFileInAPT(fileNameWithPath);
            }
        }
    };
    openLogOnPhoneAction.setText("Open Log On Phone..");
    openLogOnPhoneAction.setToolTipText("打开手机端指定的内存日志文件");
    openLogOnPhoneAction.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Constant.PLUGIN_ID, "icons/open_phone.png"));
}
Also used : Action(org.eclipse.jface.action.Action) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) List(java.util.List) FileDialog(org.eclipse.swt.widgets.FileDialog) LabelProvider(org.eclipse.jface.viewers.LabelProvider) ListDialog(org.eclipse.ui.dialogs.ListDialog)

Example 14 with LabelProvider

use of org.eclipse.jface.viewers.LabelProvider in project mechanoid by robotoworks.

the class PackageBrowserField method attachProposalProvider.

private void attachProposalProvider() {
    try {
        mProposalProvider = new PackageProposalProvider();
        mPackageProposalAdapter = new ContentProposalAdapter(getTextField(), new TextContentAdapter(), mProposalProvider, KeyStroke.getInstance("Ctrl+Space"), new char[] { '.' });
        mPackageProposalAdapter.setLabelProvider(new LabelProvider() {

            @Override
            public Image getImage(Object element) {
                return mPackageImage;
            }

            @Override
            public String getText(Object element) {
                PackageProposal p = (PackageProposal) element;
                return p.getContent();
            }
        });
        mPackageProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
    } catch (ParseException e) {
        e.printStackTrace();
    }
}
Also used : ParseException(org.eclipse.jface.bindings.keys.ParseException) TextContentAdapter(org.eclipse.jface.fieldassist.TextContentAdapter) Image(org.eclipse.swt.graphics.Image) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider) ContentProposalAdapter(org.eclipse.jface.fieldassist.ContentProposalAdapter)

Example 15 with LabelProvider

use of org.eclipse.jface.viewers.LabelProvider in project ACS by ACS-Community.

the class ReductionsView method createViewWidgets.

private void createViewWidgets(Composite parent) {
    _addElement = new Listener() {

        public void handleEvent(Event event) {
            TreeItem sel = null;
            TreeItem item = null;
            if (_tree.getSelection() == null || _tree.getSelection().length == 0)
                return;
            sel = _tree.getSelection()[0];
            NodeType type = (NodeType) sel.getData();
            item = sel;
            if (type == NodeType.NODE_REDUCTION_PARENT_DATA || type == NodeType.MULTIPLICITY_REDUCTION_PARENT_DATA)
                item = sel.getParentItem();
            type = (NodeType) item.getData();
            java.util.List<FaultFamily> ffs = _alarmManager.getAllAlarms();
            java.util.List<String> ffnames = new ArrayList<String>();
            for (FaultFamily ff : ffs) {
                if (ff.getFaultCodeCount() > 0 && ff.getFaultMemberCount() > 0)
                    ffnames.add(ff.getName());
            }
            Collections.sort(ffnames, IGNORE_CASE_ORDER);
            ListDialog dialog = new ListDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell());
            dialog.setTitle("Create Reduction Rule");
            dialog.setMessage("Select Parent Fault Family");
            dialog.setBlockOnOpen(true);
            dialog.setInput(ffnames);
            dialog.setContentProvider(new ArrayContentProvider());
            dialog.setLabelProvider(new LabelProvider());
            dialog.open();
            if (dialog.getReturnCode() == InputDialog.CANCEL)
                return;
            String ffname = (String) dialog.getResult()[0];
            FaultMember[] fms = _alarmManager.getFaultFamily(ffname).getFaultMember();
            java.util.List<String> fmnames = new ArrayList<String>();
            for (FaultMember fm : fms) {
                fmnames.add(fm.getName());
            }
            Collections.sort(ffnames, IGNORE_CASE_ORDER);
            dialog = new ListDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell());
            dialog.setTitle("Create Reduction Rule");
            dialog.setMessage("Select Parent Fault Member");
            dialog.setBlockOnOpen(true);
            dialog.setInput(fmnames);
            dialog.setContentProvider(new ArrayContentProvider());
            dialog.setLabelProvider(new LabelProvider());
            dialog.open();
            if (dialog.getReturnCode() == InputDialog.CANCEL)
                return;
            String fmname = (String) dialog.getResult()[0];
            FaultCode[] fcs = _alarmManager.getFaultFamily(ffname).getFaultCode();
            java.util.List<String> fcvalues = new ArrayList<String>();
            for (FaultCode fc : fcs) {
                fcvalues.add(Integer.toString(fc.getValue()));
            }
            Collections.sort(ffnames, IGNORE_CASE_ORDER);
            dialog = new ListDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell());
            dialog.setTitle("Create Reduction Rule");
            dialog.setMessage("Select Parent Fault Code");
            dialog.setBlockOnOpen(true);
            dialog.setInput(fcvalues);
            dialog.setContentProvider(new ArrayContentProvider());
            dialog.setLabelProvider(new LabelProvider());
            dialog.open();
            if (dialog.getReturnCode() == InputDialog.CANCEL)
                return;
            String fcvalue = (String) dialog.getResult()[0];
            ReductionRule parent = null;
            boolean error = false;
            if (type == NodeType.NODE_REDUCTION) {
                parent = _reductionManager.getNRParentByTriplet(ffname, fmname, Integer.parseInt(fcvalue));
                TreeItem[] chs = _tree.getItems()[0].getItems();
                for (TreeItem ch : chs) {
                    if (ch.getText().compareTo("<" + ffname + "," + fmname + "," + fcvalue + ">") == 0)
                        error = true;
                }
            } else if (type == NodeType.MULTIPLICITY_REDUCTION) {
                parent = _reductionManager.getMRParentByTriplet(ffname, fmname, Integer.parseInt(fcvalue));
                TreeItem[] chs = _tree.getItems()[1].getItems();
                for (TreeItem ch : chs) {
                    if (ch.getText().compareTo("<" + ffname + "," + fmname + "," + fcvalue + ">") == 0)
                        error = true;
                }
            }
            if (error || parent != null) {
                ErrorDialog edialog = new ErrorDialog(ReductionsView.this.getViewSite().getShell(), "Reduction Rule Already Exists", "The reduction rule you are trying to create already exists", new Status(IStatus.ERROR, "cl.utfsm.acs.acg", "The reduction rule parent already exists"), IStatus.ERROR);
                edialog.setBlockOnOpen(true);
                edialog.open();
                return;
            } else
                parent = new ReductionRule(_alarmManager.getAlarm(ffname + ":" + fmname + ":" + fcvalue));
            TreeItem pTree = new TreeItem(item, SWT.NONE);
            pTree.setText("<" + ffname + "," + fmname + "," + fcvalue + ">");
            if (type == NodeType.NODE_REDUCTION) {
                pTree.setData(NodeType.NODE_REDUCTION_PARENT_DATA);
                parent.setIsNodeReduction(true);
            } else if (type == NodeType.MULTIPLICITY_REDUCTION) {
                pTree.setData(NodeType.MULTIPLICITY_REDUCTION_PARENT_DATA);
                parent.setIsNodeReduction(false);
            }
            _tree.setSelection(pTree);
            Event e = new Event();
            _tree.notifyListeners(SWT.Selection, e);
        }
    };
    _addRule = new Listener() {

        public void handleEvent(Event event) {
            Table t = (Table) event.widget;
            if (event.type == SWT.KeyUp)
                if (!(event.keyCode == SWT.CR || event.keyCode == ' '))
                    return;
            if (event.type == SWT.MouseDoubleClick) {
                Point pt = new Point(event.x, event.y);
                if (t.getItem(pt) == null)
                    return;
            }
            boolean isNode;
            if (_tree.getSelection() == null || _tree.getSelection().length == 0)
                return;
            TreeItem tmp1 = _tree.getSelection()[0];
            if ((NodeType) _tree.getSelection()[0].getData() == NodeType.NODE_REDUCTION_PARENT_DATA)
                isNode = true;
            else if ((NodeType) _tree.getSelection()[0].getData() == NodeType.MULTIPLICITY_REDUCTION_PARENT_DATA)
                isNode = false;
            else
                return;
            String[] tr = getTriplet(tmp1.getText());
            ReductionRule parent;
            if (isNode)
                parent = _reductionManager.getNRParentByTriplet(tr[0], tr[1], Integer.parseInt(tr[2]));
            else
                parent = _reductionManager.getMRParentByTriplet(tr[0], tr[1], Integer.parseInt(tr[2]));
            if (t.getSelection() == null || t.getSelection().length == 0)
                return;
            TableItem item = t.getSelection()[0];
            Alarm p, c;
            if (parent == null) {
                if (isNode)
                    p = _alarmManager.getAlarm(_NRParentFFCombo.getText() + ":" + _NRParentFMCombo.getText() + ":" + _NRParentFCCombo.getText());
                else
                    p = _alarmManager.getAlarm(_MRParentFFCombo.getText() + ":" + _MRParentFMCombo.getText() + ":" + _MRParentFCCombo.getText());
                if (p == null) {
                    if (isNode)
                        _NRParentErrorMessageLabel.setText("Couldn't find parent alarm.");
                    else
                        _MRParentErrorMessageLabel.setText("Couldn't find parent alarm.");
                    return;
                }
                c = null;
            } else {
                p = parent.getParent();
                c = parent.getChild(item.getText());
            }
            if (c == null) {
                //Add child
                c = _alarmManager.getAlarm(item.getText());
                if (c == null) {
                    if (isNode)
                        _NRParentErrorMessageLabel.setText("Couldn't find child alarm.");
                    else
                        _MRParentErrorMessageLabel.setText("Couldn't find child alarm.");
                    return;
                }
                try {
                    if (isNode)
                        _reductionManager.addNodeReductionRule(p, c);
                    else {
                        _reductionManager.addMultiReductionRule(p, c);
                        if (parent == null)
                            _reductionManager.updateMultiThreshold(p, Integer.parseInt(_MRParentThresholdText.getText()));
                    }
                    item.setImage(Activator.getDefault().getImageRegistry().get(Activator.IMG_TICKET));
                    if (parent == null)
                        _tree.getSelection()[0].setText("<" + p.getAlarmId().replace(':', ',') + ">");
                    if (isNode)
                        _NRParentErrorMessageLabel.setText("");
                    else
                        _MRParentErrorMessageLabel.setText("");
                } catch (IllegalOperationException e) {
                    if (isNode)
                        _NRParentErrorMessageLabel.setText(e.getMessage());
                    else
                        _MRParentErrorMessageLabel.setText(e.getMessage());
                }
            } else {
                //Remove child
                try {
                    //ReductionRule rr;
                    if (isNode) {
                        _reductionManager.deleteNodeReductionRule(p, c);
                    //rr = _reductionManager.getNRParentByTriplet(p.getTriplet().getFaultFamily(), p.getTriplet().getFaultMember(), p.getTriplet().getFaultCode());
                    } else {
                        _reductionManager.deleteMultiReductionRule(p, c);
                    //rr = _reductionManager.getMRParentByTriplet(p.getTriplet().getFaultFamily(), p.getTriplet().getFaultMember(), p.getTriplet().getFaultCode());
                    }
                } catch (IllegalOperationException e) {
                    e.printStackTrace();
                }
                item.setImage((org.eclipse.swt.graphics.Image) null);
            }
            fillMRParentChAlarmList(tr[0], tr[1], Integer.parseInt(tr[2]));
            sortReductionRulesList();
            Triplet t2 = p.getTriplet();
            if (isNode)
                selectElementFromTree("<" + t2.getFaultFamily() + "," + t2.getFaultMember() + "," + t2.getFaultCode() + ">", true);
            else
                selectElementFromTree("<" + t2.getFaultFamily() + "," + t2.getFaultMember() + "," + t2.getFaultCode() + ">", false);
        }
    };
    _removeElement = new Listener() {

        public void handleEvent(Event event) {
            boolean choice = MessageDialog.openQuestion(ReductionsView.this.getViewSite().getShell(), "Confirmation", "Are you sure you want to delete this element");
            if (choice == true) {
                TreeItem sel = null;
                if (_tree.getSelection() == null || _tree.getSelection().length == 0)
                    return;
                NodeType type = (NodeType) _tree.getSelection()[0].getData();
                if (type == NodeType.NODE_REDUCTION || type == NodeType.MULTIPLICITY_REDUCTION)
                    return;
                TreeItem item = _tree.getSelection()[0];
                String[] tr = getTriplet(item.getText());
                try {
                    if (type == NodeType.NODE_REDUCTION_PARENT_DATA) {
                        //Remove all the NODE REDUCTION Rules in which this node is parent.
                        ReductionRule rr = _reductionManager.getNRParentByTriplet(tr[0], tr[1], Integer.parseInt(tr[2]));
                        if (rr != null) {
                            Alarm p = rr.getParent();
                            List<Alarm> chL = rr.getChildren();
                            Alarm[] als = new Alarm[chL.size()];
                            chL.toArray(als);
                            for (int i = 0; i < als.length; i++) _reductionManager.deleteNodeReductionRule(p, als[i]);
                        }
                    } else if (type == NodeType.MULTIPLICITY_REDUCTION_PARENT_DATA) {
                        //Remove all the MULTIPLICITY REDUCTION Rules in which this node is a parent.
                        ReductionRule rr = _reductionManager.getMRParentByTriplet(tr[0], tr[1], Integer.parseInt(tr[2]));
                        if (rr != null) {
                            Alarm p = rr.getParent();
                            List<Alarm> chL = rr.getChildren();
                            Alarm[] als = new Alarm[chL.size()];
                            chL.toArray(als);
                            for (int i = 0; i < als.length; i++) _reductionManager.deleteMultiReductionRule(p, als[i]);
                        }
                    }
                } catch (NullPointerException e) {
                    ErrorDialog error = new ErrorDialog(ReductionsView.this.getViewSite().getShell(), "Cannot delete the item", e.getMessage(), new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
                    error.setBlockOnOpen(true);
                    error.open();
                } catch (IllegalOperationException e) {
                    ErrorDialog error = new ErrorDialog(ReductionsView.this.getViewSite().getShell(), "Cannot delete the item", e.getMessage(), new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
                    error.setBlockOnOpen(true);
                    error.open();
                }
                sel = _tree.getSelection()[0].getParentItem();
                _tree.getSelection()[0].dispose();
                _tree.setSelection(sel);
                Event e = new Event();
                _tree.notifyListeners(SWT.Selection, e);
            }
        }
    };
    _sash = new SashForm(parent, SWT.NONE);
    _sash.setLayout(new FillLayout());
    _reductionsComp = new Composite(_sash, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    _reductionsComp.setLayout(layout);
    _treeGroup = new Group(_reductionsComp, SWT.SHADOW_ETCHED_IN);
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    _treeGroup.setLayoutData(gd);
    GridLayout gl = new GridLayout();
    gl.numColumns = 1;
    _treeGroup.setLayout(gl);
    _treeGroup.setText("Reduction Rules List");
    _tree = new Tree(_treeGroup, SWT.VIRTUAL | SWT.BORDER);
    gd = new GridData();
    gd.verticalAlignment = SWT.FILL;
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    gd.grabExcessHorizontalSpace = true;
    _tree.setLayoutData(gd);
    Menu treePopUp = new Menu(parent);
    /*
		MenuItem treePopUpDelete = new MenuItem(treePopUp,SWT.PUSH);
		treePopUpDelete.setText("Delete");
		treePopUpDelete.addListener(SWT.Selection, _removeElement);
		MenuItem treePopUpAddRule = new MenuItem(treePopUp,SWT.PUSH);
		treePopUpAddRule.setText("Add Rule");
		treePopUpAddRule.addListener(SWT.Selection, _addElement);
		MenuItem treePopUpAddChildren = new MenuItem(treePopUp,SWT.PUSH);
		treePopUpAddChildren.setText("Add Children");
		//treePopUpAddChildren.addListener(SWT.Selection, _addElement);
		*/
    _tree.setMenu(treePopUp);
    treePopUp.addListener(SWT.Show, new Listener() {

        public void handleEvent(Event e) {
            TreeItem sel = _tree.getSelection()[0];
            NodeType type = (NodeType) sel.getData();
            Menu treePopUp = _tree.getMenu();
            MenuItem[] items = treePopUp.getItems();
            for (int i = 0; i < items.length; i++) items[i].dispose();
            MenuItem mitem;
            switch(type) {
                case NODE_REDUCTION:
                    mitem = new MenuItem(treePopUp, SWT.PUSH);
                    mitem.setText("Add Node Reduction Rule Parent");
                    mitem.addListener(SWT.Selection, _addElement);
                    break;
                case NODE_REDUCTION_PARENT_DATA:
                    mitem = new MenuItem(treePopUp, SWT.PUSH);
                    mitem.setText("Delete Node Reduction Rules for this parent");
                    mitem.addListener(SWT.Selection, _removeElement);
                    break;
                case MULTIPLICITY_REDUCTION:
                    mitem = new MenuItem(treePopUp, SWT.PUSH);
                    mitem.setText("Add Multiplicity Reduction Rule Parent");
                    mitem.addListener(SWT.Selection, _addElement);
                    break;
                case MULTIPLICITY_REDUCTION_PARENT_DATA:
                    mitem = new MenuItem(treePopUp, SWT.PUSH);
                    mitem.setText("Delete Multiplicity Reduction Rules for this parent");
                    mitem.addListener(SWT.Selection, _removeElement);
                    break;
                default:
                    for (int i = 0; i < items.length; i++) items[i].dispose();
                    break;
            }
        }
    });
    _tree.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        public void widgetSelected(SelectionEvent e) {
            TreeItem[] tmp = ((Tree) e.widget).getSelection();
            if (tmp == null || tmp.length == 0)
                return;
            TreeItem item = tmp[0];
            NodeType type = (NodeType) item.getData();
            Control c = _compInitial.getChildren()[0];
            if (c instanceof Label) {
                c.dispose();
                _compInitial.layout();
                c = _compInitial.getChildren()[0];
            }
            if (type == NodeType.NODE_REDUCTION) {
                _NRParentGroup.setVisible(false);
                ((GridData) _NRParentGroup.getLayoutData()).exclude = true;
                _MRParentGroup.setVisible(false);
                ((GridData) _MRParentGroup.getLayoutData()).exclude = true;
            } else if (type == NodeType.NODE_REDUCTION_PARENT_DATA) {
                _NRParentGroup.setVisible(true);
                ((GridData) _NRParentGroup.getLayoutData()).exclude = false;
                _MRParentGroup.setVisible(false);
                ((GridData) _MRParentGroup.getLayoutData()).exclude = true;
                String[] triplet = getTriplet(item.getText());
                fillNRParentWidgets(triplet[0], triplet[1], Integer.parseInt(triplet[2]));
                _NRParentGroup.moveAbove(c);
                _compInitial.layout();
            } else if (type == NodeType.MULTIPLICITY_REDUCTION) {
                _NRParentGroup.setVisible(false);
                ((GridData) _NRParentGroup.getLayoutData()).exclude = true;
                _MRParentGroup.setVisible(false);
                ((GridData) _MRParentGroup.getLayoutData()).exclude = true;
            } else if (type == NodeType.MULTIPLICITY_REDUCTION_PARENT_DATA) {
                _NRParentGroup.setVisible(false);
                ((GridData) _NRParentGroup.getLayoutData()).exclude = true;
                _MRParentGroup.setVisible(true);
                ((GridData) _MRParentGroup.getLayoutData()).exclude = false;
                String[] triplet = getTriplet(item.getText());
                fillMRParentWidgets(triplet[0], triplet[1], Integer.parseInt(triplet[2]));
                _MRParentGroup.moveAbove(c);
                _compInitial.layout();
            }
        }
    });
    /* Top widget of the right side */
    _compInitial = new Composite(_sash, SWT.NONE);
    _compInitial.setLayout(new GridLayout());
    new Label(_compInitial, SWT.NONE).setText("Select a reduction rule");
    /* NR/MR Details */
    createNRParentWidgets();
    createMRParentWidgets();
    _NRParentGroup.setVisible(false);
    _MRParentGroup.setVisible(false);
    _sash.setWeights(new int[] { 3, 5 });
}
Also used : FaultCode(alma.acs.alarmsystem.generated.FaultCode) Group(org.eclipse.swt.widgets.Group) SelectionListener(org.eclipse.swt.events.SelectionListener) Listener(org.eclipse.swt.widgets.Listener) TreeItem(org.eclipse.swt.widgets.TreeItem) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) List(java.util.List) ArrayList(java.util.ArrayList) Menu(org.eclipse.swt.widgets.Menu) FaultMember(alma.acs.alarmsystem.generated.FaultMember) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) Triplet(cern.laser.business.data.Triplet) ErrorDialog(org.eclipse.jface.dialogs.ErrorDialog) MenuItem(org.eclipse.swt.widgets.MenuItem) Point(org.eclipse.swt.graphics.Point) FillLayout(org.eclipse.swt.layout.FillLayout) IllegalOperationException(cl.utfsm.acs.acg.core.IllegalOperationException) ReductionRule(cl.utfsm.acs.acg.core.ReductionRule) Point(org.eclipse.swt.graphics.Point) SashForm(org.eclipse.swt.custom.SashForm) FaultFamily(alma.acs.alarmsystem.generated.FaultFamily) Alarm(cern.laser.business.data.Alarm) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) LabelProvider(org.eclipse.jface.viewers.LabelProvider) ListDialog(org.eclipse.ui.dialogs.ListDialog) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

LabelProvider (org.eclipse.jface.viewers.LabelProvider)25 GridData (org.eclipse.swt.layout.GridData)17 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)12 GridLayout (org.eclipse.swt.layout.GridLayout)11 Composite (org.eclipse.swt.widgets.Composite)11 ComboViewer (org.eclipse.jface.viewers.ComboViewer)10 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10 Label (org.eclipse.swt.widgets.Label)10 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)8 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)7 Button (org.eclipse.swt.widgets.Button)7 Combo (org.eclipse.swt.widgets.Combo)7 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)6 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)6 Text (org.eclipse.swt.widgets.Text)6 ArrayList (java.util.ArrayList)5 ISelection (org.eclipse.jface.viewers.ISelection)5 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)5 Image (org.eclipse.swt.graphics.Image)5 List (java.util.List)4