Java Code Examples for org.eclipse.swt.widgets.Text#insert()

The following examples show how to use org.eclipse.swt.widgets.Text#insert() . 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: VariableButtonListenerFactory.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public static final SelectionAdapter getSelectionAdapter( final Composite composite, final Text destination,
  final GetCaretPositionInterface getCaretPositionInterface, final InsertTextInterface insertTextInterface,
  final VariableSpace space ) {
  return new SelectionAdapter() {
    public void widgetSelected( SelectionEvent e ) {
      // Before focus is lost, we get the position of where the selected variable needs to be inserted.
      int position = 0;
      if ( getCaretPositionInterface != null ) {
        position = getCaretPositionInterface.getCaretPosition();
      }

      String variableName = getVariableName( composite.getShell(), space );
      if ( variableName != null ) {
        String var = "${" + variableName + "}";
        if ( insertTextInterface == null ) {
          destination.insert( var );
          e.doit = false;
        } else {
          insertTextInterface.insertText( var, position );
        }
      }
    }
  };
}
 
Example 2
Source File: AbstractMainTab.java    From typescript.java with MIT License 5 votes vote down vote up
/**
 * A variable entry button has been pressed for the given text field. Prompt
 * the user for a variable and enter the result in the given field.
 */
private void handleVariablesButtonSelected(Text textField) {
	String variable = getVariable();
	if (variable != null) {
		textField.insert(variable);
	}
}
 
Example 3
Source File: ControlUtils.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
public static void openStringVariableSelectionDialog_ForText(Text text) {
	Shell shell = text.getShell();
	try {
		String variable = openStringVariableSelectionDialog(shell);
		text.insert(variable);
	} catch(OperationCancellation e) {
		return;
	}
}
 
Example 4
Source File: VariableButtonListenerFactory.java    From hop with Apache License 2.0 4 votes vote down vote up
public static final SelectionAdapter getSelectionAdapter( final Composite composite, final Text destination,
                                                          final GetCaretPositionInterface getCaretPositionInterface, final InsertTextInterface insertTextInterface,
                                                          final IVariables variables ) {
  return new SelectionAdapter() {
    public void widgetSelected( SelectionEvent e ) {
      String[] keys = variables.listVariables();
      Arrays.sort( keys );

      int size = keys.length;
      String[] key = new String[ size ];
      String[] val = new String[ size ];
      String[] str = new String[ size ];

      for ( int i = 0; i < keys.length; i++ ) {
        key[ i ] = keys[ i ];
        val[ i ] = variables.getVariable( key[ i ] );
        str[ i ] = key[ i ] + "  [" + val[ i ] + "]";
      }

      // Before focus is lost, we get the position of where the selected variable needs to be inserted.
      int position = 0;
      if ( getCaretPositionInterface != null ) {
        position = getCaretPositionInterface.getCaretPosition();
      }

      EnterSelectionDialog esd = new EnterSelectionDialog( composite.getShell(), str,
        BaseMessages.getString( PKG, "System.Dialog.SelectEnvironmentVar.Title" ),
        BaseMessages.getString( PKG, "System.Dialog.SelectEnvironmentVar.Message" ) );
      if ( esd.open() != null ) {
        int nr = esd.getSelectionNr();
        String var = "${" + key[ nr ] + "}";

        if ( insertTextInterface == null ) {
          destination.insert( var );
          // destination.setToolTipText(StringUtil.environmentSubstitute( destination.getText() ) );
          e.doit = false;
        } else {
          insertTextInterface.insertText( var, position );
        }
      }
    }
  };
}
 
