Java Code Examples for org.eclipse.ui.forms.widgets.FormToolkit#createText()

The following examples show how to use org.eclipse.ui.forms.widgets.FormToolkit#createText() . 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: AbstractFormPage.java    From typescript.java with MIT License 6 votes vote down vote up
protected Text createText(Composite parent, String label, JSONPath path, String defaultValue, String message) {
	FormToolkit toolkit = getToolkit();
	Composite composite = toolkit.createComposite(parent, SWT.NONE);
	composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
	GridLayout layout = new GridLayout(2, false);
	layout.marginWidth = 0;
	layout.marginBottom = 0;
	layout.marginTop = 0;
	layout.marginHeight = 0;
	layout.verticalSpacing = 0;
	composite.setLayout(layout);

	toolkit.createLabel(composite, label);

	Text text = toolkit.createText(composite, "");
	if (message != null) {
		text.setMessage(message);
	}
	text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

	bind(text, path, defaultValue);
	return text;
}
 
Example 2
Source File: CommonGui.java    From CodeCheckerEclipsePlugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Adds a {@link Text} input field with a {@link Label}.
 * @param toolkit This toolkit is the factory that makes the Controls.
 * @param comp The parent {@link Composite} that the new {@link Control} is to be added.
 * @param labelText The text that will be added to the {@link Label}.
 * @param def The default texdt thats displayed on the {@link Text}.
 * @return The newly created textfield.
 */
protected Text addTextField(FormToolkit toolkit, Composite comp, String labelText, String def) {
    Text ret;
    Label label = toolkit.createLabel(comp, labelText);
    label.setLayoutData(new GridData());
    ret = toolkit.createText(comp, def, SWT.MULTI | SWT.WRAP | SWT.BORDER);
    GridData gd = new GridData();
    gd.horizontalAlignment = GridData.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.widthHint = TEXTWIDTH;
    ret.setLayoutData(gd);
    return ret;
}
 
