Eclipse hanging on startup, Repair Corrupt Workspace

 

Eclipse can hang on start up due to various reasons like system crash , Updating a plugin etc. which corrupts the workspace.

You can check .log file (in your <workspace>/.metadata directory) for error logs like

!MESSAGE The workspace exited with unsaved changes in the previous session;
refreshing workspace to recover changes

 

Here are few quick fixes that may work (Make a backup of your Workspace and Try each step independently)

  • Removing .snap File
  1. Open <workspace>\.metadata\.plugins\org.eclipse.core.resources directory
  2. Remove .snap file in the directory
  3. Restart Eclipse

 

  • Remove .indexes Folder
  1. Remove the <workspace>\.metadata\.plugins\org.eclipse.core.resources\.root\.indexes directory
  2. Restart Eclipse

 

  • Remove “org.eclipse.ui.workbench”  folder
  1. Open <workspace>\.metadata\.plugins directory
  2. Remove “org.eclipse.ui.workbench” folder
  3. Restart Eclipse

 

If nothing works then you can start Eclipse with -clean option and import each project into new workspace.

 

[hr]

Custom SWT Dialog

Custom SWT Dialogbox extending org.eclipse.swt.widgets.Dialog Class

Source :


import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class EmployeeDialog extends Dialog {

	public EmployeeDialog(Shell parent) {
		super(parent);
	}

	private Group insGroup;

	public void open() {
		Shell shell = new Shell(getParent());
		shell.setText("Add Employee");

		draw(shell); // Contents of Dialog
		shell.pack();
		shell.open();

		Display display = getParent().getDisplay();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}

	}

	private void draw(Shell shell) {

		shell.setLayout(new GridLayout(2, true));

		// ID

		Label lid = new Label(shell, SWT.HORIZONTAL | SWT.SHADOW_OUT);
		lid.setText("Employee ID");
		Text tid = new Text(shell, SWT.BORDER | SWT.LEFT);

		// Age

		Label lage = new Label(shell, SWT.HORIZONTAL | SWT.SHADOW_OUT);
		lage.setText("Age");
		Text tage = new Text(shell, SWT.BORDER | SWT.LEFT);

		// Salary

		Label lsalary = new Label(shell, SWT.HORIZONTAL | SWT.SHADOW_OUT);
		lsalary.setText("Salary");
		Text tsalary = new Text(shell, SWT.BORDER | SWT.LEFT);

		final Button checkButton = new Button(shell, SWT.CHECK);
		checkButton.setText("Is Insured ?");
		checkButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {

				if (checkButton.getSelection()) {
					insGroup.setVisible(true);

				} else {
					insGroup.setVisible(false);
				}
			}

		});

		// Insurance Group

		insGroup = new Group(shell, SWT.SHADOW_IN);
		insGroup.setText("Insurance Details");
		insGroup.setLayout(new GridLayout(1, true));
		Label lb = new Label(insGroup, SWT.HORIZONTAL | SWT.SHADOW_OUT);
		lb.setText("Description");
		Text details = new Text(insGroup, SWT.BORDER | SWT.MULTI);
		insGroup.setVisible(false);

	}

}

Custom JFace Dialog

Custom Dialogbox  extending org.eclipse.jface.dialogs.Dialog class

Source:

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Text;

public class JfaceEmployeeDialog extends Dialog {

	public JfaceEmployeeDialog(Shell parent) {
		super(parent);
	}

	@Override
	protected Control createDialogArea(Composite parent) {

		Composite composite = (Composite) super.createDialogArea(parent);

		composite.getShell().setText("Add Employee");

		composite.setLayout(new GridLayout(1, true));

		draw(composite); // Contents of Dialog

		return composite;
	}

	private void draw(Composite composite) {

		// Employee Group

		Group empgroup = new Group(composite, SWT.SHADOW_IN);
		empgroup.setText("Employee Details");
		empgroup.setLayout(new GridLayout(3, true));

		// ID

		Label label = new Label(empgroup, SWT.HORIZONTAL);
		label.setText("Employee ID");
		Text tid = new Text(empgroup, SWT.FILL | SWT.BORDER);

		GridData textData = new GridData(SWT.FILL, SWT.FILL, true, true);
		textData.horizontalSpan = 2;
		textData.widthHint = 300;
		tid.setLayoutData(textData);

		// Name

		Label l_name = new Label(empgroup, SWT.HORIZONTAL);
		l_name.setText("Name");
		Text t_name = new Text(empgroup, SWT.FILL | SWT.BORDER);
		t_name.setLayoutData(textData);

		// Age

		Label l_age = new Label(empgroup, SWT.HORIZONTAL);
		l_age.setText("Age");
		Text t_age = new Text(empgroup, SWT.FILL | SWT.BORDER);
		t_age.setLayoutData(textData);

		Label lb = new Label(empgroup, SWT.HORIZONTAL);
		lb.setText("Is Insured");

		// CheckBox

		final Button checkBox = new Button(empgroup, SWT.CHECK);
		empgroup.setVisible(true);

		// Insurance Group

		final Group insgroup = new Group(composite, SWT.SHADOW_IN);
		insgroup.setText("Insurance Details");
		insgroup.setLayout(new GridLayout(3, true));

		// Amount

		Label l_amount = new Label(insgroup, SWT.HORIZONTAL);
		l_amount.setText("Amount");
		Text t_amount = new Text(insgroup, SWT.FILL | SWT.BORDER);
		t_amount.setLayoutData(textData);
		insgroup.setVisible(false);

		// Adding listener to check button

		checkBox.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {

				if (checkBox.getSelection()) {
					insgroup.setVisible(true);
				} else {
					insgroup.setVisible(false);
				}
			}
		});

	}

}

 

Eclipse Content Assist auto-complete (Ctrl +Space) disabled ?

Content Assist(Ctrl + Space)  is an auto-complete feature in Eclipse that helps in easy and fast coding. Popup windows  are displayed to propose possible text choices to complete a phrase , methods or arguments.

But sometimes this feature stops functioning and becomes almost impossible to write code.

Here are few steps that can help to bring back or enable Content assist feature.

1. Go to Windows-> Preferences

Now go to Java>Editor>Content Assist and Java>Editor>Content Assist>Advanced  and enable settings for which you want to enable auto-complete.

Click “Result Defaults” if you don’t know what to do.

 

2.  Make New Workspace and import your projects into New Workspace. Restart Eclipse.

3. One of the main reasons of Content assist not working is Ctrl + Space keys bound to another application . Make sure that no other application uses these set of keys. For eg. In Linux Ctrl +Space does not work because of SCIM feature to change input method installed . Make sure it is disabled.

4. Make sure that your Operating System Language and settings are set to En-US