org.eclipse.swt.widgets.Text#insert ( )源码实例Demo

下面列出了org.eclipse.swt.widgets.Text#insert ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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 );
        }
      }
    }
  };
}
 
源代码2 项目: typescript.java   文件: AbstractMainTab.java
/**
 * 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);
	}
}
 
源代码3 项目: goclipse   文件: ControlUtils.java
public static void openStringVariableSelectionDialog_ForText(Text text) {
	Shell shell = text.getShell();
	try {
		String variable = openStringVariableSelectionDialog(shell);
		text.insert(variable);
	} catch(OperationCancellation e) {
		return;
	}
}
 
源代码4 项目: hop   文件: VariableButtonListenerFactory.java
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 );
        }
      }
    }
  };
}
 
源代码5 项目: hop   文件: VariableButtonListenerFactory.java
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 );
        }
      }
    }
  };
}
 
源代码6 项目: hop   文件: VariableButtonListenerFactory.java
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 );
        }
      }
    }
  };
}
 
/**
 * 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$
	}		
}
 
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$
        }
    }
 
源代码9 项目: APICloud-Studio   文件: DiffMergePreferencePage.java
/**
 * 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$
    }
}
 
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$
        }
    }
 
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 );
        }
      }
    }
  };
}
 
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 );
        }
      }
    }
  };
}