Example 5
Source File: VariableButtonListenerFactory.java    From hop with Apache License 2.0 4 votes vote down vote up
public static final SelectionAdapter getSelectionAdapter( final Composite composite, final Text destination,
                                                          final IGetCaretPosition getCaretPositionInterface, final IInsertText insertTextInterface,
                                                          final IVariables variables ) {
  return new SelectionAdapter() {
    public void widgetSelected( SelectionEvent e ) {
      String[] keys = variables.listVariables();
      Arrays.sort( keys );

      int size = keys.length;
      String[] key = new String[ size ];
      String[] val = new String[ size ];
      String[] str = new String[ size ];

      for ( int i = 0; i < keys.length; i++ ) {
        key[ i ] = keys[ i ];
        val[ i ] = variables.getVariable( key[ i ] );
        str[ i ] = key[ i ] + "  [" + val[ i ] + "]";
      }

      // Before focus is lost, we get the position of where the selected variable needs to be inserted.
      int position = 0;
      if ( getCaretPositionInterface != null ) {
        position = getCaretPositionInterface.getCaretPosition();
      }

      EnterSelectionDialog esd = new EnterSelectionDialog( composite.getShell(), str,
        BaseMessages.getString( PKG, "System.Dialog.SelectEnvironmentVar.Title" ),
        BaseMessages.getString( PKG, "System.Dialog.SelectEnvironmentVar.Message" ) );
      if ( esd.open() != null ) {
        int nr = esd.getSelectionNr();
        String var = "${" + key[ nr ] + "}";

        if ( insertTextInterface == null ) {
          destination.insert( var );
          // destination.setToolTipText(StringUtil.environmentSubstitute( destination.getText() ) );
          e.doit = false;
        } else {
          insertTextInterface.insertText( var, position );
        }
      }
    }
  };
}
 
Example 6
Source File: VariableButtonListenerFactory.java    From hop with Apache License 2.0 4 votes vote down vote up
public static final SelectionAdapter getSelectionAdapter( final Composite composite, final Text destination,
                                                          final IGetCaretPosition getCaretPositionInterface, final IInsertText insertTextInterface,
                                                          final IVariables variables ) {
  return new SelectionAdapter() {
    public void widgetSelected( SelectionEvent e ) {
      String[] keys = variables.listVariables();
      Arrays.sort( keys );

      int size = keys.length;
      String[] key = new String[ size ];
      String[] val = new String[ size ];
      String[] str = new String[ size ];

      for ( int i = 0; i < keys.length; i++ ) {
        key[ i ] = keys[ i ];
        val[ i ] = variables.getVariable( key[ i ] );
        str[ i ] = key[ i ] + "  [" + val[ i ] + "]";
      }

      // Before focus is lost, we get the position of where the selected variable needs to be inserted.
      int position = 0;
      if ( getCaretPositionInterface != null ) {
        position = getCaretPositionInterface.getCaretPosition();
      }

      EnterSelectionDialog esd =
        new EnterSelectionDialog( composite.getShell(), str, BaseMessages.getString( PKG,
          "System.Dialog.SelectEnvironmentVar.Title" ), BaseMessages.getString( PKG,
          "System.Dialog.SelectEnvironmentVar.Message" ) );
      if ( esd.open() != null ) {
        int nr = esd.getSelectionNr();
        String var = "${" + key[ nr ] + "}";

        if ( insertTextInterface == null ) {
          destination.insert( var );
          // destination.setToolTipText(StringUtil.environmentSubstitute( destination.getText() ) );
          e.doit = false;
        } else {
          insertTextInterface.insertText( var, position );
        }
      }
    }
  };
}
 
Example 7
Source File: SVNDecoratorPreferencesPage.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Add another variable to the given target. The variable is inserted at current position
    * A ListSelectionDialog is shown and the choose the variables to add 
 */
private void addVariables(Text target, Map bindings) {

	final List variables = new ArrayList(bindings.size());
	
	ILabelProvider labelProvider = new LabelProvider() {
		public String getText(Object element) {
			return ((StringPair)element).s1 + " - " + ((StringPair)element).s2; //$NON-NLS-1$
		}
	};
	
	IStructuredContentProvider contentsProvider = new IStructuredContentProvider() {
		public Object[] getElements(Object inputElement) {
			return variables.toArray(new StringPair[variables.size()]);
		}
		public void dispose() {}
		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
	};
	
	for (Iterator it = bindings.keySet().iterator(); it.hasNext();) {
		StringPair variable = new StringPair();
		variable.s1 = (String) it.next(); // variable
		variable.s2 = (String) bindings.get(variable.s1); // description
		variables.add(variable);				
	}

	ListSelectionDialog dialog =
		new ListSelectionDialog(
			this.getShell(),
			this,
			contentsProvider,
			labelProvider,
			Policy.bind("SVNDecoratorPreferencesPage.selectVariablesToAdd")); //$NON-NLS-1$
	dialog.setTitle(Policy.bind("SVNDecoratorPreferencesPage.AddVariables")); //$NON-NLS-1$
	if (dialog.open() != ListSelectionDialog.OK)
		return;

	Object[] result = dialog.getResult();
	
	for (int i = 0; i < result.length; i++) {
		target.insert("{"+((StringPair)result[i]).s1 +"}"); //$NON-NLS-1$ //$NON-NLS-2$
	}		
}
 
