use of org.eclipse.jface.text.source.ISourceViewer in project KaiZen-OpenAPI-Editor by RepreZen.
the class OpenQuickOutlineHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISourceViewer viewer = null;
//$NON-NLS-1$
Object activeFocusControl = HandlerUtil.getVariable(event, "activeFocusControl");
if (activeFocusControl instanceof Control) {
Control control = (Control) activeFocusControl;
if (!control.isDisposed()) {
viewer = (ISourceViewer) control.getData(ISourceViewer.class.getName());
}
}
if (viewer == null) {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor instanceof JsonEditor) {
viewer = ((JsonEditor) editor).getProjectionViewer();
}
}
if (viewer != null) {
ITextOperationTarget operationTarget = viewer.getTextOperationTarget();
if (operationTarget.canDoOperation(QUICK_OUTLINE)) {
operationTarget.doOperation(QUICK_OUTLINE);
}
}
return null;
}
use of org.eclipse.jface.text.source.ISourceViewer in project tdi-studio-se by Talend.
the class StandAloneTalendJavaEditor method isEditable.
@Override
public boolean isEditable() {
if (!getRepositoryFactory().getStatus(item).isEditable()) {
ISourceViewer sourceViewer = getSourceViewer();
if (sourceViewer != null) {
sourceViewer.getTextWidget().setDragDetect(false);
}
isEditable = false;
}
return !rEditorInput.isReadOnly() && getRepositoryFactory().getStatus(item).isEditable() && isLastVersion(item);
}
use of org.eclipse.jface.text.source.ISourceViewer in project tdi-studio-se by Talend.
the class StandAloneTalendJavaEditor method init.
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
super.init(site, input);
Bundle bundle = FrameworkUtil.getBundle(StandAloneTalendJavaEditor.class);
lockService = bundle.getBundleContext().registerService(EventHandler.class.getName(), new EventHandler() {
@Override
public void handleEvent(Event event) {
String lockTopic = Constant.REPOSITORY_ITEM_EVENT_PREFIX + Constant.ITEM_LOCK_EVENT_SUFFIX;
if (lockTopic.equals(event.getTopic())) {
if (!isEditable) {
Object o = event.getProperty(Constant.ITEM_EVENT_PROPERTY_KEY);
if (o instanceof FileItem) {
boolean isTheCorrectEditor = false;
Property property = ((FileItem) o).getProperty();
if (property != null) {
String eventItemId = property.getId();
//$NON-NLS-1$
String currentOpenedItemId = "";
if (rEditorInput != null) {
currentOpenedItemId = rEditorInput.getId();
}
isTheCorrectEditor = currentOpenedItemId.equals(eventItemId);
}
if (!isTheCorrectEditor) {
return;
}
item.getProperty().eAdapters().remove(dirtyListener);
item = (FileItem) o;
item.getProperty().eAdapters().add(dirtyListener);
if (isEditable()) {
isEditable = true;
rEditorInput.getFile().setReadOnly(false);
getSite().getShell().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
setFocus();
ISourceViewer viewer = getViewer();
if (viewer != null) {
StyledText styledText = viewer.getTextWidget();
if (styledText != null) {
styledText.setBackground(bgColorForEditabeItem);
styledText.setDragDetect(true);
}
}
}
});
try {
ICodeGeneratorService service = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
if (o instanceof RoutineItem) {
ITalendSynchronizer routineSynchronizer = service.createJavaRoutineSynchronizer();
routineSynchronizer.syncRoutine((RoutineItem) o, true);
} else if (o instanceof SQLPatternItem) {
ISQLPatternSynchronizer sqlPatternSynchronizer = service.getSQLPatternSynchronizer();
sqlPatternSynchronizer.syncSQLPattern((SQLPatternItem) o, true);
} else {
//$NON-NLS-1$
org.talend.commons.exception.ExceptionHandler.process(new Exception("Uncatched case"));
}
setName();
} catch (Exception e) {
org.talend.commons.exception.ExceptionHandler.process(e);
}
}
}
}
}
}
}, new Hashtable<String, String>(//$NON-NLS-1$
Collections.singletonMap(EventConstants.EVENT_TOPIC, Constant.REPOSITORY_ITEM_EVENT_PREFIX + "*")));
}
use of org.eclipse.jface.text.source.ISourceViewer in project tdi-studio-se by Talend.
the class CodeView method createPartControl.
@Override
public void createPartControl(Composite parent) {
this.parent = parent;
parent.setLayout(new FillLayout());
ECodeLanguage language = LanguageManager.getCurrentLanguage();
ISourceViewer viewer = null;
final StyledText text;
int styles = SWT.H_SCROLL | SWT.V_SCROLL;
document = new Document();
switch(language) {
case JAVA:
IPreferenceStore store = JavaPlugin.getDefault().getCombinedPreferenceStore();
viewer = new JavaSourceViewer(parent, null, null, false, styles, store);
viewer.setDocument(document);
JavaTextTools tools = JavaPlugin.getDefault().getJavaTextTools();
tools.setupJavaDocumentPartitioner(viewer.getDocument(), IJavaPartitions.JAVA_PARTITIONING);
SimpleJavaSourceViewerConfiguration config = new SimpleJavaSourceViewerConfiguration(tools.getColorManager(), store, null, IJavaPartitions.JAVA_PARTITIONING, true);
viewer.configure(config);
viewer.getTextWidget().setFont(JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT));
document = viewer.getDocument();
break;
// empty since only have java
default:
}
viewer.setEditable(false);
text = viewer.getTextWidget();
// getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(this);
IToolBarManager tbm = getViewSite().getActionBars().getToolBarManager();
IAction wrapAction = new Action() {
@Override
public void run() {
text.setWordWrap(isChecked());
}
};
//$NON-NLS-1$
wrapAction.setToolTipText("wrap");
wrapAction.setChecked(false);
//$NON-NLS-1$
wrapAction.setImageDescriptor(ImageDescriptor.createFromFile(DesignerPlugin.class, "/icons/wrap.gif"));
tbm.add(wrapAction);
createMenu();
}
use of org.eclipse.jface.text.source.ISourceViewer in project bndtools by bndtools.
the class BndMarkerQuickAssistProcessor method computeQuickAssistProposals.
@Override
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext context) {
List<ICompletionProposal> proposals = new LinkedList<ICompletionProposal>();
ISourceViewer viewer = context.getSourceViewer();
@SuppressWarnings("unused") IDocument document = viewer.getDocument();
IAnnotationModel model = viewer.getAnnotationModel();
@SuppressWarnings("rawtypes") Iterator iter = model.getAnnotationIterator();
while (iter.hasNext()) {
Annotation annotation = (Annotation) iter.next();
if (annotation instanceof MarkerAnnotation && canFix(annotation)) {
Position position = model.getPosition(annotation);
if (isAtPosition(context.getOffset(), position)) {
IMarker marker = ((MarkerAnnotation) annotation).getMarker();
String errorType = marker.getAttribute("$bndType", null);
if (errorType != null) {
BuildErrorDetailsHandler handler = BuildErrorDetailsHandlers.INSTANCE.findHandler(errorType);
if (handler != null) {
proposals.addAll(handler.getProposals(marker));
}
}
}
}
}
if (proposals.isEmpty()) {
proposals.add(new NoCompletionsProposal());
}
return proposals.toArray(new ICompletionProposal[0]);
}
Aggregations