Java Code Examples for org.eclipse.swt.widgets.Table.getSelectionIndex()

The following are Jave code examples for showing how to use getSelectionIndex() of the org.eclipse.swt.widgets.Table class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Hydrograph   File: JoinMapDialog.java   View Source Code Vote up 6 votes
private void deleteRow(){

		Table table = mappingTableViewer.getTable();
		setValueForCellEditor();
		int selectionIndex = table.getSelectionIndex();
		int[] indexs = table.getSelectionIndices();
		if (selectionIndex == -1) {
			WidgetUtility.errorMessage("Select Rows to delete");
		} else {
			table.remove(indexs);
			int itemsRemoved=0;
			for (int index : indexs) {
				mappingTableItemList.remove(index-itemsRemoved);
				if(index-itemsRemoved-1 != -1){
					table.setSelection(index-itemsRemoved-1);
				}else{
					table.setSelection(0);
				}
				itemsRemoved++;
			}
			mappingTableViewer.refresh();
		}
		refreshButtonStatus();
	
	}
 
Example 2
Project: Hydrograph   File: LookupMapDialog.java   View Source Code Vote up 6 votes
private void deleteRow()
{
	Table table = mappingTableViewer.getTable();
	setValueForCellEditor();
	int selectionIndex = table.getSelectionIndex();
	int[] indexs = table.getSelectionIndices();
	if (selectionIndex == -1) {
		WidgetUtility.errorMessage("Select Rows to delete");
	} else {
		table.remove(indexs);
		int itemsRemoved=0;
		for (int index : indexs) {
			mappingTableItemList.remove(index-itemsRemoved);
			if(index-itemsRemoved-1 != -1){
				table.setSelection(index-itemsRemoved-1);
			}else{
				table.setSelection(0);
			}
			itemsRemoved++;
		}
		mappingTableViewer.refresh();
	}
	component.setLatestChangesInSchema(false);
	refreshButtonStatus();

}
 
Example 3
Project: Hydrograph   File: ELTTransformDeleteSelectionListener.java   View Source Code Vote up 6 votes
@Override
	public void selectionListenerAction(
			PropertyDialogButtonBar propertyDialogButtonBar,
			ListenerHelper helpers, Widget... widgets) {

		ELTGridDetails gridDetails = (ELTGridDetails) helpers.get(HelperType.SCHEMA_GRID);
		Table table =gridDetails.getTableViewer().getTable();
		int temp = table.getSelectionIndex();
		int[] indexs=table.getSelectionIndices();
		if (temp == -1) {
			WidgetUtility.errorMessage("Please Select row to delete");
		} else {
			table.remove(indexs);
			ArrayList tempList= new ArrayList();
			for (int index :indexs) { 
//				PropertyField test =(PropertyField) gridDetails.getGrids().get(index);
//				tempList.add(test);
			}
			 gridDetails.getGrids().removeAll(tempList); 
			
		}		
	}
 
Example 4
Project: Hydrograph   File: MultiParameterFileDialog.java   View Source Code Vote up 4 votes
private void deleteRow(TableViewer parameterTableViewer ){
	Table table = parameterTableViewer.getTable();
	int selectionIndex = table.getSelectionIndex();
	int[] indexs = table.getSelectionIndices();
	if (selectionIndex == -1) {
		WidgetUtility
				.errorMessage(ErrorMessages.SELECT_ROW_TO_DELETE);
	} else {
		table.remove(indexs);
		int itemsRemoved = 0;
		for (int index : indexs) {
			parameters.remove(index - itemsRemoved);
			itemsRemoved++;
		}
		parameterTableViewer.getTable().removeAll();
		parameterTableViewer.refresh();
	}
	
	if(indexs.length == 1 && parameters.size() > 0){//only one item is deleted
		if(parameters.size() == 1){//list contains only one element
			table.select(0);// select the first element
			parameterTableViewer.editElement(parameterTableViewer.getElementAt(0), 0);
		}
		else if(parameters.size() == indexs[0]){//deleted last item 
			table.select(parameters.size() - 1);//select the last element which now at the end of the list
			parameterTableViewer.editElement(parameterTableViewer.getElementAt(parameters.size() - 1), 0);
		}
		else if(parameters.size() > indexs[0]){//deleted element from middle of the list
			table.select( indexs[0] == 0 ? 0 : (indexs[0] - 1) );//select the element from at the previous location
			parameterTableViewer.editElement(parameterTableViewer.getElementAt(indexs[0] == 0 ? 0 : (indexs[0] - 1)), 0);
		}
	}
	else if(indexs.length >= 2){//multiple items are selected for deletion
		if(indexs[0] == 0){//delete from 0 to ...
			if(parameters.size() >= 1){//list contains only one element
				table.select(0);//select the remaining element
				parameterTableViewer.editElement(parameterTableViewer.getElementAt(0), 0);
			}
		}
		else{//delete started from element other than 0th element
			table.select((indexs[0])-1);//select element before the start of selection   
			parameterTableViewer.editElement(parameterTableViewer.getElementAt((indexs[0])-1), 0);
		}
	}
}
 