Example 8
Source File: NewMergeFileAssociationWizardPage.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
private void addVariables(Text target, Map bindings) {

        final List variables = new ArrayList(bindings.size());

        ILabelProvider labelProvider = new LabelProvider() {
            public String getText(Object element) {
                return ((StringPair) element).s1
                        + " - " + ((StringPair) element).s2; //$NON-NLS-1$
            }
        };

        IStructuredContentProvider contentsProvider = new IStructuredContentProvider() {
            public Object[] getElements(Object inputElement) {
                return variables.toArray(new StringPair[variables.size()]);
            }

            public void dispose() {
            }

            public void inputChanged(Viewer viewer, Object oldInput,
                    Object newInput) {
            }
        };

        for (Iterator it = bindings.keySet().iterator(); it.hasNext();) {
            StringPair variable = new StringPair();
            variable.s1 = (String) it.next(); // variable
            variable.s2 = (String) bindings.get(variable.s1); // description
            variables.add(variable);
        }

        ListDialog dialog = new ListDialog(this.getShell());
        dialog.setContentProvider(contentsProvider);
        dialog.setAddCancelButton(true);
        dialog.setLabelProvider(labelProvider);
        dialog.setInput(variables);
        dialog.setTitle(Policy
                .bind("DiffMergePreferencePage.addVariableDialogTitle")); //$NON-NLS-1$
        if (dialog.open() != ListDialog.OK)
            return;

        Object[] result = dialog.getResult();

        for (int i = 0; i < result.length; i++) {
            target.insert("${" + ((StringPair) result[i]).s1 + "}"); //$NON-NLS-1$ //$NON-NLS-2$
        }
    }
 
Example 9
Source File: DiffMergePreferencePage.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Add another variable to the given target. The variable is inserted at
 * current position A ListSelectionDialog is shown and the choose the
 * variables to add
 */
private void addVariables(Text target, Map bindings) {

    final List variables = new ArrayList(bindings.size());

    ILabelProvider labelProvider = new LabelProvider() {
        public String getText(Object element) {
            return ((StringPair) element).s1
                    + " - " + ((StringPair) element).s2; //$NON-NLS-1$
        }
    };

    IStructuredContentProvider contentsProvider = new IStructuredContentProvider() {
        public Object[] getElements(Object inputElement) {
            return variables.toArray(new StringPair[variables.size()]);
        }

        public void dispose() {
        }

        public void inputChanged(Viewer viewer, Object oldInput,
                Object newInput) {
        }
    };

    for (Iterator it = bindings.keySet().iterator(); it.hasNext();) {
        StringPair variable = new StringPair();
        variable.s1 = (String) it.next(); // variable
        variable.s2 = (String) bindings.get(variable.s1); // description
        variables.add(variable);
    }

    ListDialog dialog = new ListDialog(this.getShell());
    dialog.setContentProvider(contentsProvider);
    dialog.setAddCancelButton(true);
    dialog.setLabelProvider(labelProvider);
    dialog.setInput(variables);
    dialog.setTitle(Policy
            .bind("DiffMergePreferencePage.addVariableDialogTitle")); //$NON-NLS-1$
    if (dialog.open() != ListDialog.OK)
        return;

    Object[] result = dialog.getResult();

    for (int i = 0; i < result.length; i++) {
        target.insert("${" + ((StringPair) result[i]).s1 + "}"); //$NON-NLS-1$ //$NON-NLS-2$
    }
}
 
