Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2010 itemis AG (http://www.itemis.eu) and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html /
  
  package org.eclipse.xtext.ui.refactoring.impl;
  
 import java.util.List;
 
 import  org.eclipse.core.runtime.CoreException;
 import  org.eclipse.core.runtime.IProgressMonitor;
 import  org.eclipse.core.runtime.OperationCanceledException;
 import  org.eclipse.jface.text.IRegion;
 import  org.eclipse.ltk.core.refactoring.Change;
 import  org.eclipse.ltk.core.refactoring.ChangeDescriptor;
 import  org.eclipse.ltk.core.refactoring.RefactoringStatus;
 import  org.eclipse.ltk.core.refactoring.TextEditBasedChange;
 import  org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup;
 import  org.eclipse.text.edits.TextEditGroup;
Wraps a Change to be performed on the display thread. DocumentChanges are by default not executed on the display thread, causing thread access exceptions and leaving documents opened in editors in an inconsistent state.

Author(s):
Jan Koehnlein - Initial contribution and API
 
 public class DisplayChangeWrapper {
 
 	public static Change wrap(Change delegate) {
 		if(delegate instanceof TextEditBasedChange) {
 			return new TextEditBased((TextEditBasedChange) delegate);
 		} else {
 			return new Generic(delegate);
 		}
 	}
 	
 	public static interface Wrapper {
 		Change getDelegate();
 	}
 	
 	public static class Generic extends Change implements Wrapper {
 		
 		private Change delegate;
 	
 		protected Generic(Change delegate) {
 			this. = delegate;
 		}
 	
 		public Change getDelegate() {
 			return ;
 		}
 	
 		public ChangeDescriptor getDescriptor() {
 			return .getDescriptor();
 		}
 	
 		public String getName() {
 			return .getName();
 		}
 	
 		public void setEnabled(boolean enabled) {
 			.setEnabled(enabled);
 		}
 	
 		public Change getParent() {
 			return .getParent();
 		}
 	
 		public void dispose() {
 			.dispose();
 		}
 	
 		public boolean equals(Object obj) {
 			return .equals(obj);
 		}
 	
 		public Object getModifiedElement() {
 			return .getModifiedElement();
 		}
 	
 		public Object[] getAffectedObjects() {
 			return .getAffectedObjects();
 		}
 	
 		@SuppressWarnings("rawtypes")
		public Object getAdapter(Class adapter) {
			return .getAdapter(adapter);
		}
		public int hashCode() {
			return .hashCode();
		}
		public boolean isEnabled() {
			return .isEnabled();
		}
		public void initializeValidationData(IProgressMonitor pm) {
			.initializeValidationData(pm);
		}
		public RefactoringStatus isValid(IProgressMonitor pmthrows CoreException, OperationCanceledException {
			return .isValid(pm);
		}
		public Change perform(final IProgressMonitor pmthrows CoreException {
			Change undoChange = new DisplayRunnableWithResult<Change>() {
				protected Change run() throws Exception {
					Change result = .perform(pm);
					return result;
				}
			Change undoWrap = DisplayChangeWrapper.wrap(undoChange);
			return undoWrap;
		}
		public String toString() {
			return .toString();
		}
	}

No interfaces in LTK :-(

Author(s):
koehnlein - Initial contribution and API
	public static class TextEditBased extends TextEditBasedChange implements Wrapper {
		private TextEditBasedChange delegate;
		protected TextEditBased(TextEditBasedChange delegate) {
			super(delegate.getName());
			this. = delegate;
		}
		public TextEditBasedChange getDelegate() {
			return ;
		}
		public ChangeDescriptor getDescriptor() {
			return .getDescriptor();
		}
		public String getName() {
			return .getName();
		}
		public void setEnabled(boolean enabled) {
			.setEnabled(enabled);
		}
		public Change getParent() {
			return .getParent();
		}
		public void dispose() {
			.dispose();
		}
		public boolean equals(Object obj) {
			return .equals(obj);
		}
			return .getModifiedElement();
		}
		public Object[] getAffectedObjects() {
			return .getAffectedObjects();
		}
		@SuppressWarnings("rawtypes")
		public Object getAdapter(Class adapter) {
			return .getAdapter(adapter);
		}
		public int hashCode() {
			return .hashCode();
		}
		public boolean isEnabled() {
			return .isEnabled();
		}
		public void initializeValidationData(IProgressMonitor pm) {
			.initializeValidationData(pm);
		}
		public RefactoringStatus isValid(IProgressMonitor pmthrows CoreException, OperationCanceledException {
			return .isValid(pm);
		}
		public Change perform(final IProgressMonitor pmthrows CoreException {
			Change undoChange = new DisplayRunnableWithResult<Change>() {
				protected Change run() throws Exception {
					Change result = .perform(pm);
					return result;
				}
			Change undoWrap = DisplayChangeWrapper.wrap(undoChange);
			return undoWrap;
		}
		public String toString() {
			return .toString();
		}
		public void addChangeGroup(TextEditBasedChangeGroup group) {
			.addChangeGroup(group);
		}
		public void addTextEditGroup(TextEditGroup group) {
			.addTextEditGroup(group);
		}
		@SuppressWarnings("rawtypes")
		public boolean hasOneGroupCategory(List groupCategories) {
			return .hasOneGroupCategory(groupCategories);
		}
		public String getCurrentContent(IProgressMonitor pmthrows CoreException {
			return .getCurrentContent(pm);
		}
		public String getCurrentContent(IRegion regionboolean expandRegionToFullLineint surroundingLines,
				IProgressMonitor pmthrows CoreException {
			return .getCurrentContent(regionexpandRegionToFullLinesurroundingLinespm);
		}
		public boolean getKeepPreviewEdits() {
			return .getKeepPreviewEdits();
		}
		public String getPreviewContent(TextEditBasedChangeGroup[] changeGroups, IRegion region,
				boolean expandRegionToFullLineint surroundingLines, IProgressMonitor pmthrows CoreException {
			return .getPreviewContent(changeGroupsregionexpandRegionToFullLine,
					surroundingLinespm);
		}
		public String getPreviewContent(IProgressMonitor pmthrows CoreException {
			return .getPreviewContent(pm);
		}
		public String getTextType() {
			return .getTextType();
		}
		public void setKeepPreviewEdits(boolean keep) {
			.setKeepPreviewEdits(keep);
		}
		public void setTextType(String type) {
			.setTextType(type);
		}
	}
New to GrepCode? Check out our FAQ X