Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » org.eclipse.swt.SWTException: Widget is disposed
org.eclipse.swt.SWTException: Widget is disposed [message #692717] Tue, 05 July 2011 05:29
Mikael Petterson is currently offline Mikael PettersonFriend
Messages: 158
Registered: July 2009
Senior Member
Error trace:

!STACK 0
org.eclipse.swt.SWTException: Widget is disposed
	at org.eclipse.swt.SWT.error(SWT.java:4083)
	at org.eclipse.swt.SWT.error(SWT.java:3998)
	at org.eclipse.swt.SWT.error(SWT.java:3969)
	at org.eclipse.swt.widgets.Widget.error(Widget.java:468)
	at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:340)
	at org.eclipse.swt.widgets.Combo.getSelectionIndex(Combo.java:854)
	at net.sourceforge.eclipseccase.ui.dialogs.ActivityDialog.getActivity(ActivityDialog.java:266)
	at net.sourceforge.eclipseccase.ui.actions.CheckOutAction.checkoutWithActivity(CheckOutAction.java:117)
	at net.sourceforge.eclipseccase.ui.actions.CheckOutAction.execute(CheckOutAction.java:44)




Any ideas why I get this problem?

br,

//mike


This is "CheckOutAction":


public class CheckOutAction extends ClearCaseWorkspaceAction {

	@Override
	public void execute(IAction action) {
		String maybeComment = "";
		int maybeDepth = IResource.DEPTH_ZERO;

		if (!ClearCasePreferences.isUseClearDlg() && !ClearCasePreferences.isUCM() && ClearCasePreferences.isCommentCheckout()) {
			CommentDialog dlg = new CommentDialog(getShell(), "Checkout comment");
			if (dlg.open() == Window.CANCEL)
				return;
			maybeComment = dlg.getComment();
			maybeDepth = dlg.isRecursive() ? IResource.DEPTH_INFINITE : IResource.DEPTH_ZERO;
		}

		final String comment = maybeComment;
		final int depth = maybeDepth;

		// UCM checkout.
		if (ClearCasePreferences.isUCM()) {
			checkoutWithActivity(depth);
			return;
		}

		IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

			public void run(IProgressMonitor monitor) throws CoreException {

				try {
					IResource[] resources = getSelectedResources();
					beginTask(monitor, "Checking out...", resources.length);

					if (ClearCasePreferences.isUseClearDlg()) {
						monitor.subTask("Executing ClearCase user interface...");
						ClearDlgHelper.checkout(resources);
					} else {
						// Sort resources with directories last so that the
						// modification of a
						// directory doesn't abort the modification of files
						// within
						// it.
						List resList = Arrays.asList(resources);
						Collections.sort(resList, new DirectoryLastComparator());

						ConsoleOperationListener opListener = new ConsoleOperationListener(monitor);
						for (int i = 0; i < resources.length; i++) {
							IResource resource = resources[i];
							ClearCaseProvider provider = ClearCaseProvider.getClearCaseProvider(resource);
							if (provider != null) {
								provider.setComment(comment);
								provider.setOperationListener(opListener);
								provider.checkout(new IResource[] { resource }, depth, subMonitor(monitor));
							}
						}
					}
				} finally {
					monitor.done();
					updateActionEnablement();
				}
			}
		};

