use of org.eclipse.jface.dialogs.ErrorDialog in project ACS by ACS-Community.
the class ReductionsView method createNRParentWidgets.
private void createNRParentWidgets() {
_updateNRParentFF = new Listener() {
public void handleEvent(Event event) {
_NRParentFMCombo.removeAll();
FaultMember[] fml = _alarmManager.getFaultFamily(_NRParentFFCombo.getText()).getFaultMember();
for (int j = 0; j < fml.length; j++) {
_NRParentFMCombo.add(fml[j].getName());
}
_NRParentFCCombo.removeAll();
FaultCode[] fcl = _alarmManager.getFaultFamily(_NRParentFFCombo.getText()).getFaultCode();
for (int j = 0; j < fcl.length; j++) {
_NRParentFCCombo.add(String.valueOf(fcl[j].getValue()));
}
_NRParentErrorMessageLabel.setText("Please choose a Fault Member and a Fault Code.");
}
};
_updateNRParent = new Listener() {
public void handleEvent(Event event) {
if (_tree.getSelection() == null || _tree.getSelection().length == 0)
return;
NodeType type = (NodeType) _tree.getSelection()[0].getData();
if (type != NodeType.NODE_REDUCTION_PARENT_DATA)
return;
if (_NRParentFMCombo.getText().isEmpty()) {
_NRParentErrorMessageLabel.setText("Please choose a Fault Member.");
return;
}
if (_NRParentFCCombo.getText().isEmpty()) {
_NRParentErrorMessageLabel.setText("Please choose a Fault Code.");
return;
}
String[] tr = getTriplet(_tree.getSelection()[0].getText());
ReductionRule nrr = _reductionManager.getNRParentByTriplet(tr[0], tr[1], Integer.parseInt(tr[2]));
ReductionRule nrr2 = _reductionManager.getNRParentByTriplet(_NRParentFFCombo.getText(), _NRParentFMCombo.getText(), Integer.parseInt(_NRParentFCCombo.getText()));
Alarm parent = null;
Alarm nParent;
fillNRParentChAlarmList(_NRParentFFCombo.getText(), _NRParentFMCombo.getText(), Integer.parseInt(_NRParentFCCombo.getText()));
if (nrr == null) {
_NRParentErrorMessageLabel.setText("There's no Reduction Rule (no children) for the selected Alarm.");
return;
} else
parent = nrr.getParent();
if (nrr2 == null)
nParent = _alarmManager.getAlarm(new String(_NRParentFFCombo.getText() + ":" + _NRParentFMCombo.getText() + ":" + _NRParentFCCombo.getText()));
else {
nParent = nrr2.getParent();
if (nrr != nrr2) {
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;
}
}
if (parent != null) {
String[] ch = parent.getNodeChildren();
//Remove all Children from nrr and add them to nrr2.
for (int i = 0; i < ch.length; i++) {
Alarm aCh = _alarmManager.getAlarm(ch[i]);
if (aCh != null) {
try {
if (!_reductionManager.deleteNodeReductionRule(parent, aCh)) {
_NRParentErrorMessageLabel.setText("One or more children alarms didn't exist.");
continue;
}
_reductionManager.addNodeReductionRule(nParent, aCh);
} catch (IllegalOperationException e) {
_NRParentErrorMessageLabel.setText("The parent alarm didn't exist.");
}
}
}
_tree.getSelection()[0].setText("<" + nParent.getAlarmId().replace(':', ',') + ">");
_NRParentErrorMessageLabel.setText("");
if (tr[0].compareTo(_NRParentFFCombo.getText()) != 0 || tr[1].compareTo(_NRParentFMCombo.getText()) != 0 || tr[2].compareTo(_NRParentFCCombo.getText()) != 0) {
sortReductionRulesList();
Triplet t = nParent.getTriplet();
selectElementFromTree("<" + t.getFaultFamily() + "," + t.getFaultMember() + "," + t.getFaultCode() + ">", true);
}
}
}
};
_updateNRParentChFF = new Listener() {
public void handleEvent(Event event) {
_NRParentChFMCombo.removeAll();
_NRParentChFMCombo.add("Any");
if (_NRParentChFFCombo.getText().compareTo("Any") != 0) {
FaultMember[] fml = _alarmManager.getFaultFamily(_NRParentChFFCombo.getText()).getFaultMember();
for (int j = 0; j < fml.length; j++) {
_NRParentChFMCombo.add(fml[j].getName());
}
}
_NRParentChFMCombo.select(0);
_NRParentChFCCombo.removeAll();
_NRParentChFCCombo.add("Any");
if (_NRParentChFFCombo.getText().compareTo("Any") != 0) {
FaultCode[] fcl = _alarmManager.getFaultFamily(_NRParentChFFCombo.getText()).getFaultCode();
for (int j = 0; j < fcl.length; j++) {
_NRParentChFCCombo.add(String.valueOf(fcl[j].getValue()));
}
}
_NRParentChFCCombo.select(0);
TreeItem[] tmp = _tree.getSelection();
if (tmp == null || tmp.length == 0)
return;
TreeItem item = tmp[0];
String[] triplet = getTriplet(item.getText());
fillNRParentChAlarmList(triplet[0], triplet[1], Integer.parseInt(triplet[2]));
}
};
_updateNRParentCh = new Listener() {
public void handleEvent(Event event) {
TreeItem[] tmp = _tree.getSelection();
if (tmp == null || tmp.length == 0)
return;
TreeItem item = tmp[0];
String[] triplet = getTriplet(item.getText());
fillNRParentChAlarmList(triplet[0], triplet[1], Integer.parseInt(triplet[2]));
}
};
_NRParentGroup = new Group(_compInitial, SWT.SHADOW_ETCHED_IN);
GridLayout gl = new GridLayout();
gl.numColumns = 1;
GridData gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.grabExcessVerticalSpace = true;
gd.horizontalAlignment = SWT.FILL;
gd.verticalAlignment = SWT.FILL;
_NRParentGroup.setLayout(gl);
_NRParentGroup.setLayoutData(gd);
_NRParentFtGroup = new Group(_NRParentGroup, SWT.SHADOW_ETCHED_IN);
gl = new GridLayout();
gl.numColumns = 2;
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
_NRParentFtGroup.setLayout(gl);
_NRParentFtGroup.setLayoutData(gd);
_NRParentFtGroup.setText("Parent Alarm");
_NRParentFFLabel = new Label(_NRParentFtGroup, SWT.NONE);
_NRParentFFLabel.setText("Fault Family:");
_NRParentFFCombo = new Combo(_NRParentFtGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
_NRParentFFCombo.setLayoutData(gd);
_NRParentFFCombo.addListener(SWT.Selection, _updateNRParentFF);
_NRParentFMLabel = new Label(_NRParentFtGroup, SWT.NONE);
_NRParentFMLabel.setText("Fault Member:");
_NRParentFMCombo = new Combo(_NRParentFtGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
_NRParentFMCombo.setLayoutData(gd);
_NRParentFMCombo.addListener(SWT.Selection, _updateNRParent);
_NRParentFCLabel = new Label(_NRParentFtGroup, SWT.NONE);
_NRParentFCLabel.setText("Fault Code:");
_NRParentFCCombo = new Combo(_NRParentFtGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
_NRParentFCCombo.setLayoutData(gd);
_NRParentFCCombo.addListener(SWT.Selection, _updateNRParent);
//
_NRParentChGroup = new Group(_NRParentGroup, SWT.SHADOW_ETCHED_IN);
gl = new GridLayout();
gl.numColumns = 1;
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.grabExcessVerticalSpace = true;
gd.horizontalAlignment = SWT.FILL;
gd.verticalAlignment = SWT.FILL;
_NRParentChGroup.setLayout(gl);
_NRParentChGroup.setLayoutData(gd);
_NRParentChGroup.setText("Alarms to Hide");
_NRParentChFilterGroup = new Group(_NRParentChGroup, SWT.SHADOW_ETCHED_IN);
gl = new GridLayout();
gl.numColumns = 2;
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
_NRParentChFilterGroup.setLayout(gl);
_NRParentChFilterGroup.setLayoutData(gd);
_NRParentChFilterGroup.setText("Filter Options");
_NRParentChFilterLevelGroup = new Group(_NRParentChFilterGroup, SWT.SHADOW_ETCHED_IN);
gl = new GridLayout();
gl.numColumns = 3;
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalSpan = 2;
gd.horizontalAlignment = SWT.FILL;
_NRParentChFilterLevelGroup.setLayout(gl);
_NRParentChFilterLevelGroup.setLayoutData(gd);
_NRParentChFilterLevelGroup.setText("Show");
_NRParentChAllRadio = new Button(_NRParentChFilterLevelGroup, SWT.RADIO);
_NRParentChAllRadio.setText("All");
_NRParentChAllRadio.addListener(SWT.Selection, _updateNRParentCh);
_NRParentChSelectedRadio = new Button(_NRParentChFilterLevelGroup, SWT.RADIO);
_NRParentChSelectedRadio.setText("Selected");
_NRParentChSelectedRadio.addListener(SWT.Selection, _updateNRParentCh);
_NRParentChUnselectedRadio = new Button(_NRParentChFilterLevelGroup, SWT.RADIO);
_NRParentChUnselectedRadio.setText("Unselected");
_NRParentChUnselectedRadio.addListener(SWT.Selection, _updateNRParentCh);
_NRParentChFFLabel = new Label(_NRParentChFilterGroup, SWT.NONE);
_NRParentChFFLabel.setText("Fault Family:");
_NRParentChFFCombo = new Combo(_NRParentChFilterGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
_NRParentChFFCombo.setLayoutData(gd);
_NRParentChFFCombo.addListener(SWT.Selection, _updateNRParentChFF);
_NRParentChFMLabel = new Label(_NRParentChFilterGroup, SWT.NONE);
_NRParentChFMLabel.setText("Fault Member:");
_NRParentChFMCombo = new Combo(_NRParentChFilterGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
_NRParentChFMCombo.setLayoutData(gd);
_NRParentChFMCombo.addListener(SWT.Selection, _updateNRParentCh);
_NRParentChFCLabel = new Label(_NRParentChFilterGroup, SWT.NONE);
_NRParentChFCLabel.setText("Fault Code:");
_NRParentChFCCombo = new Combo(_NRParentChFilterGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
_NRParentChFCCombo.setLayoutData(gd);
_NRParentChFCCombo.addListener(SWT.Selection, _updateNRParentCh);
_NRParentChFilterLabel = new Label(_NRParentChFilterGroup, SWT.NONE);
_NRParentChFilterLabel.setText("Filter RegEx:");
_NRParentChFilterText = new Text(_NRParentChFilterGroup, SWT.BORDER);
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
_NRParentChFilterText.setLayoutData(gd);
_NRParentChFilterText.addListener(SWT.Modify, _updateNRParentCh);
_NRParentChAlarmList = new Table(_NRParentChGroup, SWT.BORDER);
gd = new GridData();
gd.verticalAlignment = SWT.FILL;
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessVerticalSpace = true;
gd.grabExcessHorizontalSpace = true;
_NRParentChAlarmList.setLayoutData(gd);
_NRParentChAlarmList.addListener(SWT.KeyUp, _addRule);
_NRParentChAlarmList.addListener(SWT.MouseDoubleClick, _addRule);
_NRParentErrorMessageLabel = new Label(_NRParentGroup, SWT.NONE);
_NRParentErrorMessageLabel.setText("");
_NRParentErrorMessageLabel.setForeground(getViewSite().getShell().getDisplay().getSystemColor(SWT.COLOR_RED));
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
gd.horizontalSpan = 2;
_NRParentErrorMessageLabel.setLayoutData(gd);
}
use of org.eclipse.jface.dialogs.ErrorDialog 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 });
}
use of org.eclipse.jface.dialogs.ErrorDialog in project ACS by ACS-Community.
the class CategoriesView method createViewWidgets.
private void createViewWidgets(Composite parent) {
SashForm sash = new SashForm(parent, SWT.HORIZONTAL);
sash.setLayout(new FillLayout());
/* Left pane */
Composite categoriesComp = new Composite(sash, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 1;
categoriesComp.setLayout(layout);
_listGroup = new Group(categoriesComp, SWT.SHADOW_ETCHED_IN);
GridData gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.verticalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
gd.grabExcessVerticalSpace = true;
_listGroup.setLayoutData(gd);
GridLayout gl = new GridLayout();
gl.numColumns = 1;
_listGroup.setLayout(gl);
_listGroup.setText("Categories List");
_categoriesList = new List(_listGroup, SWT.BORDER | SWT.V_SCROLL);
_categoriesList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
_categoriesList.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
public void widgetSelected(SelectionEvent e) {
Control c = _compInitial.getChildren()[0];
if (c instanceof Label) {
c.dispose();
}
_comp.setVisible(true);
_comp.layout();
/* and is shown with a "*" in the list */
if (_categoriesList.getSelection() == null || _categoriesList.getSelection().length == 0) {
_comp.setVisible(false);
_comp.layout();
return;
}
String categoryName = _categoriesList.getSelection()[0];
if (categoryName.startsWith("*"))
fillCategoryInfo((String) _categoriesList.getData());
else
fillCategoryInfo(categoryName);
if (_ffList.getItemCount() == 0)
_errorMessageLabel.setText("You have to select at least one Fault Family");
}
});
/* Add and remove buttons */
Composite categoriesButtonsComp = new Composite(categoriesComp, SWT.NONE);
layout = new GridLayout();
layout.numColumns = 2;
categoriesButtonsComp.setLayout(layout);
categoriesButtonsComp.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false));
_addCategoryButton = new Button(categoriesButtonsComp, SWT.None);
_addCategoryButton.setText("Add");
_addCategoryButton.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ADD));
_deleteCategoryButton = new Button(categoriesButtonsComp, SWT.None);
_deleteCategoryButton.setText("Delete");
_deleteCategoryButton.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ETOOL_DELETE));
Listener addCategory = new Listener() {
public void handleEvent(Event event) {
InputDialog dialog = new InputDialog(CategoriesView.this.getViewSite().getShell(), "New Category", "Enter the Category name", null, new IInputValidator() {
public String isValid(String newText) {
if (newText.trim().compareTo("") == 0)
return "The name is empty";
return null;
}
});
dialog.setBlockOnOpen(true);
dialog.open();
int returnCode = dialog.getReturnCode();
if (returnCode == InputDialog.OK) {
if (_categoryManager.getCategoryByPath(dialog.getValue()) != null) {
ErrorDialog error = new ErrorDialog(CategoriesView.this.getViewSite().getShell(), "Category already exist", "The Category " + dialog.getValue() + " already exists in the current configuration", new Status(IStatus.ERROR, "cl.utfsm.acs.acg", "The Category " + dialog.getValue() + " already exists in the current configuration"), IStatus.ERROR);
error.setBlockOnOpen(true);
error.open();
return;
}
Category newCategory = new Category();
newCategory.setPath(dialog.getValue());
InputDialog dialog2 = new InputDialog(CategoriesView.this.getViewSite().getShell(), "Category Description", "Enter the Description for the Category", null, new IInputValidator() {
public String isValid(String newText) {
if (newText.trim().compareTo("") == 0)
return "The name is empty";
return null;
}
});
dialog2.setBlockOnOpen(true);
dialog2.open();
String description = dialog2.getValue();
if (description == null)
return;
if (returnCode == InputDialog.OK)
newCategory.setDescription(description);
java.util.List<String> ffnames = sortFullFaultFamilyList();
ListSelectionDialog dialog3 = new ListSelectionDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), ffnames, new ArrayContentProvider(), new LabelProvider(), "");
dialog3.setTitle("Fault Family Selection");
dialog3.setMessage("List of Fault Families");
dialog3.setBlockOnOpen(true);
dialog3.open();
Object[] ffselected = dialog3.getResult();
if (ffselected == null)
return;
if (ffselected.length == 0) {
try {
_categoryManager.addCategory(newCategory);
} catch (IllegalOperationException e) {
ErrorDialog error = new ErrorDialog(CategoriesView.this.getViewSite().getShell(), "Category already exist", "The Category " + dialog.getValue() + " already exists in the current configuration", new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
error.setBlockOnOpen(true);
error.open();
return;
}
} else {
Alarms alarms = new Alarms();
for (int i = 0; i < ffselected.length; i++) {
try {
alarms.addFaultFamily(_alarmManager.getFaultFamily((String) ffselected[i]).getName());
//alarms.setFaultFamily(i, (String)ffselected[i]);
} catch (NullPointerException e) {
}
newCategory.setAlarms(alarms);
}
try {
_categoryManager.addCategory(newCategory);
} catch (IllegalOperationException e) {
ErrorDialog error = new ErrorDialog(CategoriesView.this.getViewSite().getShell(), "Category already exist", "The Category " + dialog.getValue() + " already exists in the current configuration", new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
error.setBlockOnOpen(true);
error.open();
return;
}
}
String[] items = new String[1];
items[0] = dialog.getValue();
refreshContents();
_categoriesList.setSelection(items);
Event e = new Event();
_categoriesList.notifyListeners(SWT.Selection, e);
IWorkbenchWindow _window = getViewSite().getWorkbenchWindow();
IViewReference[] views = _window.getActivePage().getViewReferences();
IMyViewPart view = ((IMyViewPart) views[3].getView(false));
//view.refreshContents();
view.fillWidgets();
if (_ffList.getItemCount() == 0)
_errorMessageLabel.setText("You have to select at least one Fault Family");
} else
return;
}
};
_addCategoryButton.addListener(SWT.Selection, addCategory);
Listener deleteCategory = new Listener() {
public void handleEvent(Event event) {
boolean choice = MessageDialog.openQuestion(CategoriesView.this.getViewSite().getShell(), "Confirmation", "Are you sure you want to delete this Category");
if (choice == true) {
String[] tmp = _categoriesList.getSelection();
if (tmp == null || tmp.length == 0) {
ErrorDialog error = new ErrorDialog(CategoriesView.this.getViewSite().getShell(), "Empty selection", "There are no Categories selected to be deleted", new Status(IStatus.ERROR, "cl.utfsm.acs.acg", ""), IStatus.ERROR);
error.setBlockOnOpen(true);
error.open();
return;
}
String category = tmp[0];
if (category.startsWith("*")) {
ErrorDialog error = new ErrorDialog(CategoriesView.this.getViewSite().getShell(), "Cannot delete Category", "The Category cannot be deleted", new Status(IStatus.ERROR, "cl.utfsm.acs.acg", "There must be one default category. Please select a different one before removing this category."), IStatus.ERROR);
error.setBlockOnOpen(true);
error.open();
return;
}
try {
_categoryManager.deleteCategory(_categoryManager.getCategoryByPath(category));
} catch (IllegalOperationException e) {
ErrorDialog error = new ErrorDialog(CategoriesView.this.getViewSite().getShell(), "Cannot delete Category", "The Category cannot be deleted", new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
error.setBlockOnOpen(true);
error.open();
return;
}
String[] items = null;
if (_categoriesList.getSelection() != null && _categoriesList.getSelection().length != 0) {
items = _categoriesList.getSelection();
refreshContents();
if (items == null)
if (_categoriesList.getItemCount() > 0)
_categoriesList.setSelection(0);
} else
_categoriesList.setSelection(items);
Event e = new Event();
_categoriesList.notifyListeners(SWT.Selection, e);
IWorkbenchWindow _window = getViewSite().getWorkbenchWindow();
IViewReference[] views = _window.getActivePage().getViewReferences();
IMyViewPart view = ((IMyViewPart) views[3].getView(false));
//view.refreshContents();
view.fillWidgets();
}
}
};
_deleteCategoryButton.addListener(SWT.Selection, deleteCategory);
/* To delete a FF from a given Category */
Listener deleteFaultFamily = new Listener() {
public void handleEvent(Event event) {
Category c = _categoryManager.getCategoryByPath(_pathText.getText());
try {
String[] ff = c.getAlarms().getFaultFamily();
Alarms alarms = new Alarms();
String[] temp = _ffList.getSelection();
//int j = 0;
for (int i = 0; i < ff.length; i++) {
if (ff[i].compareTo(temp[0]) == 0) {
_ffList.remove(temp[0]);
c.getAlarms().removeFaultFamily(ff[i]);
} else {
alarms.addFaultFamily(ff[i]);
//alarms.setFaultFamily(j, ff[i]);
//j++;
}
}
c.setAlarms(alarms);
_categoryManager.updateCategory(c, c);
if (_ffList.getItemCount() == 0)
_errorMessageLabel.setText("You have to select at least one Fault Family");
IWorkbenchWindow _window = getViewSite().getWorkbenchWindow();
IViewReference[] views = _window.getActivePage().getViewReferences();
IMyViewPart view = ((IMyViewPart) views[3].getView(false));
//view.refreshContents();
view.fillWidgets();
boolean inUse = false;
boolean def = false;
String defCat = "";
for (Category cat : _categoryManager.getAllCategories()) {
String[] ffs = cat.getAlarms().getFaultFamily();
for (String tff : ffs) {
if (tff.compareTo(temp[0]) == 0)
inUse = true;
}
if (cat.getIsDefault()) {
def = true;
defCat = cat.getPath();
}
}
if (!inUse) {
String msg;
if (def)
msg = "Default category: " + defCat;
else
msg = "No default category";
ErrorDialog error = new ErrorDialog(CategoriesView.this.getViewSite().getShell(), "Fault Family isn't in any Categoty", "The Fault Family is not part of any Category", new Status(IStatus.WARNING, "cl.utfsm.acs.acg", "The Fault Family " + temp[0] + " is not part of any Category (" + msg + ")"), IStatus.WARNING);
error.setBlockOnOpen(true);
error.open();
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
/* To delete all FF from a given Category */
Listener deleteAllFaultFamily = new Listener() {
public void handleEvent(Event event) {
Category c = _categoryManager.getCategoryByPath(_pathText.getText());
try {
String[] ff = c.getAlarms().getFaultFamily();
Alarms alarms = new Alarms();
for (int i = 0; i < ff.length; i++) {
_ffList.remove(ff[i]);
c.getAlarms().removeFaultFamily(ff[i]);
}
c.setAlarms(alarms);
_categoryManager.updateCategory(c, c);
IWorkbenchWindow _window = getViewSite().getWorkbenchWindow();
IViewReference[] views = _window.getActivePage().getViewReferences();
IMyViewPart view = ((IMyViewPart) views[3].getView(false));
//view.refreshContents();
view.fillWidgets();
java.util.List<String> ffList = new ArrayList<String>();
boolean def = false;
String defCat = "";
for (String cff : ff) {
Boolean inUse = false;
for (Category cat : _categoryManager.getAllCategories()) {
String[] ffs = cat.getAlarms().getFaultFamily();
for (String tff : ffs) {
if (tff.compareTo(cff) == 0)
inUse = true;
}
if (cat.getIsDefault()) {
def = true;
defCat = cat.getPath();
}
}
if (!inUse)
ffList.add(cff);
}
if (ffList.size() > 0) {
String list = "";
for (String ffel : ffList) list = list + ffel + ", ";
list.substring(0, list.length() - 2);
String msg;
if (def)
msg = "Default category: " + defCat;
else
msg = "No default category";
ErrorDialog error = new ErrorDialog(CategoriesView.this.getViewSite().getShell(), "Fault Family isn't in any Categoty", "The Fault Family is not part of any Category", new Status(IStatus.WARNING, "cl.utfsm.acs.acg", "The Fault Family(ies) " + list + " is not part of any Category (" + msg + ")"), IStatus.WARNING);
error.setBlockOnOpen(true);
error.open();
}
} catch (Exception e) {
e.printStackTrace();
}
if (_ffList.getItemCount() == 0)
_errorMessageLabel.setText("You have to select at least one Fault Family");
}
};
/* To add a new FF to a Category */
Listener addFaultFamily = new Listener() {
public void handleEvent(Event event) {
Category c = _categoryManager.getCategoryByPath(_pathText.getText());
java.util.List<String> currentffs = new ArrayList<String>();
try {
String[] ffss = c.getAlarms().getFaultFamily();
for (int i = 0; i < ffss.length; i++) {
currentffs.add(ffss[i]);
}
} catch (NullPointerException e) {
e.printStackTrace();
}
java.util.List<String> ffnames = sortFullFaultFamilyList();
ListSelectionDialog dialog3 = new ListSelectionDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), ffnames, new ArrayContentProvider(), new LabelProvider(), "");
dialog3.setTitle("Fault Family Selection");
dialog3.setMessage("List of Fault Families");
dialog3.setBlockOnOpen(true);
if (currentffs != null)
dialog3.setInitialElementSelections(currentffs);
dialog3.open();
if (dialog3.getReturnCode() == InputDialog.OK) {
Object[] ffselected = dialog3.getResult();
try {
Alarms alarms = new Alarms();
for (int i = 0; i < ffselected.length; i++) alarms.addFaultFamily(_alarmManager.getFaultFamily((String) ffselected[i]).getName());
c.setAlarms(alarms);
_categoryManager.updateCategory(c, c);
sortCategoryFaultFamilyList(c.getPath());
} catch (Exception e) {
e.printStackTrace();
}
String[] items = _categoriesList.getSelection();
refreshContents();
_categoriesList.setSelection(items);
Event e = new Event();
_categoriesList.notifyListeners(SWT.Selection, e);
IWorkbenchWindow _window = getViewSite().getWorkbenchWindow();
IViewReference[] views = _window.getActivePage().getViewReferences();
IMyViewPart view = ((IMyViewPart) views[3].getView(false));
//view.refreshContents();
view.fillWidgets();
if (_ffList.getItemCount() == 0)
_errorMessageLabel.setText("You have to select at least one Fault Family");
}
}
};
/* Initial label when no categories are selected */
_compInitial = new Composite(sash, SWT.NONE);
_compInitial.setLayout(new GridLayout());
new Label(_compInitial, SWT.NONE).setText("Select a category");
/* Fill the right pane Group that will be shown when
* a category is selected in the left list */
layout = new GridLayout();
layout.numColumns = 2;
GridData gridData = new GridData();
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
gridData.horizontalAlignment = SWT.FILL;
gridData.verticalAlignment = SWT.FILL;
_comp = new Group(_compInitial, SWT.SHADOW_ETCHED_IN);
_comp.setText("Category information");
_comp.setLayout(layout);
_comp.setLayoutData(gridData);
_pathLabel = new Label(_comp, SWT.NONE);
_pathLabel.setText("Category name");
_pathText = new Text(_comp, SWT.SINGLE | SWT.BORDER);
gridData = new GridData();
gridData.horizontalAlignment = SWT.FILL;
gridData.grabExcessHorizontalSpace = true;
_pathText.setLayoutData(gridData);
_descriptionLabel = new Label(_comp, SWT.NONE);
_descriptionLabel.setText("Category description");
_descriptionText = new Text(_comp, SWT.SINGLE | SWT.BORDER);
gridData = new GridData();
gridData.horizontalAlignment = SWT.FILL;
gridData.grabExcessHorizontalSpace = true;
_descriptionText.setLayoutData(gridData);
_isDefaultLabel = new Label(_comp, SWT.NONE);
_isDefaultLabel.setText("Is default category?");
_isDefaultCheck = new Button(_comp, SWT.CHECK);
_ffLabel = new Label(_comp, SWT.NONE);
_ffLabel.setText("Fault Families:");
gridData = new GridData();
gridData.verticalAlignment = SWT.TOP;
gridData.horizontalSpan = 2;
_ffLabel.setLayoutData(gridData);
_ffList = new List(_comp, SWT.V_SCROLL | SWT.BORDER);
gridData = new GridData();
gridData.horizontalAlignment = SWT.FILL;
gridData.grabExcessHorizontalSpace = true;
gridData.verticalAlignment = SWT.FILL;
gridData.grabExcessVerticalSpace = true;
gridData.horizontalSpan = 2;
_ffList.setLayoutData(gridData);
_errorMessageLabel = new Label(_comp, SWT.NONE);
_errorMessageLabel.setText("A");
_errorMessageLabel.setForeground(getViewSite().getShell().getDisplay().getSystemColor(SWT.COLOR_RED));
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
gd.horizontalSpan = 2;
_errorMessageLabel.setLayoutData(gd);
/* Adding a click right menu to modify the FF of a given Category */
Menu treePopUp1 = new Menu(parent);
MenuItem treePopUpAddFF = new MenuItem(treePopUp1, SWT.PUSH);
treePopUpAddFF.setText("Add a new Fault Family");
treePopUpAddFF.addListener(SWT.Selection, addFaultFamily);
MenuItem treePopUpDeleteFF = new MenuItem(treePopUp1, SWT.PUSH);
treePopUpDeleteFF.setText("Delete this Fault Family");
treePopUpDeleteFF.addListener(SWT.Selection, deleteFaultFamily);
MenuItem treePopUpDeleteAllFF = new MenuItem(treePopUp1, SWT.PUSH);
treePopUpDeleteAllFF.setText("Delete All Fault Families");
treePopUpDeleteAllFF.addListener(SWT.Selection, deleteAllFaultFamily);
_ffList.setMenu(treePopUp1);
/* Adding a click menu to add/delete Categories */
Menu treePopUp2 = new Menu(parent);
MenuItem treePopUpaddCategory = new MenuItem(treePopUp2, SWT.PUSH);
treePopUpaddCategory.setText("Add a new Category");
treePopUpaddCategory.addListener(SWT.Selection, addCategory);
MenuItem treePopUpdeleteCategory = new MenuItem(treePopUp2, SWT.PUSH);
treePopUpdeleteCategory.setText("Delete this Category");
treePopUpdeleteCategory.addListener(SWT.Selection, deleteCategory);
_categoriesList.setMenu(treePopUp2);
_comp.setVisible(false);
/* Set a weight for each side of the view */
sash.setWeights(new int[] { 3, 5 });
Listener updateCategory = new Listener() {
public void handleEvent(Event e) {
updateName();
}
};
_descriptionText.addListener(SWT.Modify, updateCategory);
_pathText.addListener(SWT.Modify, updateCategory);
_isDefaultCheck.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
String category;
if (_categoriesList.getSelection()[0].startsWith("*"))
category = (String) _categoriesList.getData();
else
category = _categoriesList.getSelection()[0];
if (_categoryManager.getCategoryByPath(category).getIsDefault() == true) {
_isDefaultCheck.setSelection(true);
MessageBox messageBox = new MessageBox(PlatformUI.getWorkbench().getDisplay().getActiveShell(), SWT.ICON_ERROR);
messageBox.setMessage("The Default Category always must exist, you can only change it");
messageBox.open();
} else {
_categoryManager.updateDefaultCategory(_categoryManager.getCategoryByPath(_categoriesList.getSelection()[0]));
String[] items = _categoriesList.getSelection();
refreshContents();
items[0] = "* " + items[0];
_categoriesList.setSelection(items);
Event e2 = new Event();
_categoriesList.notifyListeners(SWT.Selection, e2);
IWorkbenchWindow _window = getViewSite().getWorkbenchWindow();
IViewReference[] views = _window.getActivePage().getViewReferences();
IMyViewPart view = ((IMyViewPart) views[3].getView(false));
//view.refreshContents();
view.fillWidgets();
}
}
});
}
use of org.eclipse.jface.dialogs.ErrorDialog in project tdi-studio-se by Talend.
the class ComponentsLocalProviderService method validateComponent.
public boolean validateComponent(String componentFolder, ECodeLanguage language) {
if (componentFolder != null && language != null) {
File folder = new File(componentFolder);
if (folder.exists() && folder.isDirectory()) {
try {
ComponentFileChecker.checkComponentFolder(folder, language.getName().toLowerCase());
// It's ok
return true;
} catch (BusinessException e) {
final BusinessException tempE = e;
Display.getDefault().syncExec(new Runnable() {
public void run() {
Status status = new Status(IStatus.ERROR, CodeGeneratorActivator.PLUGIN_ID, 1, tempE.getMessage(), tempE.getCause());
ErrorDialog dlg = new ErrorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.getString("ComponentsLocalProviderService.talendExchangeError"), Messages.getString("ComponentsLocalProviderService.componentLoadError"), status, //$NON-NLS-1$ //$NON-NLS-2$
IStatus.ERROR);
dlg.open();
}
});
}
}
}
return false;
}
use of org.eclipse.jface.dialogs.ErrorDialog in project bndtools by bndtools.
the class RunRequirementsPart method doResolve.
private void doResolve() {
// Make sure all the parts of this editor page have committed their
// dirty state to the model
IFormPart[] parts = getManagedForm().getParts();
for (IFormPart part : parts) {
if (part.isDirty())
part.commit(false);
}
final IFormPage page = (IFormPage) getManagedForm().getContainer();
final IEditorInput input = page.getEditorInput();
final IEditorPart editor = page.getEditor();
final IFile file = ResourceUtil.getFile(input);
final Shell parentShell = page.getEditor().getSite().getShell();
// Create the wizard and pre-validate
final ResolveJob job = new ResolveJob(model);
IStatus validation = job.validateBeforeRun();
if (!validation.isOK()) {
ErrorDialog errorDialog = new ErrorDialog(parentShell, "Validation Problem", null, validation, IStatus.ERROR | IStatus.WARNING) {
@Override
protected void createButtonsForButtonBar(Composite parent) {
// create OK, Cancel and Details buttons
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false);
createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, true);
createDetailsButton(parent);
}
};
int response = errorDialog.open();
if (Window.CANCEL == response || validation.getSeverity() >= IStatus.ERROR) {
btnResolveNow.setEnabled(true);
return;
}
}
// Add the operation to perform at the end of the resolution job (i.e.,
// showing the result)
final Runnable showResult = new Runnable() {
@Override
public void run() {
ResolutionWizard wizard = new ResolutionWizard(model, file, job.getResolutionResult());
WizardDialog dialog = new WizardDialog(parentShell, wizard);
boolean dirtyBeforeResolve = editor.isDirty();
if (dialog.open() == Dialog.OK && !dirtyBeforeResolve) {
// only save the editor, when no unsaved changes happened before resolution
editor.getEditorSite().getPage().saveEditor(editor, false);
}
btnResolveNow.setEnabled(true);
}
};
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
Outcome outcome = job.getResolutionResult().getOutcome();
if (outcome != Outcome.Cancelled)
parentShell.getDisplay().asyncExec(showResult);
}
});
job.setUser(true);
job.schedule();
}
Aggregations