Example 10
Source File: MergeFileAssociationPreferencePage.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
private void addVariables(Text target, Map bindings) {

        final List variables = new ArrayList(bindings.size());

        ILabelProvider labelProvider = new LabelProvider() {
            public String getText(Object element) {
                return ((StringPair) element).s1
                        + " - " + ((StringPair) element).s2; //$NON-NLS-1$
            }
        };

        IStructuredContentProvider contentsProvider = new IStructuredContentProvider() {
            public Object[] getElements(Object inputElement) {
                return variables.toArray(new StringPair[variables.size()]);
            }

            public void dispose() {
            }

            public void inputChanged(Viewer viewer, Object oldInput,
                    Object newInput) {
            }
        };

        for (Iterator it = bindings.keySet().iterator(); it.hasNext();) {
            StringPair variable = new StringPair();
            variable.s1 = (String) it.next(); // variable
            variable.s2 = (String) bindings.get(variable.s1); // description
            variables.add(variable);
        }

        ListDialog dialog = new ListDialog(this.getShell());
        dialog.setContentProvider(contentsProvider);
        dialog.setAddCancelButton(true);
        dialog.setLabelProvider(labelProvider);
        dialog.setInput(variables);
        dialog.setTitle(Policy
                .bind("DiffMergePreferencePage.addVariableDialogTitle")); //$NON-NLS-1$
        if (dialog.open() != ListDialog.OK)
            return;

        Object[] result = dialog.getResult();

        for (int i = 0; i < result.length; i++) {
            target.insert("${" + ((StringPair) result[i]).s1 + "}"); //$NON-NLS-1$ //$NON-NLS-2$
        }
    }
 
Example 11
Source File: VariableButtonListenerFactory.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public static final SelectionAdapter getSelectionAdapter( final Composite composite, final Text destination,
    final GetCaretPositionInterface getCaretPositionInterface, final InsertTextInterface insertTextInterface,
    final VariableSpace space ) {
  return new SelectionAdapter() {
    public void widgetSelected( SelectionEvent e ) {
      String[] keys = space.listVariables();
      Arrays.sort( keys );

      int size = keys.length;
      String[] key = new String[size];
      String[] val = new String[size];
      String[] str = new String[size];

      for ( int i = 0; i < keys.length; i++ ) {
        key[i] = keys[i];
        val[i] = space.getVariable( key[i] );
        str[i] = key[i] + "  [" + val[i] + "]";
      }

      // Before focus is lost, we get the position of where the selected variable needs to be inserted.
      int position = 0;
      if ( getCaretPositionInterface != null ) {
        position = getCaretPositionInterface.getCaretPosition();
      }

      EnterSelectionDialog esd =
          new EnterSelectionDialog( composite.getShell(), str, BaseMessages.getString( PKG,
              "System.Dialog.SelectEnvironmentVar.Title" ), BaseMessages.getString( PKG,
                  "System.Dialog.SelectEnvironmentVar.Message" ) );
      if ( esd.open() != null ) {
        int nr = esd.getSelectionNr();
        String var = "${" + key[nr] + "}";

        if ( insertTextInterface == null ) {
          destination.insert( var );
          // destination.setToolTipText(StringUtil.environmentSubstitute( destination.getText() ) );
          e.doit = false;
        } else {
          insertTextInterface.insertText( var, position );
        }
      }
    }
  };
}
 
Example 12
Source File: VariableButtonListenerFactory.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public static final SelectionAdapter getSelectionAdapter( final Composite composite, final Text destination,
  final GetCaretPositionInterface getCaretPositionInterface, final InsertTextInterface insertTextInterface,
  final VariableSpace space ) {
  return new SelectionAdapter() {
    public void widgetSelected( SelectionEvent e ) {
      String[] keys = space.listVariables();
      Arrays.sort( keys );

      int size = keys.length;
      String[] key = new String[size];
      String[] val = new String[size];
      String[] str = new String[size];

      for ( int i = 0; i < keys.length; i++ ) {
        key[i] = keys[i];
        val[i] = space.getVariable( key[i] );
        str[i] = key[i] + "  [" + val[i] + "]";
      }

      // Before focus is lost, we get the position of where the selected variable needs to be inserted.
      int position = 0;
      if ( getCaretPositionInterface != null ) {
        position = getCaretPositionInterface.getCaretPosition();
      }

      EnterSelectionDialog esd = new EnterSelectionDialog( composite.getShell(), str,
        BaseMessages.getString( PKG, "System.Dialog.SelectEnvironmentVar.Title" ),
        BaseMessages.getString( PKG, "System.Dialog.SelectEnvironmentVar.Message" ) );
      if ( esd.open() != null ) {
        int nr = esd.getSelectionNr();
        String var = "${" + key[nr] + "}";

        if ( insertTextInterface == null ) {
          destination.insert( var );
          // destination.setToolTipText(StringUtil.environmentSubstitute( destination.getText() ) );
          e.doit = false;
        } else {
          insertTextInterface.insertText( var, position );
        }
      }
    }
  };
}