		executeInBackground(runnable, "Checking out resources from ClearCase");

	}

	@Override
	public boolean isEnabled() {
		IResource[] resources = getSelectedResources();
		if (resources.length == 0)
			return false;
		for (int i = 0; i < resources.length; i++) {
			IResource resource = resources[i];
			ClearCaseProvider provider = ClearCaseProvider.getClearCaseProvider(resource);
			if (provider == null || provider.isUnknownState(resource) || provider.isIgnored(resource) || !provider.isClearCaseElement(resource))
				return false;
			if (provider.isCheckedOut(resource))
				return false;
		}
		return true;
	}

	private void checkoutWithActivity(int depth) {
		IResource[] resources = getSelectedResources();
		for (int i = 0; i < resources.length; i++) {
			IResource resource = resources[i];
			ClearCaseProvider provider = ClearCaseProvider.getClearCaseProvider(resource);
			if (provider != null) {

				ActivityDialog dlg = new ActivityDialog(getShell(), provider);
				if (dlg.open() == Window.OK) {

					//
					String activitySelector = dlg.getActivity().getActivitySelector();

					provider.setActivity(activitySelector);
					provider.setComment(dlg.getComment());//

					try {
						provider.checkout(new IResource[] { resource }, depth, null);
					} catch (TeamException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		}
	}
}



This is "ActivityDialog":


 * Copyright (c) 2011 eclipse-ccase.sourceforge.net.
package net.sourceforge.eclipseccase.ui.dialogs;

import net.sourceforge.eclipseccase.ClearCasePlugin;

/**
 * @author mikael petterson
 * 
 */
public class ActivityDialog extends Dialog {
	
	/** trace id */
	private static final String TRACE_ACTIVITYDIALOG = "ActivityDialog"; //$NON-NLS-1$

	private Combo activityCombo;

	private Button newButton;

	private CommentDialogArea commentDialogArea;

	private ClearCaseProvider provider;

	private ArrayList<Activity> activities;

	private static final String NO_ACTIVITY = "NONE";
	
	private boolean test = false;

	

	public ActivityDialog(Shell parentShell, ClearCaseProvider provider) {
		super(parentShell);
		this.setShellStyle(SWT.CLOSE);
		this.provider = provider;
		commentDialogArea = new CommentDialogArea(this, null);

	}

	protected Control createDialogArea(Composite parent) {
		getShell().setText(Messages.getString("ActivityDialog.title"));
		Composite composite = new Composite(parent, SWT.NULL);
		composite.setLayoutData(new GridData(GridData.FILL_BOTH));
		GridLayout layout = new GridLayout();
		layout.numColumns = 1;
		composite.setLayout(layout);

		Label descriptionLabel = new Label(composite, SWT.NONE);
		descriptionLabel.setText(Messages.getString("ActivityDialog.activityDescription")); //$NON-NLS-1$
		descriptionLabel.setLayoutData(new GridData());

		Label label = new Label(composite, SWT.NONE);
		label.setText(Messages.getString("ActivityDialog.activity")); //$NON-NLS-1$
		label.setLayoutData(new GridData());

		activityCombo = createCombo(composite);
		activityCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		activityCombo.addListener(SWT.Modify, new Listener() {
			public void handleEvent(Event e) {
				((Combo) e.widget).getText();

			}
		});

		activityCombo.setFocus();

		addButton(parent);

		commentDialogArea.createArea(composite);
		commentDialogArea.addPropertyChangeListener(new IPropertyChangeListener() {
			public void propertyChange(PropertyChangeEvent event) {
				if (event.getProperty() == CommentDialogArea.OK_REQUESTED) {
					okPressed();
				}
			}
		});

		initContent();

		return composite;

	}

	private void addButton(Composite parent) {
		Composite buttons = new Composite(parent, SWT.NONE);
		buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
		GridLayout layout = new GridLayout();
		layout.marginHeight = 0;
		layout.marginWidth = 0;
		buttons.setLayout(layout);

		newButton = new Button(buttons, SWT.PUSH);
		newButton.setText(Messages.getString("ActivityDialog.newActivity")); //$NON-NLS-1$
		GridData data = new GridData();
		data.horizontalAlignment = GridData.FILL;
		int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
		data.widthHint = Math.max(widthHint, newButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
		newButton.setLayoutData(data);
		newButton.setEnabled(true);
		SelectionListener listener = new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				// Open new Dialog to add activity.
				Shell activeShell;
				if(isTest()){
					activeShell = Display.getDefault().getActiveShell();
				}else{
					activeShell = PlatformUI.getWorkbench().getDisplay().getActiveShell();

				}
					
				NewActivityDialog dlg = new NewActivityDialog(activeShell,provider);
				if (dlg.open() == Window.CANCEL)
					return;
				// FIXME: mike 20110407 update list to get new activity
				initContent();
				

			}
		};
		newButton.addSelectionListener(listener);
	}

	private void initContent() {
		if (provider != null) {
			activities = provider.listActivities();
		} else {
			// for testing
			activities = new ArrayList<Activity>();
			// 06-Jun-00.17:16:12
			activities.add(new Activity("06-Jun-00.17:16:12", "test", "eraonel", "test comment"));
			activities.add(new Activity("04-Jun-00.17:10:00", "test2","eraonel", "another test comment"));
			activities.add(new Activity("2011-06-14T16:16:04+03:00",
					"bmn011_quick_bug_fix", "bmn011", "bmn011_quick_bug_fix"));
		}

		if (activities.size() == 0) {
			activityCombo.add(NO_ACTIVITY);
			activityCombo.select(0);
		} else {
			for (int i = 0; i < activities.size(); i++) {
				activityCombo.add(activities.get(i).getHeadline());
			}
			if (provider != null) {
				//Select last create
				Activity myLastCreatedAct = getLastCreatedActvity(activities);
				int index = activities.indexOf(myLastCreatedAct);
				activityCombo.select(index);
			}
		}

	}

	/**
	 * Retrieve last created activity.
	 * 
	 * @param activities
	 * @return
	 */
	private Activity getLastCreatedActvity(ArrayList<Activity> activities) {
		Activity myLast = null;
		Date newestDate = null;
		for (int i = 0; i < activities.size(); i++) {
			Activity currentActivity = activities.get(i);
			Date activityDate = currentActivity.getDate();
			if (ClearCasePlugin.DEBUG_UCM) {
				ClearCasePlugin.trace(TRACE_ACTIVITYDIALOG,
						"Date: " + activityDate.getTime()); //$NON-NLS-1$
			}
			if (newestDate == null) {
				newestDate = activityDate;
			}
			int results = newestDate.compareTo(activityDate);

			if (results < 0) {
				// newestTime is before activityTime
				newestDate = activityDate;
				myLast = currentActivity;
			}

		}

		return myLast;
	}

	/*
	 * Utility method that creates a combo box
	 * 
	 * @param parent the parent for the new label
	 * 
	 * @return the new widget
	 */
	protected Combo createCombo(Composite parent) {
		Combo combo = new Combo(parent, SWT.READ_ONLY);
		GridData data = new GridData(GridData.FILL_HORIZONTAL);
		data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
		combo.setLayoutData(data);
		return combo;
	}

	/**
	 * Returns the comment.
	 * 
	 * @return String
	 */
	public String getComment() {
		return commentDialogArea.getComment();
	}

	public Activity getActivity() {
		Activity currentActivity = null;
		int index = activityCombo.getSelectionIndex();
		String headline = activityCombo.getItem(index);
		for (int i = 0; i < activities.size(); i++) {
			currentActivity = activities.get(i);
			if(currentActivity.getHeadline().equalsIgnoreCase(headline)){
				return currentActivity;
			}
		}
		return currentActivity;
	}
	
	public boolean isTest() {
		return test;
	}

	public void setTest(boolean test) {
		this.test = test;
	}

	// For testing of Dialog.
	public static void main(String[] args) {
		final Display display = new Display();
		Shell shell = new Shell(display);
		ActivityDialog dlg = new ActivityDialog(shell, null);
		dlg.setTest(true);
		dlg.open();
	}

}
Previous Topic:Problems with ColorDialog in combination with Browser on Macos
Next Topic:Pls help! How to add a checkbox on the tableheader?
Goto Forum:
  


Current Time: Fri Apr 19 03:52:29 GMT 2024

Powered by FUDForum. Page generated in 0.01665 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top