/** * Classe de visualisation des résultats */ public class ResultView extends ViewPart { public static final String ID = "fast.resultview"; private TableViewer viewer; private DataRowFilter filter; private TableSorter tableSorter; private Query myQuery; private String myDataSource; private ModelProvider modelProvider; private Integer instanceNum; public ResultView(){ instanceNum = 0; } public void createPartControl(final Composite parent) { // pour avoir le même style d'onglets que comme dans eclipse PlatformUI.getPreferenceStore().setValue(IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS, false); this.getSite().getWorkbenchWindow().getSelectionService().addSelectionListener("fast.navigationview", new ISelectionListener(){ public void selectionChanged(IWorkbenchPart part, ISelection selection) { if (selection == null) { return; } if (selection instanceof IStructuredSelection) { GridLayout layout = new GridLayout(2, false); parent.setLayout(layout); Label searchLabel = new Label(parent, SWT.NONE); searchLabel.setText("Search: "); final Text searchText = new Text(parent, SWT.BORDER | SWT.SEARCH); searchText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL)); searchText.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent ke) { filter.setSearchText(searchText.getText()); viewer.refresh(); } }); IStructuredSelection ss = (IStructuredSelection)selection; if (ss.getFirstElement() != null){ //if the selection is != of null if (ss.getFirstElement().getClass() == SubModule.class) { getViewSite().getActionBars().getStatusLineManager().setMessage("Selected : " + ((SubModule) ss.getFirstElement()).getName()); myQuery = new Query(((SubModule) ss.getFirstElement()).getQuery().getName()); myDataSource = ((SubModule)ss.getFirstElement()).getDataSource(); Activator.getLogger().info("myProcStock = "+ myQuery.getName()); modelProvider = new ModelProvider(myQuery, myDataSource); viewer = createTableViewer(parent, modelProvider); try { PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(ResultView.ID, Integer.toString((instanceNum)), IWorkbenchPage.VIEW_CREATE); instanceNum++; setPartName( ((SubModule)ss.getFirstElement()).getName()); //notify of changes to the name firePropertyChange(IWorkbenchPartConstants.PROP_PART_NAME); } catch (PartInitException e) { e.printStackTrace(); } } else{ MessageDialog.openInformation(getSite().getShell(),"Ouverture","Veuillez ouvrir le fichier"); } } } } }); } /** * méthode permettant de créer mon tableViewer * @param parent * @param viewer * @param modelProvider (fournisseur d'objets metiers) * @return */ private TableViewer createTableViewer(final Composite parent, final ModelProvider modelProvider){ TableViewer viewer = new TableViewer(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER); // création des colonnes de la table createColumns(viewer, modelProvider.getHearders(), modelProvider.getTypes()); viewer.setContentProvider(new DataRowContentProvider()); viewer.setLabelProvider(new DataRowLabelProvider()); viewer.setInput(modelProvider.getTblRows()); // On active la sélection getSite().setSelectionProvider(viewer); // On active le Sorter sur notre table tableSorter = new TableSorter(); viewer.setSorter(tableSorter); filter = new DataRowFilter(); viewer.addFilter(filter); // Layout the viewer GridData gridData = new GridData(); gridData.verticalAlignment = GridData.FILL; gridData.horizontalSpan = 2; gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = true; gridData.horizontalAlignment = GridData.FILL; viewer.getControl().setLayoutData(gridData); return viewer; } /** * les colonnes sont crées avec des noms vennant de la base de données * @param viewer */ private void createColumns(final TableViewer viewer, String[] headers, String[] types) { Table table = viewer.getTable(); // initialisation des bounds : leur taille devra à terme être gérée dynamiquement int[] bounds = new int [headers.length]; for (int i=0; i