Example 3
Source File: ResultPage.java    From tlaplus with MIT License 5 votes vote down vote up
private int getHeightGuidanceForLabelTextFieldLine(final Composite parent, final FormToolkit toolkit) {
	final Label l = toolkit.createLabel(parent, "Just Some Concerned Text you get");
	final Text t = toolkit.createText(parent, "More time text 12345:67890", SWT.FLAT);
	
	final int height = Math.max(t.computeSize(SWT.DEFAULT, SWT.DEFAULT).y, l.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
	
	l.dispose();
	t.dispose();
	
	return height;
}
 
Example 4
Source File: SWTHelper.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
public static Text createText(final FormToolkit tk, final Composite parent, final int lines,
	final int flags){
	int lNum = SWT.SINGLE;
	if (lines > 1) {
		lNum = SWT.MULTI | SWT.WRAP;
	}
	Text ret = tk.createText(parent, "", lNum | flags | SWT.BORDER); //$NON-NLS-1$
	GridData gd = getFillGridData(1, true, 1, true);
	int h = Math.round(ret.getFont().getFontData()[0].height);
	gd.minimumHeight = (lines + 1) * (h + 2);
	gd.heightHint = gd.minimumHeight;
	ret.setLayoutData(gd);
	return ret;
}
 
Example 5
Source File: SqlEditor.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private void createResultSection(Composite body, FormToolkit toolkit) {
	Section section = UI.section(body, toolkit, "Results");
	UI.gridData(section, true, true);
	Composite composite = UI.sectionClient(section, toolkit, 1);
	composite.setLayout(new FillLayout());
	resultText = toolkit.createText(composite, null, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
}
 
Example 6
Source File: CommitDialog.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private void createCommitMessage(Composite parent, FormToolkit toolkit) {
	Section section = UI.section(parent, toolkit, M.CommitMessage);
	Composite client = toolkit.createComposite(section);
	client.setLayout(new GridLayout());
	section.setClient(client);
	Text commitText = toolkit.createText(client, null, SWT.BORDER
			| SWT.V_SCROLL | SWT.WRAP | SWT.MULTI);
	GridData gd = UI.gridData(commitText, true, false);
	gd.heightHint = 150;
	commitText.addModifyListener((event) -> {
		message = commitText.getText();
		updateButton();
	});
}
 
Example 7
Source File: DBImportFirstPage.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
public void createControl(Composite parent){
	DBImportWizard wiz = (DBImportWizard) getWizard();
	
	FormToolkit tk = UiDesk.getToolkit();
	Form form = tk.createForm(parent);
	form.setText(Messages.DBImportFirstPage_Connection); //$NON-NLS-1$
	Composite body = form.getBody();
	body.setLayout(new TableWrapLayout());
	tk.createLabel(body, Messages.DBImportFirstPage_EnterType); //$NON-NLS-1$
	dbTypes = new List(body, SWT.BORDER);
	dbTypes.setItems(supportedDB);
	dbTypes.addSelectionListener(new SelectionAdapter() {
		@Override
		public void widgetSelected(SelectionEvent e){
			int it = dbTypes.getSelectionIndex();
			switch (it) {
			case MYSQL:
			case POSTGRESQL:
				server.setEnabled(true);
				dbName.setEnabled(true);
				defaultUser = ""; //$NON-NLS-1$
				defaultPassword = ""; //$NON-NLS-1$
				break;
			case H2:
				server.setEnabled(false);
				dbName.setEnabled(true);
				defaultUser = "sa";
				defaultPassword = "";
				break;
			case ODBC:
				server.setEnabled(false);
				dbName.setEnabled(true);
				defaultUser = "sa"; //$NON-NLS-1$
				defaultPassword = ""; //$NON-NLS-1$
				break;
			default:
				break;
			}
			DBImportSecondPage sec = (DBImportSecondPage) getNextPage();
			sec.name.setText(defaultUser);
			sec.pwd.setText(defaultPassword);
			
		}
		
	});
	
	tk.adapt(dbTypes, true, true);
	tk.createLabel(body, Messages.DBImportFirstPage_serverAddress); //$NON-NLS-1$
	server = tk.createText(body, "", SWT.BORDER); //$NON-NLS-1$
	
	TableWrapData twr = new TableWrapData(TableWrapData.FILL_GRAB);
	server.setLayoutData(twr);
	tk.createLabel(body, Messages.DBImportFirstPage_databaseName); //$NON-NLS-1$
	dbName = tk.createText(body, "", SWT.BORDER); //$NON-NLS-1$
	TableWrapData twr2 = new TableWrapData(TableWrapData.FILL_GRAB);
	dbName.setLayoutData(twr2);
	if (wiz.preset != null && wiz.preset.length > 1) {
		int idx = StringTool.getIndex(supportedDB, wiz.preset[0]);
		if (idx < dbTypes.getItemCount()) {
			dbTypes.select(idx);
		}
		server.setText(wiz.preset[1]);
		dbName.setText(wiz.preset[2]);
	}
	setControl(form);
}
 
Example 8
Source File: DBConnectFirstPage.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
public void createControl(Composite parent){
	FormToolkit tk = UiDesk.getToolkit();
	Form form = tk.createForm(parent);
	form.setText(Messages.DBConnectFirstPage_connectioNDetails); //$NON-NLS-1$
	Composite body = form.getBody();
	body.setLayout(new TableWrapLayout());
	FormText alt = tk.createFormText(body, false);
	StringBuilder old = new StringBuilder();
	old.append("<form>"); //$NON-NLS-1$
	String driver = "";
	String user = "";
	String typ = "";
	String connectString = "";
	Hashtable<Object, Object> hConn = null;
	String cnt = CoreHub.localCfg.get(Preferences.CFG_FOLDED_CONNECTION, null);
	if (cnt != null) {
		hConn = PersistentObject.fold(StringTool.dePrintable(cnt));
		if (hConn != null) {
			driver =
				PersistentObject.checkNull(hConn.get(Preferences.CFG_FOLDED_CONNECTION_DRIVER));
			connectString =
				PersistentObject.checkNull(hConn
					.get(Preferences.CFG_FOLDED_CONNECTION_CONNECTSTRING));
			user =
				PersistentObject.checkNull(hConn.get(Preferences.CFG_FOLDED_CONNECTION_USER));
			typ = PersistentObject.checkNull(hConn.get(Preferences.CFG_FOLDED_CONNECTION_TYPE));
		}
	}
	// Check whether we were overridden
	String dbUser = System.getProperty(ElexisSystemPropertyConstants.CONN_DB_USERNAME);
	String dbPw = System.getProperty(ElexisSystemPropertyConstants.CONN_DB_PASSWORD);
	String dbFlavor = System.getProperty(ElexisSystemPropertyConstants.CONN_DB_FLAVOR);
	String dbSpec = System.getProperty(ElexisSystemPropertyConstants.CONN_DB_SPEC);
	if (dbUser != null && dbPw != null && dbFlavor != null && dbSpec != null) {
		old.append("<br/><li><b>Aktuelle Verbindung wurde via Übergabeparameter ans Programm gesetzt!</b></li><br/>"); //$NON-NLS-1$
	}
	if (ch.rgw.tools.StringTool.isNothing(connectString)) {
		old.append("<br/>"); //$NON-NLS-1$
		old.append("Keine konfigurierte Verbindung."); //$NON-NLS-1$
	} else {
		old.append("Konfigurierte Verbindung ist:<br/>"); //$NON-NLS-1$
		old.append("<li><b>Typ:</b>       ").append(typ).append("</li>"); //$NON-NLS-1$ //$NON-NLS-2$
		old.append("<li><b>Treiber</b>    ").append(driver).append("</li>"); //$NON-NLS-1$ //$NON-NLS-2$
		old.append("<li><b>Verbinde</b>   ").append(connectString).append("</li>"); //$NON-NLS-1$ //$NON-NLS-2$
		old.append("<li><b>Username</b>   ").append(user).append("</li>"); //$NON-NLS-1$ //$NON-NLS-2$
	}
	if (PersistentObject.getConnection() != null
		&& PersistentObject.getConnection().getConnectString() != null) {
		old.append("<li><b>Effektiv</b> verwendet wird:").append( //$NON-NLS-1$
			PersistentObject.getConnection().getConnectString()).append("</li>"); //$NON-NLS-1$
	}
	old.append("</form>"); //$NON-NLS-1$
	alt.setText(old.toString(), true, false);
	// Composite form=new Composite(parent, SWT.BORDER);
	Label sep = tk.createSeparator(body, SWT.NONE);
	TableWrapData twd = new TableWrapData();
	twd.heightHint = 5;
	sep.setLayoutData(twd);
	tk.createLabel(body, Messages.DBConnectFirstPage_enterType); //$NON-NLS-1$
	dbTypes = new Combo(body, SWT.BORDER | SWT.SIMPLE);
	dbTypes.setItems(supportedDB);
	dbTypes.addSelectionListener(new SelectionAdapter() {
		@Override
		public void widgetSelected(SelectionEvent e){
			int it = dbTypes.getSelectionIndex();
			switch (it) {
			case 0:
			case 1:
				server.setEnabled(true);
				dbName.setEnabled(true);
				defaultUser = "elexis"; //$NON-NLS-1$
				defaultPassword = "elexisTest"; //$NON-NLS-1$
				break;
			case 2:
				server.setEnabled(false);
				dbName.setEnabled(true);
				defaultUser = "sa"; //$NON-NLS-1$
				defaultPassword = ""; //$NON-NLS-1$
				break;
			default:
				break;
			}
			DBConnectSecondPage sec = (DBConnectSecondPage) getNextPage();
			sec.name.setText(defaultUser);
			sec.pwd.setText(defaultPassword);
			
		}
		
	});
	tk.adapt(dbTypes, true, true);
	tk.createLabel(body, Messages.DBConnectFirstPage_serevrAddress); //$NON-NLS-1$
	server = tk.createText(body, "", SWT.BORDER); //$NON-NLS-1$
	TableWrapData twr = new TableWrapData(TableWrapData.FILL_GRAB);
	server.setLayoutData(twr);
	tk.createLabel(body, Messages.DBConnectFirstPage_databaseName); //$NON-NLS-1$
	dbName = tk.createText(body, "", SWT.BORDER); //$NON-NLS-1$
	TableWrapData twr2 = new TableWrapData(TableWrapData.FILL_GRAB);
	dbName.setLayoutData(twr2);
	setControl(form);
}
 
Example 9
Source File: GeoPage.java    From olca-app with Mozilla Public License 2.0 4 votes vote down vote up
private void setupSection(Composite body, FormToolkit tk) {
	Composite comp = UI.formSection(body, tk, "Setup");
	UI.gridLayout(comp, 3);

	// GeoJSON file
	UI.gridLayout(comp, 3);
	UI.gridData(comp, true, false);
	UI.formLabel(comp, tk, "GeoJSON File");
	Text fileText = tk.createText(comp, "");
	fileText.setEditable(false);
	UI.gridData(fileText, false, false).widthHint = 350;
	Button fileBtn = tk.createButton(
			comp, "Open file", SWT.NONE);
	fileBtn.setImage(Icon.FOLDER_OPEN.get());
	Controls.onSelect(fileBtn, _e -> {
		File file = FileChooser.open("*.geojson");
		if (file == null)
			return;
		Setup s = App.exec("Parse GeoJSON ...",
				() -> Setup.read(file));
		if (s == null || s.file == null)
			return;

		// copy possible elementary flow bindings
		// into the new setup (note that the parameters
		// are already initialized in the new setup)
		if (setup != null) {
			s.bindings.addAll(setup.bindings);
		}
		setup = s;
		fileText.setText(s.file);
		paramSection.update();
		flowSection.update();
	});

	UI.filler(comp, tk);
	Composite btnComp = tk.createComposite(comp);
	UI.gridLayout(btnComp, 2, 10, 0);
	Button openBtn = tk.createButton(
			btnComp, "Open setup", SWT.NONE);
	openBtn.setImage(Icon.FOLDER_OPEN.get());
	Button saveBtn = tk.createButton(
			btnComp, "Save setup", SWT.NONE);
	saveBtn.setImage(Icon.SAVE.get());
}