use of org.eclipse.swt.widgets.MenuItem in project translationstudio8 by heartsome.
the class ProjectSettingTMPage method createContents.
/**
* Create contents of the preference page.
* @param parent
*/
@Override
public Control createContents(Composite parent) {
Composite container = new Composite(parent, SWT.NULL);
container.setLayout(new GridLayout(1, false));
tableViewer = new TableViewer(container, SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE);
Table table = tableViewer.getTable();
table.setLinesVisible(true);
table.setHeaderVisible(true);
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
tableViewer.setContentProvider(new ArrayContentProvider());
createColumn(tableViewer);
tableViewer.setInput(curDbList);
tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
DatabaseModelBean dbModel = (DatabaseModelBean) selection.getFirstElement();
if (null == dbModel) {
return;
}
if (Constants.DBTYPE_SQLITE.equals(dbModel.getDbType())) {
String path = dbModel.getItlDBLocation() + File.separator + dbModel.getDbName();
File file = new File(path);
if (!file.exists()) {
setMessage(Messages.getString("projectsetting.ProjectSettingTMPage.FileNotFound"));
return;
} else {
setMessage(Messages.getString("projectsetting.ProjectSettingTMPage.title"));
}
}
if (dbModel != null && !dbModel.isHasMatch()) {
setMessage(Messages.getString("projectsetting.ProjectSettingTMPage.msg1"));
}
}
});
Composite composite = new Composite(container, SWT.NONE);
composite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
composite.setLayout(new GridLayout(5, false));
new Label(composite, SWT.NONE);
HSDropDownButton addBtn = new HSDropDownButton(composite, SWT.NONE);
addBtn.setText(Messages.getString("projectsetting.ProjectSettingTMPage.addBtn"));
Menu addMenu = addBtn.getMenu();
MenuItem item = new MenuItem(addMenu, SWT.PUSH);
item.setText(Messages.getString("tm.dialog.addTm.DropDownButton.AddFileTm"));
item.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
FileDialog fileDialg = new FileDialog(getShell());
fileDialg.setFilterExtensions(new String[] { "*.hstm", "*.*" });
String result = fileDialg.open();
if (result == null) {
return;
}
File f = new File(result);
if (!f.exists()) {
return;
}
Map<DatabaseModelBean, String> r = null;
try {
r = Utils.convertFile2TmModel(f, false);
} catch (Exception e1) {
MessageDialog.openError(getShell(), Messages.getString("tm.dialog.addFileTm.errorTitle"), e1.getMessage());
}
if (r == null) {
return;
}
Iterator<DatabaseModelBean> it = r.keySet().iterator();
if (it.hasNext()) {
DatabaseModelBean selectedVal = it.next();
List<DatabaseModelBean> dbList = new ArrayList<DatabaseModelBean>();
dbList.add(selectedVal);
addToCurrDbList(dbList);
}
}
});
MenuItem serverItem = new MenuItem(addMenu, SWT.PUSH);
serverItem.setText(Messages.getString("tm.dialog.addTm.DropDownButton.AddServerTm"));
serverItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
TmDbManagerDialog dialog = new TmDbManagerDialog(getShell());
dialog.setDialogUseFor(TmDbManagerDialog.TYPE_DBSELECTED);
if (dialog.open() == Window.OK) {
Iterator<DatabaseModelBean> it = dialog.getHasSelectedDatabase().keySet().iterator();
List<DatabaseModelBean> dbList = new ArrayList<DatabaseModelBean>();
while (it.hasNext()) {
dbList.add(it.next());
}
addToCurrDbList(dbList);
}
}
});
Button createBtn = new Button(composite, SWT.NONE);
createBtn.setText(Messages.getString("projectsetting.ProjectSettingTMPage.createBtn"));
createBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
NewTmDbWizard wizard = new NewTmDbWizard();
ImportTmxWizardDialog dlg = new ImportTmxWizardDialog(getShell(), wizard);
if (dlg.open() == 0) {
DatabaseModelBean dbModel = wizard.getCreateDb();
List<DatabaseModelBean> dbList = new ArrayList<DatabaseModelBean>();
dbList.add(dbModel);
addToCurrDbList(dbList);
}
}
});
Button removeBtn = new Button(composite, SWT.NONE);
removeBtn.setText(Messages.getString("projectsetting.ProjectSettingTMPage.removeBtn"));
removeBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
removeForCurrDbList((IStructuredSelection) tableViewer.getSelection());
}
});
Button importTmxBtn = new Button(composite, SWT.NONE);
importTmxBtn.setText(Messages.getString("projectsetting.ProjectSettingTMPage.importTmxBtn"));
importTmxBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
Iterator<?> it = selection.iterator();
if (it.hasNext()) {
DatabaseModelBean dbModel = (DatabaseModelBean) it.next();
ImportTmxWizard wizard = new ImportTmxWizard(dbModel);
ImportTmxWizardDialog dlg = new ImportTmxWizardDialog(getShell(), wizard);
if (dlg.open() == 0) {
checkDbHashMatch(dbModel);
tableViewer.refresh();
}
// 刷新项目
ResourceUtils.refreshCurentSelectProject();
} else {
MessageDialog.openInformation(getShell(), Messages.getString("projectsetting.ProjectSettingTMPage.msgTitle"), Messages.getString("projectsetting.ProjectSettingTMPage.msg2"));
}
}
});
addBtn.setFocus();
Point addPoint = addBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
Point createPoint = createBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
Point remPoint = removeBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
Point importPoint = importTmxBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
int width = Math.max(importPoint.x, Math.max(remPoint.x, Math.max(addPoint.x, createPoint.x)));
GridData btnData = new GridData();
btnData.widthHint = width + 10;
addBtn.setLayoutData(btnData);
createBtn.setLayoutData(btnData);
removeBtn.setLayoutData(btnData);
importTmxBtn.setLayoutData(btnData);
return container;
}
use of org.eclipse.swt.widgets.MenuItem in project translationstudio8 by heartsome.
the class CustomMatchContributionItem method fill.
@Override
public void fill(Menu menu, int index) {
LinkedHashMap<String, String> map = XLFHandler.getCustomMatchFilterMap();
if (map == null || map.size() == 0) {
for (Item item : menu.getItems()) {
if (!item.isDisposed()) {
item.dispose();
}
}
} else {
for (Entry<String, String> entry : map.entrySet()) {
final String xpath = entry.getValue();
MenuItem item = new MenuItem(menu, SWT.PUSH);
item.setText(entry.getKey());
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
XLIFFEditorImplWithNatTable xliffEditor = XLIFFEditorImplWithNatTable.getCurrent();
if (xliffEditor == null) {
return;
}
xliffEditor.getXLFHandler().deleteAltTrans(xpath);
ArrayList<Integer> rowList = new ArrayList<Integer>();
int[] rows = xliffEditor.getSelectedRows();
for (int i : rows) {
rowList.add(i);
}
StructuredSelection selection = new StructuredSelection(rowList);
xliffEditor.getSite().getSelectionProvider().setSelection(selection);
}
});
}
}
}
use of org.eclipse.swt.widgets.MenuItem in project tdi-studio-se by Talend.
the class AbstractXMLConfigPage method initialize.
/*
* (non-Javadoc)
*
* @see org.talend.componentdesigner.ui.wizard.creatcomponent.AbstractComponentPage#initialize()
*/
protected void initialize() {
availableXmlTree.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
if (availableXmlTree.getMenu() != null) {
availableXmlTree.getMenu().dispose();
}
final TreeItem[] treeItem = ((Tree) event.getSource()).getSelection();
Menu popMenu = new Menu(availableXmlTree);
MenuItem itemNew = new MenuItem(popMenu, SWT.CASCADE);
//$NON-NLS-1$
itemNew.setText(Messages.getString("AbstractXMLConfigPage.New"));
MenuItem itemDel = new MenuItem(popMenu, SWT.CASCADE);
//$NON-NLS-1$
itemDel.setText(Messages.getString("AbstractXMLConfigPage.Delete"));
itemDel.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
TreeNodeData currentNodeData = (TreeNodeData) treeItem[0].getParentItem().getData();
currentNodeData.getXMLNode().removeChild(((TreeNodeData) treeItem[0].getData()).getXMLNode());
treeItem[0].dispose();
}
});
final TreeNodeData treeNodeData = ((TreeNodeData) treeItem[0].getData());
if (treeNodeData.isHasChildTreeNode()) {
Menu subNewMenu = new Menu(itemNew);
itemNew.setMenu(subNewMenu);
Object[] subNodeNames = treeNodeData.getChildNodeNames();
for (Object nodeName : subNodeNames) {
final MenuItem nodeMenuItem = new MenuItem(subNewMenu, SWT.CASCADE);
final String itemName = (String) nodeName;
nodeMenuItem.setText(itemName);
nodeMenuItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
TreeItem newItem = new TreeItem(treeItem[0], 0);
newItem.setText(itemName);
TreeNodeData newNodeData = null;
newNodeData = new TreeNodeData();
Node parentNode = treeNodeData.getXMLNode();
newNodeData.setXMLNode(parentNode.appendChild(parentNode.getOwnerDocument().createElement(itemName)));
//$NON-NLS-1$
newNodeData.setTreePath(treeNodeData.getTreePath() + "/" + itemName);
newNodeData.setTreeNode(ATreeNodeUtil.getTreeNodeByPath(newNodeData.getTreePath()));
newItem.setData(newNodeData);
}
});
}
} else {
itemNew.setEnabled(false);
}
availableXmlTree.setMenu(popMenu);
if (nodeAttrCompsite != null) {
nodeAttrCompsite.dispose();
}
rebuildAttrComposite(treeNodeData);
setComponentMinSize(treeNodeData.getTreeNode().getLabel());
rightComposite.layout();
}
});
}
use of org.eclipse.swt.widgets.MenuItem in project tesb-studio-se by Talend.
the class SpringConfigurationStyledText method menuDetected.
public void menuDetected(MenuDetectEvent e) {
/*
* create context menus
* and set a data for each item
* which will be used on listener to indicate the item
*/
Menu m = new Menu(this);
MenuItem copyItem = new MenuItem(m, SWT.NONE);
copyItem.setText("&Copy\tCtrl+C");
copyItem.setEnabled(!"".equals(getSelectionText()));
copyItem.setData('c');
MenuItem pasteItem = new MenuItem(m, SWT.NONE);
pasteItem.setText("&Paste\tCopy+V");
pasteItem.setData('p');
MenuItem cutItem = new MenuItem(m, SWT.NONE);
cutItem.setText("Cu&t\tCtrl+X");
cutItem.setEnabled(!"".equals(getSelectionText()));
cutItem.setData('t');
new MenuItem(m, SWT.SEPARATOR);
MenuItem selectAllItem = new MenuItem(m, SWT.NONE);
selectAllItem.setText("&Select All\tCtrl+A");
selectAllItem.setData('s');
new MenuItem(m, SWT.SEPARATOR);
MenuItem undoItem = new MenuItem(m, SWT.NONE);
undoItem.setText("&Undo\tCtrl+Z");
undoItem.setEnabled(undoStack.size() > 0);
undoItem.setData('u');
MenuItem redoItem = new MenuItem(m, SWT.NONE);
redoItem.setText("&Redo\tCtrl+Y");
redoItem.setEnabled(redoStack.size() > 0);
redoItem.setData('r');
new MenuItem(m, SWT.SEPARATOR);
MenuItem commentItem = null;
if (isCommentAvailable()) {
commentItem = new MenuItem(m, SWT.NONE);
commentItem.setText("&Comment\tCtrl+Shift+/");
commentItem.setData('/');
} else if (selectionIsCommented()) {
commentItem = new MenuItem(m, SWT.NONE);
commentItem.setText("&Uncomment\tCtrl+Shift+/");
commentItem.setData('/');
}
setMenu(m);
SelectionAdapter listener = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Object data = e.widget.getData();
if (data == null || !(data instanceof Character)) {
return;
}
switch((Character) data) {
case 'c':
copy();
break;
case 'p':
paste();
break;
case 't':
cut();
break;
case 's':
selectAll();
break;
case 'u':
undo();
break;
case 'r':
redo();
break;
case '/':
commentEventHandler();
break;
default:
break;
}
}
};
copyItem.addSelectionListener(listener);
pasteItem.addSelectionListener(listener);
cutItem.addSelectionListener(listener);
selectAllItem.addSelectionListener(listener);
undoItem.addSelectionListener(listener);
redoItem.addSelectionListener(listener);
if (commentItem != null) {
commentItem.addSelectionListener(listener);
}
}
use of org.eclipse.swt.widgets.MenuItem in project ACS by ACS-Community.
the class AlarmsView method createFFWidgets.
private void createFFWidgets() {
_updateFaultFamily = new Listener() {
public void handleEvent(Event event) {
TreeItem tmp = _tree.getSelection()[0];
String ff = tmp.getText();
FaultFamily fft = new FaultFamily();
//TODO: Error icon or something similar
if (_ffNameText.getText().isEmpty()) {
_ffErrorMessageLabel.setText("FaultFamily Name Missing!");
return;
}
if (_ffNameText.getText().contains(" ")) {
_ffErrorMessageLabel.setText("Invalid FaultFamily Name. No spaces allowed.");
return;
}
fft.setName(_ffNameText.getText());
if (!_ffHelpURLText.getText().isEmpty()) {
URI hurl;
try {
hurl = new URI(_ffHelpURLText.getText());
} catch (MalformedURIException e1) {
_ffErrorMessageLabel.setText("Malformed URL!");
return;
}
fft.setHelpUrl(hurl.toString());
}
fft.setAlarmSource(_ffSourceCombo.getText());
Contact ct = new Contact();
if (_ffContactNameText.getText().isEmpty()) {
_ffErrorMessageLabel.setText("Contact Name Missing!");
return;
}
ct.setName(_ffContactNameText.getText());
if (!_ffContactMailText.getText().isEmpty())
ct.setEmail(_ffContactMailText.getText());
if (!_ffContactGSMText.getText().isEmpty())
ct.setGsm(_ffContactGSMText.getText());
fft.setContact(ct);
_ffErrorMessageLabel.setText("");
try {
_alarmManager.updateFaultFamily(_alarmManager.getFaultFamily(ff), fft);
tmp.setText(_ffNameText.getText());
IWorkbenchWindow _window = getViewSite().getWorkbenchWindow();
IViewReference[] views = _window.getActivePage().getViewReferences();
IMyViewPart view = ((IMyViewPart) views[2].getView(false));
view.fillWidgets();
if (ff.compareTo(fft.getName()) != 0) {
sortFaultFamilyList();
selectElementFromTree(fft.getName(), null, null);
}
} catch (IllegalOperationException e) {
_ffErrorMessageLabel.setText(e.getMessage());
} catch (NullPointerException e) {
e.printStackTrace();
_ffErrorMessageLabel.setText(e.getMessage());
}
}
};
_addCategory = new Listener() {
public void handleEvent(Event event) {
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 (_ffCategoryList.getItem(pt) == null)
return;
}
TreeItem[] tmp1 = _tree.getSelection();
if (tmp1 == null || tmp1.length == 0)
return;
String ff = tmp1[0].getText();
TableItem[] tmp2 = _ffCategoryList.getSelection();
if (tmp2 == null || tmp2.length == 0)
return;
TableItem item = tmp2[0];
Category c = _categoryManager.getCategoryByPath(item.getText());
try {
String[] ffs = c.getAlarms().getFaultFamily();
for (int i = 0; i < ffs.length; i++) {
if (ff.compareTo(ffs[i]) == 0) {
c.getAlarms().removeFaultFamily(ff);
item.setImage((org.eclipse.swt.graphics.Image) null);
IWorkbenchWindow _window = getViewSite().getWorkbenchWindow();
IViewReference[] views = _window.getActivePage().getViewReferences();
IMyViewPart view = ((IMyViewPart) views[2].getView(false));
view.fillWidgets();
return;
}
}
c.getAlarms().addFaultFamily(ff);
item.setImage(Activator.getDefault().getImageRegistry().get(Activator.IMG_TICKET));
} catch (NullPointerException e) {
item.setImage((org.eclipse.swt.graphics.Image) null);
Alarms alarms = new Alarms();
alarms.addFaultFamily(ff.toString());
alarms.setFaultFamily(0, ff.toString());
c.setAlarms(alarms);
item.setImage(Activator.getDefault().getImageRegistry().get(Activator.IMG_TICKET));
}
IWorkbenchWindow _window = getViewSite().getWorkbenchWindow();
IViewReference[] views = _window.getActivePage().getViewReferences();
IMyViewPart view = ((IMyViewPart) views[2].getView(false));
view.fillWidgets();
}
};
_FFgroup = new Group(_compInitial, SWT.SHADOW_ETCHED_IN);
_FFgroup.setText("Fault Family details");
GridData gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
gd.verticalAlignment = SWT.FILL;
gd.grabExcessVerticalSpace = true;
_FFgroup.setLayoutData(gd);
GridLayout gl = new GridLayout();
gl.numColumns = 2;
_FFgroup.setLayout(gl);
_ffNameLabel = new Label(_FFgroup, SWT.NONE);
_ffNameLabel.setText("Fault Family name");
_ffNameText = new Text(_FFgroup, SWT.SINGLE | SWT.BORDER);
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
_ffNameText.setLayoutData(gd);
_ffNameText.addListener(SWT.Modify, _updateFaultFamily);
_ffHelpURLLabel = new Label(_FFgroup, SWT.NONE);
_ffHelpURLLabel.setText("Help URL");
_ffHelpURLText = new Text(_FFgroup, SWT.SINGLE | SWT.BORDER);
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
_ffHelpURLText.setLayoutData(gd);
_ffHelpURLText.addListener(SWT.Modify, _updateFaultFamily);
_ffContactNameLabel = new Label(_FFgroup, SWT.NONE);
_ffContactNameLabel.setText("Contact name");
_ffContactNameText = new Text(_FFgroup, SWT.SINGLE | SWT.BORDER);
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
_ffContactNameText.setLayoutData(gd);
_ffContactNameText.addListener(SWT.Modify, _updateFaultFamily);
_ffContactMailLabel = new Label(_FFgroup, SWT.NONE);
_ffContactMailLabel.setText("Contact e-mail");
_ffContactMailText = new Text(_FFgroup, SWT.SINGLE | SWT.BORDER);
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
_ffContactMailText.setLayoutData(gd);
_ffContactMailText.addListener(SWT.Modify, _updateFaultFamily);
_ffContactGSMLabel = new Label(_FFgroup, SWT.NONE);
_ffContactGSMLabel.setText("Contact GSM");
_ffContactGSMText = new Text(_FFgroup, SWT.SINGLE | SWT.BORDER);
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
_ffContactGSMText.setLayoutData(gd);
_ffContactGSMText.addListener(SWT.Modify, _updateFaultFamily);
_ffSourceLabel = new Label(_FFgroup, SWT.NONE);
_ffSourceLabel.setText("Source");
_ffSourceCombo = new Combo(_FFgroup, SWT.DROP_DOWN | SWT.READ_ONLY);
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
_ffSourceCombo.setLayoutData(gd);
_ffSourceCombo.setEnabled(false);
_ffSourceCombo.addListener(SWT.Modify, _updateFaultFamily);
_ffCategoryLabel = new Label(_FFgroup, SWT.NONE);
_ffCategoryLabel.setText("Categories:");
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
gd.horizontalSpan = 2;
_ffCategoryLabel.setLayoutData(gd);
_ffCategoryList = new Table(_FFgroup, SWT.BORDER);
gd = new GridData();
gd.verticalAlignment = SWT.FILL;
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessVerticalSpace = true;
gd.grabExcessHorizontalSpace = true;
gd.horizontalSpan = 2;
_ffCategoryList.setLayoutData(gd);
_ffCategoryList.addListener(SWT.KeyUp, _addCategory);
_ffCategoryList.addListener(SWT.MouseDoubleClick, _addCategory);
Menu categoryPopUp = new Menu(_ffCategoryList);
_ffCategoryList.setMenu(categoryPopUp);
categoryPopUp.addListener(SWT.Show, new Listener() {
public void handleEvent(Event e) {
TableItem[] sel = _ffCategoryList.getSelection();
Menu categoryPopUp = _ffCategoryList.getMenu();
MenuItem[] items = categoryPopUp.getItems();
for (int i = 0; i < items.length; i++) items[i].dispose();
if (sel == null || sel.length == 0)
return;
MenuItem mitem;
mitem = new MenuItem(categoryPopUp, SWT.PUSH);
if (sel[0].getImage() == null) {
mitem.setText("Add to Category");
mitem.addListener(SWT.Selection, _addCategory);
} else {
mitem.setText("Remove from Category");
mitem.addListener(SWT.Selection, _addCategory);
}
}
});
_ffErrorMessageLabel = new Label(_FFgroup, SWT.NONE);
_ffErrorMessageLabel.setText("");
_ffErrorMessageLabel.setForeground(getViewSite().getShell().getDisplay().getSystemColor(SWT.COLOR_RED));
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
gd.horizontalSpan = 2;
_ffErrorMessageLabel.setLayoutData(gd);
}
Aggregations