use of org.eclipse.jface.viewers.IStructuredContentProvider in project tmdm-studio-se by Talend.
the class MDMXSDSchemaEntryDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
parent.getShell().setText(this.title);
Composite composite = (Composite) super.createDialogArea(parent);
GridLayout layout = (GridLayout) composite.getLayout();
layout.numColumns = 1;
wcListViewer = new ListViewer(composite, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
wcListViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
((GridData) wcListViewer.getControl().getLayoutData()).minimumHeight = 200;
wcListViewer.setContentProvider(new IStructuredContentProvider() {
public void dispose() {
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
public Object[] getElements(Object inputElement) {
return ((ArrayList) inputElement).toArray(new String[] {});
}
});
wcListViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
importedUrls.clear();
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
Iterator iter = selection.iterator();
while (iter.hasNext()) {
String url = (String) iter.next();
importedUrls.add(url);
}
getButton(IDialogConstants.OK_ID).setEnabled(!selection.isEmpty());
}
});
wcListViewer.setLabelProvider(new ILabelProvider() {
public void addListener(ILabelProviderListener listener) {
}
public void dispose() {
}
public boolean isLabelProperty(Object element, String property) {
return false;
}
public void removeListener(ILabelProviderListener listener) {
}
public Image getImage(Object element) {
return null;
}
public String getText(Object element) {
return element.toString();
}
});
wcListViewer.setSorter(new ViewerSorter());
wcListViewer.setInput(urls);
return composite;
}
use of org.eclipse.jface.viewers.IStructuredContentProvider in project tmdm-studio-se by Talend.
the class AnnotationLanguageLabelsDialog method createDialogArea.
protected Control createDialogArea(Composite parent) {
// Should not really be here but well,....
parent.getShell().setText(this.title);
Composite composite = (Composite) super.createDialogArea(parent);
GridLayout layout = (GridLayout) composite.getLayout();
layout.numColumns = 3;
// layout.verticalSpacing = 10;
languagesCombo = new Combo(composite, SWT.READ_ONLY | SWT.DROP_DOWN | SWT.SINGLE);
languagesCombo.setLayoutData(new GridData(SWT.BEGINNING, SWT.NONE, false, false, 1, 1));
Set<String> languages = Util.lang2iso.keySet();
for (Iterator iter = languages.iterator(); iter.hasNext(); ) {
String language = (String) iter.next();
languagesCombo.add(language);
}
languagesCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
}
});
languagesCombo.select(0);
labelText = new Text(composite, SWT.BORDER | SWT.SINGLE);
labelText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
((GridData) labelText.getLayoutData()).minimumWidth = 150;
labelText.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
if ((e.stateMask == 0) && (e.character == SWT.CR)) {
String isoCode = Util.lang2iso.get(languagesCombo.getText());
descriptionsMap.put(isoCode, labelText.getText());
descriptionsViewer.refresh();
}
}
});
Button addLabelButton = new Button(composite, SWT.PUSH);
addLabelButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
addLabelButton.setImage(ImageCache.getCreatedImage(EImage.ADD_OBJ.getPath()));
addLabelButton.setToolTipText(Messages.AnnotationLanguageLabelsDialog_Add);
addLabelButton.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
}
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
String code = Util.lang2iso.get(languagesCombo.getText());
descriptionsMap.put(code, labelText.getText());
descriptionsViewer.refresh();
}
});
final String LANGUAGE = Messages.AnnotationLanguageLabelsDialog_Language;
final String LABEL = Messages.AnnotationLanguageLabelsDialog_Label;
descriptionsViewer = new TableViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
descriptionsViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
((GridData) descriptionsViewer.getControl().getLayoutData()).heightHint = 100;
// Set up the underlying table
Table table = descriptionsViewer.getTable();
// table.setLayoutData(new GridData(GridData.FILL_BOTH));
new TableColumn(table, SWT.LEFT).setText(LANGUAGE);
new TableColumn(table, SWT.CENTER).setText(LABEL);
table.getColumn(0).setWidth(150);
table.getColumn(1).setWidth(150);
for (int i = 2, n = table.getColumnCount(); i < n; i++) {
table.getColumn(i).pack();
}
table.setHeaderVisible(true);
table.setLinesVisible(true);
Button delLabelButton = new Button(composite, SWT.PUSH);
delLabelButton.setLayoutData(new GridData(SWT.NONE, SWT.NONE, false, false, 1, 1));
delLabelButton.setImage(ImageCache.getCreatedImage(EImage.DELETE_OBJ.getPath()));
delLabelButton.setToolTipText(Messages.AnnotationLanguageLabelsDialog_Del);
delLabelButton.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
}
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
deleteItem();
}
});
// Create the cell editors --> We actually discard those later: not natural for an user
CellEditor[] editors = new CellEditor[2];
editors[0] = new ComboBoxCellEditor(table, Util.lang2iso.keySet().toArray(new String[] {}), SWT.READ_ONLY);
editors[1] = new TextCellEditor(table);
descriptionsViewer.setCellEditors(editors);
// set the content provider
descriptionsViewer.setContentProvider(new IStructuredContentProvider() {
public void dispose() {
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
public Object[] getElements(Object inputElement) {
// System.out.println("getElements() ");
LinkedHashMap<String, String> descs = (LinkedHashMap<String, String>) inputElement;
Set<String> languages = descs.keySet();
ArrayList<DescriptionLine> lines = new ArrayList<DescriptionLine>();
for (Iterator iter = languages.iterator(); iter.hasNext(); ) {
String language = ((String) iter.next());
DescriptionLine line = new DescriptionLine(Util.iso2lang.get(language), descs.get(language));
lines.add(line);
}
// we return an instance line made of a Sring and a boolean
return lines.toArray(new DescriptionLine[lines.size()]);
}
});
// set the label provider
descriptionsViewer.setLabelProvider(new ITableLabelProvider() {
public boolean isLabelProperty(Object element, String property) {
return false;
}
public void dispose() {
}
public void addListener(ILabelProviderListener listener) {
}
public void removeListener(ILabelProviderListener listener) {
}
public String getColumnText(Object element, int columnIndex) {
// System.out.println("getColumnText() "+columnIndex);
DescriptionLine line = (DescriptionLine) element;
switch(columnIndex) {
case 0:
return line.getLanguage();
case 1:
return line.getLabel();
}
// $NON-NLS-1$
return "";
}
public Image getColumnImage(Object element, int columnIndex) {
return null;
}
});
// Set the column properties
descriptionsViewer.setColumnProperties(new String[] { LANGUAGE, LABEL });
// set the Cell Modifier
descriptionsViewer.setCellModifier(new ICellModifier() {
public boolean canModify(Object element, String property) {
// if (INSTANCE_ACCESS.equals(property)) return true; Deactivated
return true;
}
public void modify(Object element, String property, Object value) {
TableItem item = (TableItem) element;
int columnIndex = Arrays.asList(descriptionsViewer.getColumnProperties()).indexOf(property);
DescriptionLine line = (DescriptionLine) item.getData();
if (columnIndex == 0) {
String[] attrs = Util.lang2iso.keySet().toArray(new String[] {});
int orgIndx = Arrays.asList(attrs).indexOf(line.getLanguage());
if (orgIndx != Integer.parseInt(value.toString())) {
String newLang = attrs[Integer.parseInt(value.toString())];
if (descriptionsMap.containsKey(Util.lang2iso.get(newLang))) {
MessageDialog.openInformation(null, Messages.Warnning, Messages.AnnotationLanguageLabelsDialog_InforContent);
return;
}
descriptionsMap.remove(Util.lang2iso.get(line.getLanguage()));
line.setLanguage(newLang);
descriptionsMap.put(Util.lang2iso.get(newLang), line.getLabel());
}
} else // column label
{
line.setLabel(value.toString());
descriptionsMap.put(Util.lang2iso.get(line.getLanguage()), line.getLabel());
}
descriptionsViewer.update(line, null);
}
public Object getValue(Object element, String property) {
int columnIndex = Arrays.asList(descriptionsViewer.getColumnProperties()).indexOf(property);
DescriptionLine line = (DescriptionLine) element;
if (columnIndex == 0) {
String[] attrs = Util.lang2iso.keySet().toArray(new String[] {});
return Arrays.asList(attrs).indexOf(line.getLanguage());
} else {
if (LANGUAGE.equals(property)) {
return line.getLanguage();
}
if (LABEL.equals(property)) {
return line.getLabel();
}
}
return null;
}
});
// Listen for changes in the selection of the viewer to display additional parameters
descriptionsViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
}
});
// display for Delete Key events to delete an instance
descriptionsViewer.getTable().addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
// System.out.println("Table keyReleased() ");
if ((e.stateMask == 0) && (e.character == SWT.DEL) && (descriptionsViewer.getSelection() != null)) {
deleteItem();
}
}
});
descriptionsViewer.setInput(descriptionsMap);
descriptionsViewer.refresh();
labelText.setFocus();
return composite;
}
use of org.eclipse.jface.viewers.IStructuredContentProvider in project tmdm-studio-se by Talend.
the class ComplexTypeWrapper method changeTypeName.
public boolean changeTypeName() {
if (curXSDComplexType.getName().equals(newTypeName))
return false;
curXSDComplexType.setName(newTypeName);
curXSDComplexType.updateElement();
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart activeEditor = activePage.getActiveEditor();
if (activeEditor instanceof XSDEditor) {
XSDEditor editor = (XSDEditor) activeEditor;
DataModelMainPage page = editor.getdMainPage();
IStructuredContentProvider provider = (IStructuredContentProvider) page.getSchemaContentProvider();
Util.updateReferenceToXSDTypeDefinition(page.getSite(), curXSDComplexType, provider);
}
return true;
}
use of org.eclipse.jface.viewers.IStructuredContentProvider in project tmdm-studio-se by Talend.
the class SimpleTypeWrapper method changeTypeName.
public boolean changeTypeName() {
if (getNewTypeName().trim().equals(getOldTypeName()))
return false;
xsdSimpleType.setName(getNewTypeName().trim());
xsdSimpleType.updateElement();
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart activeEditor = activePage.getActiveEditor();
if (activeEditor instanceof XSDEditor) {
XSDEditor editor = (XSDEditor) activeEditor;
DataModelMainPage page = editor.getdMainPage();
IStructuredContentProvider provider = (IStructuredContentProvider) page.getSchemaContentProvider();
Util.updateReferenceToXSDTypeDefinition(page.getSite(), xsdSimpleType, provider);
}
return true;
}
use of org.eclipse.jface.viewers.IStructuredContentProvider in project tmdm-studio-se by Talend.
the class XSDDeleteElementAction method doAction.
public IStatus doAction() {
try {
// xsdElem is to support the multiple delete action on key press,
// which each delete action on element must be explicit passed a xsdElem to
// delete
XSDElementDeclaration decl = xsdElem;
if (decl == null) {
ISelection selection = page.getTreeViewer().getSelection();
decl = (XSDElementDeclaration) ((IStructuredSelection) selection).getFirstElement();
}
ArrayList<Object> objList = new ArrayList<Object>();
IStructuredContentProvider provider = (IStructuredContentProvider) page.getTreeViewer().getContentProvider();
Object[] all = Util.getAllObject(page.getSite(), objList, provider);
Util.deleteReference(decl, all);
// remove declaration
schema.getContents().remove(decl);
schema.update();
xsdElem = null;
page.refresh();
page.markDirtyWithoutCommit();
} catch (Exception e) {
log.error(e.getMessage(), e);
MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDDeleteElementAction_ErrorMsg, e.getLocalizedMessage()));
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
Aggregations