Example 5
Project: Hydrograph   File: WidgetUtility.java   View Source Code Vote up 4 votes
/**
 * Set the cursor on delete the row from table.
 * @param tableViewer
 * @param gridList
 */
public static void setCursorOnDeleteRow(TableViewer tableViewer, List<?> gridList){
	Table table = tableViewer.getTable();
	int[] indexes = table.getSelectionIndices();
	if (table.getSelectionIndex() == -1) {
		WidgetUtility.errorMessage(ERROR_MESSAGE);
	} else {
		table.remove(indexes);
		List listOfItemsToRemove= new ArrayList();
		for (int index : indexes) { 
			listOfItemsToRemove.add(gridList.get(index));
		}
		gridList.removeAll(listOfItemsToRemove);
		
	//highlight after deletion
	if(indexes.length == 1 && gridList.size() > 0){//only one item is deleted
		if(gridList.size() == 1){//list contains only one element
			table.select(0);// select the first element
			tableViewer.editElement(tableViewer.getElementAt(0), 0);
		}
		else if(gridList.size() == indexes[0]){//deleted last item 
			table.select(gridList.size() - 1);//select the last element which now at the end of the list
			tableViewer.editElement(tableViewer.getElementAt(gridList.size() - 1), 0);
		}
		else if(gridList.size() > indexes[0]){//deleted element from middle of the list
			table.select( indexes[0] == 0 ? 0 : (indexes[0] - 1) );//select the element from at the previous location
			tableViewer.editElement(tableViewer.getElementAt(indexes[0] == 0 ? 0 : (indexes[0] - 1)), 0);
		}
	}
	else if(indexes.length >= 2){//multiple items are selected for deletion
		if(indexes[0] == 0){//delete from 0 to ...
			if(gridList.size() >= 1){//list contains only one element
				table.select(0);//select the remaining element
				tableViewer.editElement(tableViewer.getElementAt(0), 0);
			}
		}
		else{//delete started from element other than 0th element
			table.select((indexes[0])-1);//select element before the start of selection   
			tableViewer.editElement(tableViewer.getElementAt((indexes[0])-1), 0);
		}
	}
  }
}
 
Example 6
Project: Hydrograph   File: ELTGridDeleteSelectionListener.java   View Source Code Vote up 4 votes
@Override
public void selectionListenerAction(
		PropertyDialogButtonBar propertyDialogButtonBar,
		ListenerHelper helpers, Widget... widgets) {
	propertyDialogButtonBar.enableApplyButton(true);
	ELTGridDetails gridDetails = (ELTGridDetails) helpers.get(HelperType.SCHEMA_GRID);
	
	TableViewer tableViewer = gridDetails.getTableViewer();
	Table table = tableViewer.getTable();
	int[] indexes=table.getSelectionIndices();
	if (table.getSelectionIndex() == -1) {
		WidgetUtility.errorMessage("Please Select row to delete");
	} else {
		table.remove(indexes);
		List listOfItemsToRemove= new ArrayList();
		for (int index : indexes) { 
			listOfItemsToRemove.add(gridDetails.getGrids().get(index));
		}
		List<GridRow> gridsList = gridDetails.getGrids();
		gridsList.removeAll(listOfItemsToRemove);
		
		
		//highlight after deletion
		if(indexes.length == 1 && gridsList.size() > 0){//only one item is deleted
			if(gridsList.size() == 1){//list contains only one element
				table.select(0);// select the first element
				tableViewer.editElement(tableViewer.getElementAt(0), 0);
			}
			else if(gridsList.size() == indexes[0]){//deleted last item 
				table.select(gridsList.size() - 1);//select the last element which now at the end of the list
				tableViewer.editElement(tableViewer.getElementAt(gridsList.size() - 1), 0);
			}
			else if(gridsList.size() > indexes[0]){//deleted element from middle of the list
				table.select( indexes[0] == 0 ? 0 : (indexes[0] - 1) );//select the element from at the previous location
				tableViewer.editElement(tableViewer.getElementAt(indexes[0] == 0 ? 0 : (indexes[0] - 1)), 0);
			}
		}
		else if(indexes.length >= 2){//multiple items are selected for deletion
			if(indexes[0] == 0){//delete from 0 to ...
				if(gridsList.size() >= 1){//list contains only one element
					table.select(0);//select the remaining element
					tableViewer.editElement(tableViewer.getElementAt(0), 0);
				}
			}
			else{//delete started from element other than 0th element
				table.select((indexes[0])-1);//select element before the start of selection   
				tableViewer.editElement(tableViewer.getElementAt((indexes[0])-1), 0);
			}
		}
	}
	
	if (gridDetails.getGrids().size() >= 1) {
		((Button) widgets[1]).setEnabled(true);
	} else {
		((Button) widgets[1]).setEnabled(false);
	}
	
	if (gridDetails.getGrids().size() >= 2) {
		((Button) widgets[2]).setEnabled(true);
		((Button) widgets[3]).setEnabled(true);
	} else {
		((Button) widgets[2]).setEnabled(false);
		((Button) widgets[3]).setEnabled(false);
	}
	((Component)helpers.get(HelperType.COMPONENT)).setLatestChangesInSchema(true);
}