use of org.eclipse.jface.viewers.ViewerSorter in project tdi-studio-se by Talend.
the class LoginProjectPage method instantiateControl.
@Override
public void instantiateControl(Composite container) {
/**
* 1. Create all the control first
*/
//$NON-NLS-1$
String execute = Messages.getString("LoginProjectPage.execute");
// Image openImage = ImageProvider.getImage(ERepositoryImages.OPEN_PROJECT_ICON);
// Connection Area
title = new Label(container, SWT.NONE);
title.setFont(LoginDialogV2.fixedFont);
//$NON-NLS-1$
title.setText(Messages.getString("LoginProjectPage.title"));
connectionManageArea = new Composite(container, SWT.NONE);
connectionsViewer = new ComboViewer(connectionManageArea, SWT.READ_ONLY);
connectionsViewer.getControl().setFont(LoginDialogV2.fixedFont);
manageButton = new Button(connectionManageArea, SWT.NONE);
manageButton.setFont(LoginDialogV2.fixedFont);
manageButton.setBackground(backgroundColor);
//$NON-NLS-1$
manageButton.setText(Messages.getString("LoginProjectPage.manage"));
// Project Operation Area
projectOperationArea = new Composite(container, SWT.NONE);
// Existing Project Area
selectExistingProject = new Button(projectOperationArea, SWT.RADIO);
selectExistingProject.setFont(LoginDialogV2.fixedFont);
selectExistingProject.setBackground(backgroundColor);
//$NON-NLS-1$
selectExistingProject.setText(Messages.getString("LoginProjectPage.selectProject"));
projectListArea = new Composite(projectOperationArea, SWT.NONE);
projectViewer = new ListViewer(projectListArea, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
projectViewer.getControl().setFont(LoginDialogV2.fixedFont);
projectViewer.setContentProvider(ArrayContentProvider.getInstance());
projectViewer.setLabelProvider(new ProjectLabelProvider());
projectViewer.setSorter(new ViewerSorter());
// Branch Area
branchArea = new Composite(projectListArea, SWT.NONE);
branchLabel = new Label(branchArea, SWT.NONE);
branchLabel.setFont(LoginDialogV2.fixedFont);
//$NON-NLS-1$
branchLabel.setText(Messages.getString("LoginProjectPage.Branch"));
branchesViewer = new ComboViewer(branchArea, SWT.READ_ONLY);
branchesViewer.getControl().setFont(LoginDialogV2.fixedFont);
branchesViewer.setContentProvider(ArrayContentProvider.getInstance());
branchesViewer.setLabelProvider(new LabelProvider());
refreshProjectButton = new Button(branchArea, SWT.NONE);
refreshProjectButton.setFont(LoginDialogV2.fixedFont);
refreshProjectButton.setBackground(backgroundColor);
refreshProjectButton.setImage(ImageProvider.getImage(EImage.REFRESH_ICON));
// Create New Project
createNewProject = new Button(projectOperationArea, SWT.RADIO);
createNewProject.setFont(LoginDialogV2.fixedFont);
createNewProject.setBackground(backgroundColor);
//$NON-NLS-1$
createNewProject.setText(Messages.getString("LoginProjectPage.createNewProject"));
newProjectName = new Text(projectOperationArea, SWT.BORDER);
newProjectName.setFont(LoginDialogV2.fixedFont);
newProjectName.setBackground(backgroundColor);
executeCreateNewProject = new Button(projectOperationArea, SWT.NONE);
executeCreateNewProject.setFont(LoginDialogV2.fixedFont);
//$NON-NLS-1$
executeCreateNewProject.setText(Messages.getString("LoginProjectPage.create"));
executeCreateNewProject.setBackground(backgroundColor);
// Import Demo Project
importDemoProject = new Button(projectOperationArea, SWT.RADIO);
importDemoProject.setFont(LoginDialogV2.fixedFont);
importDemoProject.setBackground(backgroundColor);
//$NON-NLS-1$
importDemoProject.setText(Messages.getString("LoginProjectPage.importDemoProject"));
executeImportDemoProject = new Button(projectOperationArea, SWT.NONE);
executeImportDemoProject.setFont(LoginDialogV2.fixedFont);
// executeImportDemoProject.setImage(openImage);
executeImportDemoProject.setText(execute);
executeImportDemoProject.setBackground(backgroundColor);
// Import Local Project
importLocalProject = new Button(projectOperationArea, SWT.RADIO);
importLocalProject.setFont(LoginDialogV2.fixedFont);
importLocalProject.setBackground(backgroundColor);
//$NON-NLS-1$
importLocalProject.setText(Messages.getString("LoginProjectPage.importLocalProject"));
executeImportLocalProject = new Button(projectOperationArea, SWT.NONE);
executeImportLocalProject.setFont(LoginDialogV2.fixedFont);
// executeImportLocalProject.setImage(openImage);
executeImportLocalProject.setText(execute);
executeImportLocalProject.setBackground(backgroundColor);
// Create SandBox Project
createSandBoxProject = new Button(projectOperationArea, SWT.RADIO);
createSandBoxProject.setFont(LoginDialogV2.fixedFont);
createSandBoxProject.setBackground(backgroundColor);
//$NON-NLS-1$
createSandBoxProject.setText(Messages.getString("LoginProjectPage.createSandBoxProject.title"));
executeCreateSandBoxProject = new Button(projectOperationArea, SWT.NONE);
executeCreateSandBoxProject.setFont(LoginDialogV2.fixedFont);
// executeCreateSandBoxProject.setImage(openImage);
executeCreateSandBoxProject.setText(execute);
executeCreateSandBoxProject.setBackground(backgroundColor);
super.instantiateControl(container);
}
use of org.eclipse.jface.viewers.ViewerSorter in project tdi-studio-se by Talend.
the class ImportItemWizardPage method createErrorsList.
private void createErrorsList(Composite workArea) {
Composite composite = new Composite(workArea, SWT.NONE);
GridLayout layout = new GridLayout();
layout.makeColumnsEqualWidth = false;
layout.marginWidth = 0;
composite.setLayout(layout);
GridData gridData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
gridData.heightHint = 100;
composite.setLayoutData(gridData);
Label title = new Label(composite, SWT.NONE);
//$NON-NLS-1$
title.setText(Messages.getString("ImportItemWizardPage.ErrorsAndWarnings"));
title.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
errorsList = new TableViewer(composite, SWT.BORDER);
errorsList.getControl().setLayoutData(gridData);
errorsList.setContentProvider(new IStructuredContentProvider() {
@Override
public void dispose() {
}
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
@Override
public Object[] getElements(Object inputElement) {
return errors.toArray();
}
});
errorsList.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
return element.toString();
}
});
errorsList.setInput(this);
errorsList.setSorter(new ViewerSorter());
}
use of org.eclipse.jface.viewers.ViewerSorter in project tdi-studio-se by Talend.
the class PaletteSettingPage method addTreeViewer.
/**
* qwei Comment method "addViewer".
*
* @param parent
*/
private void addTreeViewer(ThreeCompositesSashForm parent) {
ViewerSorter sorter = new ViewerSorter() {
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer,
* java.lang.Object, java.lang.Object)
*/
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
if (e1 instanceof ComponentPaletteItem && e2 instanceof ComponentPaletteItem) {
return super.compare(viewer, ((IPaletteItem) e1).getLabel(), ((IPaletteItem) e2).getLabel());
} else if (e1 instanceof FolderPaletteItem && e2 instanceof FolderPaletteItem) {
return super.compare(viewer, ((IPaletteItem) e1).getLabel(), ((IPaletteItem) e2).getLabel());
} else if (e1 instanceof ComponentPaletteItem && e2 instanceof FolderPaletteItem) {
return 1;
} else if (e1 instanceof FolderPaletteItem && e2 instanceof ComponentPaletteItem) {
return -1;
} else if (e1 instanceof RootPaletteItem && e2 instanceof RootPaletteItem) {
if (((IPaletteItem) e1).getPaletteType() == ComponentCategory.CATEGORY_4_DI) {
// up
return -1;
} else if (((IPaletteItem) e2).getPaletteType() == ComponentCategory.CATEGORY_4_DI) {
// down
return 1;
} else if (((IPaletteItem) e1).getPaletteType() == ComponentCategory.CATEGORY_4_CAMEL && ((IPaletteItem) e2).getPaletteType() == ComponentCategory.CATEGORY_4_MAPREDUCE) {
// up
return -1;
} else if (((IPaletteItem) e1).getPaletteType() == ComponentCategory.CATEGORY_4_MAPREDUCE && ((IPaletteItem) e2).getPaletteType() == ComponentCategory.CATEGORY_4_CAMEL) {
// down
return 1;
} else if (((IPaletteItem) e1).getPaletteType() == ComponentCategory.CATEGORY_4_MAPREDUCE && ((IPaletteItem) e2).getPaletteType() == ComponentCategory.CATEGORY_4_STORM) {
// up
return -1;
} else if (((IPaletteItem) e1).getPaletteType() == ComponentCategory.CATEGORY_4_STORM && ((IPaletteItem) e2).getPaletteType() == ComponentCategory.CATEGORY_4_MAPREDUCE) {
// down
return 1;
} else if (((IPaletteItem) e1).getPaletteType() == ComponentCategory.CATEGORY_4_CAMEL && ((IPaletteItem) e2).getPaletteType() == ComponentCategory.CATEGORY_4_STORM) {
// up
return -1;
} else if (((IPaletteItem) e1).getPaletteType() == ComponentCategory.CATEGORY_4_STORM && ((IPaletteItem) e2).getPaletteType() == ComponentCategory.CATEGORY_4_CAMEL) {
// down
return 1;
}
}
return super.compare(viewer, e1, e2);
}
};
List<IPaletteItem> input = getViewerInput();
Composite leftComposite = parent.getLeftComposite();
Label label = new Label(leftComposite, SWT.NONE);
label.setText("Hide");
hiddenViewer = new TreeViewer(leftComposite);
hiddenViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
hiddenViewer.setContentProvider(new TalendPaletteTreeProvider());
hiddenViewer.setLabelProvider(new TalendPaletteLabelProvider());
hiddenViewer.addFilter(getFilterForComponent(false));
hiddenViewer.setSorter(sorter);
hiddenViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
displayComponentsButton.setEnabled(!event.getSelection().isEmpty());
}
});
createButtons(parent.getMidComposite());
Composite rightComposite = parent.getRightComposite();
label = new Label(rightComposite, SWT.NONE);
label.setText("Show");
displayViewer = new TreeViewer(rightComposite);
displayViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
displayViewer.setContentProvider(new TalendPaletteTreeProvider());
displayViewer.setLabelProvider(new TalendPaletteLabelProvider());
displayViewer.addFilter(getFilterForComponent(true));
displayViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
hideCompnentsButton.setEnabled(!event.getSelection().isEmpty());
}
});
displayViewer.setSorter(sorter);
getComponentsFromProject(project);
hiddenViewer.setInput(input);
displayViewer.setInput(input);
if (!input.isEmpty()) {
displayViewer.expandToLevel(input.get(0), 1);
}
if (!input.isEmpty()) {
hiddenViewer.expandToLevel(input.get(0), 1);
}
}
use of org.eclipse.jface.viewers.ViewerSorter in project tdi-studio-se by Talend.
the class ProcessVersionComposite method addSortListener.
/**
* DOC Administrator Comment method "addSortListener".
*
* @param table
* @param column1
* @param column2
* @param column3
*/
private void addSortListener(final Table table, final TableColumn column1, final TableColumn column2, final TableColumn column3, final TableColumn column4) {
Listener sortListener = new Listener() {
private int direction = 1;
@Override
public void handleEvent(Event e) {
final TableColumn column = (TableColumn) e.widget;
if (column == table.getSortColumn()) {
direction = -direction;
}
if (direction == 1) {
table.setSortDirection(SWT.DOWN);
} else {
table.setSortDirection(SWT.UP);
}
table.setSortColumn(column);
tableViewer.setSorter(new ViewerSorter() {
int index = 0;
@Override
public void sort(Viewer viewer, Object[] elements) {
while (index < table.getColumns().length && table.getColumn(index) != column) {
index++;
}
super.sort(viewer, elements);
}
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
ITableLabelProvider labelProvider = (ITableLabelProvider) tableViewer.getLabelProvider();
String columnText = labelProvider.getColumnText(e1, index) != null ? labelProvider.getColumnText(e1, index) : //$NON-NLS-1$
"";
String columnText2 = labelProvider.getColumnText(e2, index) != null ? labelProvider.getColumnText(e2, index) : //$NON-NLS-1$
"";
return getComparator().compare(columnText, columnText2) * direction;
}
});
}
};
tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
/*
* (non-Javadoc)
*
* @seeorg.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.
* SelectionChangedEvent)
*/
@Override
public void selectionChanged(SelectionChangedEvent event) {
ProcessVersionComposite.this.selection = event.getSelection();
if (getParentWizard() != null) {
((WizardPage) getParentWizard()).setPageComplete(true);
}
}
});
column1.addListener(SWT.Selection, sortListener);
column2.addListener(SWT.Selection, sortListener);
column3.addListener(SWT.Selection, sortListener);
column4.addListener(SWT.Selection, sortListener);
table.setSortColumn(column1);
table.setSortDirection(SWT.DOWN);
tableViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
if (getParentWizard() == null) {
ITreeContextualAction editPropertiesAction = getEditPropertiesAction(EditPropertiesAction.class);
if (editPropertiesAction != null) {
editPropertiesAction.run();
}
}
}
});
}
use of org.eclipse.jface.viewers.ViewerSorter in project tdi-studio-se by Talend.
the class VersionSection method createControls.
@Override
public void createControls(Composite parent, TabbedPropertySheetPage aTabbedPropertySheetPage) {
super.createControls(parent, aTabbedPropertySheetPage);
composite = getWidgetFactory().createFlatFormComposite(parent);
tableViewer = new TableViewer(composite, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
final Table table = tableViewer.getTable();
TableLayout tableLayout = new TableLayout();
table.setLayout(tableLayout);
table.setHeaderVisible(true);
table.setLinesVisible(true);
final String[] columnProperties = new String[] { //$NON-NLS-1$
Messages.getString("VersionSection.Version"), //$NON-NLS-1$
Messages.getString("VersionSection.CreationDate"), Messages.getString("VersionSection.ModificationDate"), //$NON-NLS-1$ //$NON-NLS-2$
Messages.getString("VersionSection.Status") };
final TableColumn column1 = new TableColumn(table, SWT.NONE);
tableLayout.addColumnData(new ColumnPixelData(125, true));
column1.setText(columnProperties[0]);
final TableColumn column2 = new TableColumn(table, SWT.NONE);
tableLayout.addColumnData(new ColumnPixelData(125, true));
column2.setText(columnProperties[1]);
final TableColumn column3 = new TableColumn(table, SWT.NONE);
tableLayout.addColumnData(new ColumnPixelData(125, true));
column3.setText(columnProperties[2]);
final TableColumn column4 = new TableColumn(table, SWT.NONE);
tableLayout.addColumnData(new ColumnWeightData(1, 150, true));
column4.setText(columnProperties[3]);
tableViewer.setColumnProperties(columnProperties);
Object layoutData = parent.getLayoutData();
if (layoutData instanceof GridData) {
GridData gridData = (GridData) layoutData;
gridData.grabExcessVerticalSpace = true;
gridData.verticalAlignment = SWT.FILL;
}
FormData formData = new FormData();
formData.left = new FormAttachment(0);
formData.top = new FormAttachment(0);
formData.right = new FormAttachment(100);
formData.bottom = new FormAttachment(100);
table.setLayoutData(formData);
tableViewer.setContentProvider(new IStructuredContentProvider() {
public Object[] getElements(Object inputElement) {
IRepositoryViewObject repositoryObject = ((IRepositoryViewObject) inputElement);
if (repositoryObject.getProperty() == null) {
return null;
}
RepositoryNode parentRepositoryNode = RepositoryNodeUtilities.getParentRepositoryNodeFromSelection(repositoryObject);
try {
List<IRepositoryViewObject> allVersion = ProxyRepositoryFactory.getInstance().getAllVersion(repositoryObject.getId());
Collections.sort(allVersion, new IRepositoryObjectComparator());
Object[] objects = new Object[allVersion.size()];
for (int i = 0; i < objects.length; i++) {
IRepositoryViewObject repositoryObjectVersion = allVersion.get(i);
RepositoryNode repositoryNode = createRepositoryNode(parentRepositoryNode, repositoryObjectVersion);
objects[i] = repositoryNode;
}
return objects;
} catch (PersistenceException e) {
return null;
}
}
private RepositoryNode createRepositoryNode(RepositoryNode parentRepositoryNode, IRepositoryViewObject repositoryObjectVersion) {
ERepositoryObjectType itemType = ERepositoryObjectType.getItemType(repositoryObjectVersion.getProperty().getItem());
RepositoryNode repositoryNode = new RepositoryNode(repositoryObjectVersion, parentRepositoryNode, ENodeType.REPOSITORY_ELEMENT);
repositoryNode.setProperties(EProperties.CONTENT_TYPE, itemType);
repositoryNode.setProperties(EProperties.LABEL, repositoryObjectVersion.getLabel());
return repositoryNode;
}
public void dispose() {
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
});
tableViewer.setLabelProvider(new ITableLabelProvider() {
public Image getColumnImage(Object element, int columnIndex) {
return null;
}
public String getColumnText(Object element, int columnIndex) {
RepositoryNode repositoryNode = (RepositoryNode) element;
switch(columnIndex) {
case 0:
return repositoryNode.getObject().getVersion();
case 1:
if (repositoryNode.getObject().getCreationDate() != null) {
return FORMATTER.format(repositoryNode.getObject().getCreationDate());
} else {
return null;
}
case 2:
if (repositoryNode.getObject().getModificationDate() != null) {
return FORMATTER.format(repositoryNode.getObject().getModificationDate());
} else {
return null;
}
case 3:
if (repositoryNode.getObject().getStatusCode() != null) {
return repositoryNode.getObject().getStatusCode();
} else {
return null;
}
default:
return null;
}
}
public void addListener(ILabelProviderListener listener) {
}
public void dispose() {
}
public boolean isLabelProperty(Object element, String property) {
return false;
}
public void removeListener(ILabelProviderListener listener) {
}
});
//$NON-NLS-1$
MenuManager menuMgr = new MenuManager("#PopUp");
menuMgr.setRemoveAllWhenShown(true);
menuMgr.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager mgr) {
ISelection selection = tableViewer.getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
List<ITreeContextualAction> contextualsActions = ActionsHelper.getRepositoryContextualsActions();
for (ITreeContextualAction action : contextualsActions) {
if (action.isReadAction() || action.isEditAction() || action.isPropertiesAction()) {
action.init(null, structuredSelection);
if (action.isVisible()) {
mgr.add(action);
}
}
}
}
}
});
Menu menu = menuMgr.createContextMenu(tableViewer.getControl());
tableViewer.getControl().setMenu(menu);
Listener sortListener = new Listener() {
private int direction = 1;
public void handleEvent(Event e) {
final TableColumn column = (TableColumn) e.widget;
if (column == table.getSortColumn()) {
direction = -direction;
}
if (direction == 1) {
table.setSortDirection(SWT.DOWN);
} else {
table.setSortDirection(SWT.UP);
}
table.setSortColumn(column);
tableViewer.setSorter(new ViewerSorter() {
int index = 0;
@Override
public void sort(Viewer viewer, Object[] elements) {
while (index < table.getColumns().length && table.getColumn(index) != column) {
index++;
}
super.sort(viewer, elements);
}
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
ITableLabelProvider labelProvider = (ITableLabelProvider) tableViewer.getLabelProvider();
String columnText = labelProvider.getColumnText(e1, index) != null ? labelProvider.getColumnText(e1, index) : //$NON-NLS-1$
"";
String columnText2 = labelProvider.getColumnText(e2, index) != null ? labelProvider.getColumnText(e2, index) : //$NON-NLS-1$
"";
return getComparator().compare(columnText, columnText2) * direction;
}
});
}
};
column1.addListener(SWT.Selection, sortListener);
column2.addListener(SWT.Selection, sortListener);
column3.addListener(SWT.Selection, sortListener);
column4.addListener(SWT.Selection, sortListener);
table.setSortColumn(column1);
table.setSortDirection(SWT.DOWN);
aTabbedPropertySheetPage.getSite().setSelectionProvider(this);
}
Aggregations