Java Code Examples for org.eclipse.jface.viewers.TableViewer#getInput()

The following examples show how to use org.eclipse.jface.viewers.TableViewer#getInput() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FormHelper.java    From tlaplus with MIT License 6 votes vote down vote up
/**
    * Reads the input (list of formulas) and returns a list of strings which can be serialized 
    * @param source - viewer containing the formulas/assignments
    * @return
    */
public static List<String> getSerializedInput(final TableViewer tableViewer) {
	if (tableViewer instanceof CheckboxTableViewer) {
		final ArrayList<String> result = new ArrayList<>();
		final TableItem[] tableItems = tableViewer.getTable().getItems();
		final int itemCount = tableItems.length;
		for (int i = 0; i < itemCount; i++) {
			final TableItem item = tableItems[i];
			final String serialized = (item.getChecked() ? "1" : "0") + item.getText();
			
			result.add(serialized);
		}

           return result;
	} else {
           @SuppressWarnings("unchecked")
		List<Assignment> assignments = (List<Assignment>) tableViewer.getInput();
		if (assignments == null) {
			return null;
		}

           return ModelHelper.serializeAssignmentList(assignments);
       }
   }
 
Example 2
Source File: FormHelper.java    From tlaplus with MIT License 5 votes vote down vote up
/**
   * Performs the inverse operation to {@link FormHelper#getSerializedInput(CheckboxTableViewer)} 
   */
  public static void setSerializedInput(TableViewer table, List<String> serializedInput)
  {
      @SuppressWarnings("unchecked")
Vector<Formula> input = ((Vector<Formula>) table.getInput());
      if (input == null)
      {
          input = new Vector<Formula>();
      }
      // handling Formulas
      if (table instanceof CheckboxTableViewer)
      {
          Iterator<String> serializedIterator = serializedInput.iterator();
          Vector<Formula> checked = new Vector<Formula>();

          CheckboxTableViewer checkTable = (CheckboxTableViewer) table;
          while (serializedIterator.hasNext())
          {
              String entry = serializedIterator.next();
              Formula formula = new Formula(entry.substring(1));
              input.add(formula);
              if ("1".equals(entry.substring(0, 1)))
              {
                  checked.add(formula);
              }
          }
          checkTable.setInput(input);
          checkTable.setCheckedElements(checked.toArray());

      } else
      // handling Assignments
      {
          List<Assignment> deserializeAssignmentList = ModelHelper.deserializeAssignmentList(serializedInput);
          table.setInput(deserializeAssignmentList);
      }

  }
 
Example 3
Source File: UnDefinesViewer.java    From cmake4eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private void handleUnDefineAddButton(TableViewer tableViewer) {
  final Shell shell = tableViewer.getControl().getShell();
  AddCmakeUndefineDialog dlg = new AddCmakeUndefineDialog(shell, null);
  if (dlg.open() == Dialog.OK) {
    CmakeUnDefine cmakeDefine = dlg.getCmakeUndefine();
    @SuppressWarnings("unchecked")
    ArrayList<CmakeUnDefine> undefines = (ArrayList<CmakeUnDefine>) tableViewer
        .getInput();
    undefines.add(cmakeDefine);
    tableViewer.add(cmakeDefine); // updates the display
  }
}
 
Example 4
Source File: UnDefinesViewer.java    From cmake4eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private void handleUnDefineDelButton(TableViewer tableViewer) {
  final IStructuredSelection selection = (IStructuredSelection) tableViewer
      .getSelection();
  final Shell shell = tableViewer.getControl().getShell();
  if (MessageDialog.openQuestion(shell,
      "CMake-Undefine deletion confirmation",
      "Are you sure to delete the selected CMake-undefines?")) {
    @SuppressWarnings("unchecked")
    ArrayList<String> undefines = (ArrayList<String>) tableViewer.getInput();
    undefines.removeAll(selection.toList());
    tableViewer.remove(selection.toArray());// updates the display
  }
}
 
Example 5
Source File: DefinesViewer.java    From cmake4eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private void handleDefineAddButton(TableViewer tableViewer) {
  final Shell shell = tableViewer.getControl().getShell();
  AddCmakeDefineDialog dlg = new AddCmakeDefineDialog(shell, cfgd, null);
  if (dlg.open() == Dialog.OK) {
    CmakeDefine cmakeDefine = dlg.getCmakeDefine();
    @SuppressWarnings("unchecked")
    ArrayList<CmakeDefine> defines = (ArrayList<CmakeDefine>) tableViewer
        .getInput();
    defines.add(cmakeDefine);
    tableViewer.add(cmakeDefine); // updates the display
  }
}
 
Example 6
Source File: DefinesViewer.java    From cmake4eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private void handleDefineDelButton(TableViewer tableViewer) {
  final IStructuredSelection selection = (IStructuredSelection) tableViewer
      .getSelection();
  final Shell shell = tableViewer.getControl().getShell();
  if (MessageDialog.openQuestion(shell, "CMake-Define deletion confirmation",
      "Are you sure to delete the selected CMake-defines?")) {
    @SuppressWarnings("unchecked")
    ArrayList<CmakeDefine> defines = (ArrayList<CmakeDefine>) tableViewer
        .getInput();
    defines.removeAll(selection.toList());
    tableViewer.remove(selection.toArray());// updates the display
  }
}
 
Example 7
Source File: FilesPage.java    From typescript.java with MIT License 4 votes vote down vote up
/**
 * Remove selected files.
 */
private void removeSelectedItems(TableViewer viewer) {
	IObservableList list = ((IObservableList) viewer.getInput());
	list.removeAll(viewer.getStructuredSelection().toList());
}