Programa Java Del IDE de COBOL

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 66

/******************************************************************************* * Copyright (c) 2000, 2003 FUJITSU LIMITED and others. * All rights reserved.

This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * FUJITSU LIMITED - initial implementation ******************************************************************************* / package org.eclipse.cobol.ui.editor; import java.lang.reflect.InvocationTargetException; import java.text.MessageFormat; import java.util.Iterator; //import java.util.List; import org.eclipse.cobol.ui.CBDTUiPlugin; import org.eclipse.cobol.ui.COBOLPluginImages; import org.eclipse.cobol.ui.ICOBOLHelpContextId; import org.eclipse.cobol.ui.actions.COBOLBreakpointActionPopup; import org.eclipse.cobol.ui.actions.COBOLBreakpointRulerAction; import org.eclipse.cobol.ui.actions.COBOLContentAssistantAction; import org.eclipse.cobol.ui.actions.COBOLGotoLineAction; import org.eclipse.cobol.ui.actions.COBOLPrintAction; import org.eclipse.cobol.ui.actions.COBOLRenumberAction; import org.eclipse.cobol.ui.build.BuildUtil; import org.eclipse.cobol.ui.build.DependencyModelManipulation; import org.eclipse.cobol.ui.common.COBOLAbstractUndoManager; import org.eclipse.cobol.ui.common.COBOLDialogProperties; import org.eclipse.cobol.ui.common.IReferenceFormatConstants; import org.eclipse.cobol.ui.common.IReferenceFormatHandler; import org.eclipse.cobol.ui.common.text.COBOLTextFactory; //import org.eclipse.cobol.ui.editor.quickdiff.COBOLLastSaveReferenceProvider; //import org.eclipse.cobol.ui.editor.quickdiff.COBOLQuickDiffSupport; import org.eclipse.cobol.ui.fixedformat.COBOLFixedFormatDocumentProvider; import org.eclipse.cobol.ui.fixedformat.COBOLFixedFormatEventHandler; import org.eclipse.cobol.ui.fixedformat.COBOLFixedFormatSourceViewerConfiguratio n; import org.eclipse.cobol.ui.fixedformat.COBOLFixedFormatUndoManager; import org.eclipse.cobol.ui.fixedformat.COBOLSequenceNumberArea; import org.eclipse.cobol.ui.fixedformat.COBOLFixedFormatDocumentProvider.Interna lListener; import org.eclipse.cobol.ui.freeformat.COBOLFreeFormatDocumentProvider; import org.eclipse.cobol.ui.freeformat.COBOLFreeFormatSourceViewerConfiguration; import org.eclipse.cobol.ui.preferences.COBOLEditorPreferenceFormatBlock; import org.eclipse.cobol.ui.preferences.COBOLEditorPreferenceGeneralBlock; //import org.eclipse.cobol.ui.preferences.COBOLEditorPreferencePage; import org.eclipse.cobol.ui.rulers.COBOLHorizontalRuler; import org.eclipse.cobol.ui.variableformat.COBOLVariableFormatEventHandler; import org.eclipse.cobol.ui.variableformat.COBOLVariableFormatSourceViewerConfig uration; import org.eclipse.cobol.ui.variableformat.COBOLVariableFormatUndoManager; import org.eclipse.cobol.ui.views.common.IViewConstants; import org.eclipse.cobol.ui.views.common.RemoteFileEditorInput; import org.eclipse.cobol.ui.views.common.TreeElement; import org.eclipse.cobol.ui.views.common.ViewsTreeModel; import org.eclipse.cobol.ui.views.outlineview.COBOLContentOutlinePage;

import org.eclipse.cobol.ui.views.structures.StructuresView; import org.eclipse.core.internal.resources.IMarkerSetElement; import org.eclipse.core.internal.resources.MarkerInfo; import org.eclipse.core.internal.resources.MarkerSet; import org.eclipse.core.internal.resources.ResourceInfo; import org.eclipse.core.internal.resources.Workspace; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IContributionItem; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IStatusLineManager; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.Separator; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.ProgressMonitorDialog; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferenceConverter; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.text.BadLocationException; //import org.eclipse.jface.text.DocumentEvent; import org.eclipse.jface.text.IDocument; //import org.eclipse.jface.text.IDocumentListener; import org.eclipse.jface.text.ITextListener; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.text.IViewportListener; import org.eclipse.jface.text.Position; import org.eclipse.jface.text.TextEvent; import org.eclipse.jface.text.source.Annotation; //import org.eclipse.jface.text.source.IChangeRulerColumn; //import org.eclipse.jface.text.source.AnnotationRulerColumn; //import org.eclipse.jface.text.source.CompositeRuler; import org.eclipse.jface.text.source.IAnnotationAccess; //import org.eclipse.jface.text.source.IAnnotationModelExtension; //import org.eclipse.jface.text.source.IChangeRulerColumn; import org.eclipse.jface.text.source.IOverviewRuler; //import org.eclipse.jface.text.source.IAnnotationAccess; import org.eclipse.jface.text.source.IAnnotationModel; //import org.eclipse.jface.text.source.IOverviewRuler; //import org.eclipse.jface.text.source.ISharedTextColors; import org.eclipse.jface.text.source.ISourceViewer; //import org.eclipse.jface.text.source.ISourceViewerExtension; import org.eclipse.jface.text.source.IVerticalRuler; //import org.eclipse.jface.text.source.OverviewRuler; import org.eclipse.jface.text.source.SourceViewer; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection;

import org.eclipse.search.ui.SearchUI; import org.eclipse.swt.SWT; //import org.eclipse.swt.custom.StackLayout; import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.custom.StyledText2; import org.eclipse.swt.dnd.DND; import org.eclipse.swt.dnd.DropTarget; import org.eclipse.swt.dnd.DropTargetEvent; import org.eclipse.swt.dnd.DropTargetListener; import org.eclipse.swt.dnd.TextTransfer; import org.eclipse.swt.dnd.Transfer; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.FontData; import org.eclipse.swt.graphics.FontMetrics; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Layout; import org.eclipse.swt.widgets.Shell; import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot; import org.eclipse.ui.IEditorActionBarContributor; import org.eclipse.ui.IEditorActionDelegate; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IEditorReference; import org.eclipse.ui.IFileEditorInput; import org.eclipse.ui.IPageLayout; import org.eclipse.ui.IStorageEditorInput; import org.eclipse.ui.IViewPart; import org.eclipse.ui.IViewReference; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.actions.WorkspaceModifyOperation; import org.eclipse.ui.dialogs.SaveAsDialog; import org.eclipse.ui.editors.text.DefaultEncodingSupport; import org.eclipse.ui.editors.text.EditorsUI; import org.eclipse.ui.editors.text.IEncodingSupport; import org.eclipse.ui.ide.ResourceUtil; //import org.eclipse.ui.editors.text.TextEditorPreferenceConstants; //import org.eclipse.ui.help.WorkbenchHelp; //import org.eclipse.ui.internal.editors.text.EditorsPlugin; //import org.eclipse.ui.internal.texteditor.TextEditorPlugin; //import org.eclipse.ui.internal.texteditor.quickdiff.QuickDiffExtensionsRegistr y; //import org.eclipse.ui.internal.editors.quickdiff.LastSaveReferenceProvider; //import org.eclipse.ui.internal.texteditor.quickdiff.DocumentLineDiffer; //import org.eclipse.ui.internal.editors.text.EditorsPlugin; //import org.eclipse.ui.internal.editors.text.EditorsPlugin; import org.eclipse.ui.part.EditorActionBarContributor;

import org.eclipse.ui.part.FileEditorInput; //import org.eclipse.ui.texteditor.AbstractTextEditor; import org.eclipse.ui.texteditor.AddTaskAction; import org.eclipse.ui.texteditor.IAbstractTextEditorHelpContextIds; //import org.eclipse.ui.texteditor.IDocumentProviderExtension; import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor; //import org.eclipse.ui.texteditor.AnnotationPreference; //import org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess; //import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstant s; //import org.eclipse.ui.texteditor.DefaultRangeIndicator; import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants; import org.eclipse.ui.texteditor.ChainedPreferenceStore; import org.eclipse.ui.texteditor.IStatusField; //import org.eclipse.ui.texteditor.ITextEditor; import org.eclipse.ui.texteditor.ITextEditorActionConstants; import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; import org.eclipse.ui.texteditor.IUpdate; import org.eclipse.ui.texteditor.SourceViewerDecorationSupport; //import org.eclipse.ui.texteditor.MarkerAnnotationPreferences; //import org.eclipse.ui.texteditor.SourceViewerDecorationSupport; //import org.eclipse.ui.texteditor.StatusTextEditor; //import org.eclipse.ui.texteditor.InfoForm; import org.eclipse.ui.texteditor.MarkerAnnotation; import org.eclipse.ui.texteditor.MarkerUtilities; import org.eclipse.ui.texteditor.ResourceAction; import org.eclipse.ui.texteditor.TextEditorAction; //import org.eclipse.ui.texteditor.quickdiff.IQuickDiffReferenceProvider; //import org.eclipse.ui.texteditor.quickdiff.QuickDiff; //import org.eclipse.ui.texteditor.quickdiff.ReferenceProviderDescriptor; //import org.eclipse.ui.texteditor.quickdiff.IQuickDiffReferenceProvider; import org.eclipse.ui.views.contentoutline.IContentOutlinePage; import org.eclipse.ui.views.tasklist.TaskList; /** * Main implementation of the cobol editor. * This class is responsible for showing the file with the * extension of .cob or .cobol or .cbl * <p> * Also handles the hetrogenious format files ie., fixed and * free format files in a single instance of the editor. * When the file changes from one format to another format * the editor behaviour changes accordingly. * </p> * * @version 1.1 * @author Fujitsu */ public class COBOLEditor //extends AbstractTextEditor //extends StatusTextEditor extends AbstractDecoratedTextEditor { /** * instance of vertical ruler */ //private IVerticalRuler fVRuler; /**

* Type of reference format */ private String fRefFormat; /** * Horizontal ruler instance */ private boolean showHRuler = true; private Composite fHRulerComposite; private COBOLHorizontalRuler fHRuler; private Label fHRulerSpacer; /** * Document provider instance for fixed/variable format and only one ins tance maintained * for all the editors.whenever the format changes from * free/variable to fixed format then this document provider get in to a ct. */ private COBOLFixedFormatDocumentProvider fSeqFormatDocumentProvider = nu ll; /** * Document provider instance for free format and only one instance main tained * for the editor.whenever the format changes from * fixed/variable to free format then this document provider get in to a ct. */ private COBOLFreeFormatDocumentProvider fFreeFormatDocumentProvider = nu ll; /** * Factory class which provides tools like content assistant etc */ private COBOLTextFactory fTextFactory; /** * Source Viewer Configuration for Fixed Format. * whenever the format changes from free to fixed format then this * source viewer configuration get in to act */ private COBOLFixedFormatSourceViewerConfiguration fFixedFormatSourceView erConfiguration; /** * Source Viewer Configuration for Free Format. * whenever the format changes from fixed to free format then this * source viewer configuration get in to act */ private COBOLFreeFormatSourceViewerConfiguration fFreeFormatSourceViewer Configuration; /** * Source Viewer Configuration for Variable Format. * whenever the format changes from fixed to free format then this * source viewer configuration get in to act */ private COBOLVariableFormatSourceViewerConfiguration fVariableFormatSour ceViewerConfiguration;

/** * Reference format handler interface for fixed format files */ private IReferenceFormatHandler fFixedFormatEventHandler; /** * Reference format handler interface for variable format files */ private IReferenceFormatHandler fVariableFormatEventHandler; /** * Content outline page reference */ private COBOLContentOutlinePage fPage; /** * Grid data width hint */ /*private*/public /*static*/ final int VERTICAL_RULER_WIDTH = 12; /** * Action id for content assistant */ private final String CONTENT_ASSIST_ACTION_ID = "ContentAssistProposal"; //$NON-NLS-1$ /** * Content assistant resource key prefix */ private final String CONTENT_ASSIST_RESOURCE_KEY_PREFIX = "ContentAssist Proposal."; //$NON-NLS-1$ /** * Editor context menu action for Renumbering */ private COBOLRenumberAction renumberAction = null; /** * the TAB character */ private final char TAB = '\t'; //$NON-NLS-1$ /** * the styled text used for printing */ private StyledText styledTextPrinter; /** * the status line message provider */ private COBOLStatusLineMessages fStatusLineMsg; /** * the status line change listener */ protected ISelectionChangedListener fStatusLineClearer; /** * Action ID of Add Breakpoint

*/ private static final String ADD_BREAKPOINT = "AddBreakpoint"; //$NON-NLS -1$ /** * Renumber action id. */ private static final String RENUMBER = "Renumber"; //$NON-NLS-1$ /** * The current platform */ private static final String PLATFORM = "win32"; //$NON-NLS-1$ /** * The cobol sequence area instance */ protected COBOLSequenceNumberArea fCblSequenceNumberArea; /** * The cobol sequence area styled text */ protected StyledText fSequenceAreaText; /** * Instance of the view port listener. */ protected InternalViewPortListener fViewportListener = new InternalViewP ortListener(); /** asynchronous thread used for updating sequence number area*/ private Runnable fRunnable; /** sequence area text used after reverting a file**/ private String fRevertOSavedText; /** the path of the currently open active file in editor*/ private static String fOpenFilePath; /** Specifies whether a bookmark is placed in Free Format or Fixed Forma t*/ private static final String START_FORMAT = "Start_Format"; //$NON-NLS-1$ /** Constant for line delimiter */ private static final String LINE_DELIMITER = "\n"; /** Cobol editor id */ public static final String COBOL_EDITOR_ID = "org.eclipse.cobol.ui.edito r.COBOLEditor"; /** Element analyser for COBOL editor */ COBOLElementAnalyzer fAnalyzer = null; /** AddVariable action contribution */ private TextEditorAction fAddVariableAction = null; private TextEditorAction fCOBOLBreakpointActionPopup = null; private Action fCOBOLBreakpointRulerAction = null;

private TextEditorAction fContentAssistAction = null; private TextEditorAction fGotoLineAction = null; private COBOLPrintAction fPrintAction = null; /** RuntoLine action contribution */ private TextEditorAction fRuntoLineAction; /** ChangeExecutionpoint action contribution */ private TextEditorAction fChangeExecutionpointAction; /** AddVariable action contribution class */ private final static String VARIABLEACTION_CLASS = "org.eclipse.cobol.de bug.ui.actions.AddVariableAction"; /** AddVariable action id */ private final static String VARIABLEACTION_ID = "org.eclipse.cobol.debug .AddVariableAction"; /** ChangeExecutionpoint action contribution class */ private final static String CHANGEEXECUTIONPOINT_CLASS = "org.eclipse.co bol.debug.ui.actions.COBOLChangeExecutionpointAction"; /** ChangeExecutionpoint action id */ private final static String CHANGEEXECUTIONPOINT_ID = "org.eclipse.cobol .debug.COBOLChangeExecutionpoint"; /** RuntoLine action contribution class */ private final static String RUNTOLINE_CLASS = "org.eclipse.cobol.debug.u i.actions.COBOLRuntoLineAction"; /** RuntoLine action contribution id */ private final static String RUNTOLINE_ID = "org.eclipse.cobol.debug.COBO LRuntoLineAction"; private InternalListener fInternalListener = null; /** * The editor's font properties change listener. * @since 2.1 */ private IPropertyChangeListener fFontPropertyChangeListener= new FontPro pertyChangeListener(); /** This editor's encoding support */ private DefaultEncodingSupport fEncodingSupport; /** * The overview ruler of this editor. * @since 2.1 */ //protected IOverviewRuler fOverviewRuler; /** * Helper for accessing annotation from the perspective of this editor. * @since 2.1 */ //protected IAnnotationAccess fAnnotationAccess; /** * Helper for managing the decoration support of this editor's viewer.

* @since 2.1 */ //protected SourceViewerDecorationSupport fSourceViewerDecorationSupport ; /** * The annotation preferences. * @since 2.1 */ //private MarkerAnnotationPreferences fAnnotationPreferences; /** * Preference key for showing the overview ruler. * @since 2.1 */ //private final static String OVERVIEW_RULER= TextEditorPreferenceConsta nts.EDITOR_OVERVIEW_RULER; /** * Preference key for unknown annotation indication in overview ruler. * @since 2.1 **/ //private final static String UNKNOWN_INDICATION_IN_OVERVIEW_RULER= Text EditorPreferenceConstants.EDITOR_UNKNOWN_INDICATION_IN_OVERVIEW_RULER; /** * Preference key for unknown annotation indication. * @since 2.1 **/ //private final static String UNKNOWN_INDICATION= TextEditorPreferenceCo nstants.EDITOR_UNKNOWN_INDICATION; /** * Preference key for unknown annotation color. * @since 2.1 **/ //private final static String UNKNOWN_INDICATION_COLOR= TextEditorPrefer enceConstants.EDITOR_UNKNOWN_INDICATION_COLOR; /** * Preference key for highlighting current line. * @since 2.1 */ //private final static String CURRENT_LINE= TextEditorPreferenceConstant s.EDITOR_CURRENT_LINE; /** * Preference key for highlight color of current line. * @since 2.1 */ //private final static String CURRENT_LINE_COLOR= TextEditorPreferenceCo nstants.EDITOR_CURRENT_LINE_COLOR; /** * Preference key for showing print marging ruler. * @since 2.1 */ //private final static String PRINT_MARGIN= TextEditorPreferenceConstant s.EDITOR_PRINT_MARGIN; /** * Preference key for print margin ruler color. * @since 2.1 */ //private final static String PRINT_MARGIN_COLOR= TextEditorPreferenceCo nstants.EDITOR_PRINT_MARGIN_COLOR; /** * Preference key for print margin ruler column. * @since 2.1

**/ //private final static String PRINT_MARGIN_COLUMN= TextEditorPreferenceC onstants.EDITOR_PRINT_MARGIN_COLUMN; /** The size of the gap between the vertical ruler and the text widget * / public final /*static*/ int GAP_SIZE= 2; /** * Default constructor.Constructs the cobol editor for the file with the * extension of .cob or .cobol or .cbl */ public COBOLEditor() { super(); try { //setRangeIndicator(new DefaultRangeIndicator()); //document provider for Fixed & Variable formats fSeqFormatDocumentProvider = CBDTUiPlugin.getDefault().g etFixedFormatDocumentProvider(); //document provider for Free format fFreeFormatDocumentProvider = CBDTUiPlugin.getDefault(). getFreeFormatDocumentProvider(); setEditorContextMenuId("#CobolTextEditorContext"); //$NO N-NLS-1$ setRulerContextMenuId("#CobolTextRulerContext"); //$NONNLS-1$ //setPreferenceStore(CBDTUiPlugin.getDefault().getPrefer enceStore()); fTextFactory = CBDTUiPlugin.getDefault().getCOBOLTextFac tory(); //adds the listener to the document provider fSeqFormatDocumentProvider.addDocumentChangedListener(fI nternalListener = new InternalListener() { public void updateSequenceBuffer() { setSequenceNumbers(); } }); //instantiating source viewer configuration for both the format fFixedFormatSourceViewerConfiguration = new COBOLFixedFo rmatSourceViewerConfiguration(fTextFactory, this); fFreeFormatSourceViewerConfiguration = new COBOLFreeForm atSourceViewerConfiguration(fTextFactory, this); //3/09/02 - Added for Variable format support fVariableFormatSourceViewerConfiguration = new COBOLVari ableFormatSourceViewerConfiguration(fTextFactory, this); //initializing COBOL Sequence Number Area fCblSequenceNumberArea = new COBOLSequenceNumberArea(); //Associate the element analyzer with this editor

fAnalyzer = new COBOLElementAnalyzer(); fAnalyzer.setEditor(this); fAnalyzer.setPriority(3); fAnalyzer.start(); //fAnnotationPreferences= new MarkerAnnotationPreference s(); } catch (NullPointerException e) { CBDTUiPlugin.logError(e); } } /* (??Javadoc) * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#initialize Editor() */ private IPreferenceStore createCombinedPreferenceStore() { IPreferenceStore cobolStore= CBDTUiPlugin.getDefault().getPrefer enceStore(); IPreferenceStore generalTextStore= EditorsUI.getPreferenceStore( ); return new ChainedPreferenceStore(new IPreferenceStore[] { cobol Store, generalTextStore }); } protected void initializeEditor() { //super.initializeEditor(); //setPreferenceStore(CBDTUiPlugin.getDefault().getPreferenceStor e()); setPreferenceStore(createCombinedPreferenceStore()); setCompatibilityMode(false); } /** * Method addDropListner. * @param control */ public void addDropListner(Control control){ int operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_DEFAUL T; Transfer[] types = new Transfer[] {TextTransfer.getInstance()}; DropTarget target = new DropTarget(control, operations); target.setTransfer(types); target.addDropListener (new DropTargetListener() { public void dragEnter(DropTargetEvent event) { } public void dragOver(DropTargetEvent event) { } public void dragLeave(DropTargetEvent event) { } public void dragOperationChanged(DropTargetEvent event) { } public void dropAccept(DropTargetEvent event) { }

public void drop(DropTargetEvent event) { if (event.data == null) { // no data to copy, in dicate failure in event.detail event.detail = DND.DROP_NONE; return; } Object object = event.data; if(object != null){ String text = object.toString(); pasteIntoEditor(text); } } }); } /** * Checks whether the 'save as' is allowed or not for the file. * @return boolean - true if 'save as' is allowed * @see AbstractTextEditor#isSaveAsAllowed() */ public boolean isSaveAsAllowed() { String previousFilePath = fOpenFilePath; setOpenFilePath(); if (!fOpenFilePath.equals(previousFilePath)) { if (fRefFormat.equals(IReferenceFormatConstants.FIXED_FO RMAT) || fRefFormat.equals(IReferenceFormatConstants.VARIABLE_ FORMAT)) { Object element = getEditorInput(); if (element != null) { fSeqFormatDocumentProvider.setLatestEdit orInfo(element); setSequenceNumbers(); } } } return true; } /** * Performs a 'save as' and reports the result state back to the given * progress monitor. * @param progressMonitor IProgressMonitor */ protected void performSaveAs(IProgressMonitor progressMonitor) { Shell shell = getSite().getShell(); SaveAsDialog dialog = new SaveAsDialog(shell); IEditorInput input = getEditorInput(); if (input instanceof IFileEditorInput) dialog.setOriginalFile(((IFileEditorInput) input).getFil e()); dialog.open(); IPath path = dialog.getResult();

if (path == null) { if (progressMonitor != null) progressMonitor.setCanceled(true); return; } IWorkspace workspace = ResourcesPlugin.getWorkspace(); IFile file = workspace.getRoot().getFile(path); final IEditorInput newInput = new FileEditorInput(file); WorkspaceModifyOperation op = new WorkspaceModifyOperation() { public void execute(final IProgressMonitor monitor) thro ws CoreException { getDocumentProvider().saveDocument(monitor, newI nput, getDocumentProvider().getDocument(getEditorInput()), true); } }; boolean success = false; try { getDocumentProvider().aboutToChange(newInput); new ProgressMonitorDialog(shell).run(false, true, op); success = true; } catch (InterruptedException x) { } catch (InvocationTargetException x) { String title = COBOLEditorMessages.getString("Editor.err or.save.title"); //$NON-NLS-1$ String msg = MessageFormat.format(COBOLEditorMessages.ge tString("Editor.error.save.message"), new Object[] { x.getTargetException().getM essage()}); //$NON-NLS-1$ MessageDialog.openError(shell, title, msg); } finally { getDocumentProvider().changed(newInput); if (success) { setInput(newInput); //call the update of outline view as it requires the new document to be //updated for any furthur change in the editor t o reflect in outline view if(fPage != null) fPage.update(); } } if (progressMonitor != null) progressMonitor.setCanceled(!success); //update the status line updateStatusField(ITextEditorActionConstants.STATUS_CATEGORY_INP UT_POSITION); } /** * Creates the source viewer to be used by this editor. * @param parent the part control * @param ruler the vertical ruler * @param styles Style bits

* @return the source viewer */ protected ISourceViewer createSourceViewer(Composite parent, IVerticalRu ler ruler, int styles) { ISourceViewer svr = null; if (parent == null || ruler == null) { return svr; } fAnnotationAccess= createAnnotationAccess(); //ISharedTextColors sharedColors= EditorsPlugin.getDefault().get SharedTextColors(); //fOverviewRuler= new OverviewRuler(fAnnotationAccess, VERTICAL_ RULER_WIDTH, sharedColors); fOverviewRuler= createOverviewRuler(getSharedColors()); //Iterator e= fAnnotationPreferences.getAnnotationPreferences(). iterator(); //while (e.hasNext()) { // AnnotationPreference preference= (AnnotationPreference) e.next(); // if (preference.contributesToHeader()) // fOverviewRuler.addHeaderAnnotationType(preferenc e.getAnnotationType()); //} //svr = super.createSourceViewer(parent, ruler, styles); //svr = new COBOLSourceViewer(parent, ruler, styles); svr = new COBOLSourceViewer(parent, ruler, getOverviewRuler(), i sOverviewRulerVisible(), styles); addDropListner(parent); // Add the DND dropListner() //fSourceViewerDecorationSupport= new SourceViewerDecorationSupp ort(svr, fOverviewRuler, fAnnotationAccess, sharedColors); //configureSourceViewerDecorationSupport(); getSourceViewerDecorationSupport(svr); //Handler is added to the sourceviewer irrespective of the //format, but the actions are restricted based on the format //This is to handle the other handlers added to the source viewe r fFixedFormatEventHandler = new COBOLFixedFormatEventHandler(svr, this); svr.getTextWidget().addVerifyKeyListener(fFixedFormatEventHandle r); svr.getTextWidget().addVerifyListener(fFixedFormatEventHandler); //3/09/02 - Added for Variable format support fVariableFormatEventHandler = new COBOLVariableFormatEventHandle r(svr, this); svr.getTextWidget().addVerifyKeyListener(fVariableFormatEventHan dler); svr.getTextWidget().addVerifyListener(fVariableFormatEventHandle r); if(fRefFormat.equals(IReferenceFormatConstants.FIXED_FORMAT) || fRefFormat.equals(IReferenceFormatConstants.VARIABLE_FORMAT)) {

//Set the customized tab stop for Fixed format file try { //((StyledText2)(svr.getTextWidget())).setTabSto pMode("Customize", 6); //$NON-NLS-1$ ((StyledText2)(svr.getTextWidget())).setStartCol umn(6); } catch (Exception exception) { //no need to catch the exception } //Modify listener is added to update the status bar if a ny modification inside //the styled text.(This is Eclipse Bug Fix) svr.getTextWidget().addModifyListener(new ModifyListener () { public void modifyText(ModifyEvent e) { updateStatusField(ITextEditorActionConst ants.STATUS_CATEGORY_INPUT_POSITION); } }); } svr.addViewportListener(fViewportListener); svr.addTextListener(fViewportListener); /* * There is no specific handler implementation to the free form at. * if require we can associate the handler to the source viewer by _FORMAT)) * the following piece of code. * else if(fRefFormat.equals(IReferenceFormatConstants.FREE { * Add a handler listener to the source viewer * } */ return svr;

} protected void configureSourceViewerDecorationSupport( SourceViewerDecorationSupport support) { super.configureSourceViewerDecorationSupport(support); String format = decideFormat(); if(format.equals(IReferenceFormatConstants.VARIABLE_FORMAT) || format.equals(IReferenceFormatConstants.FIXED_FORMAT) ) { support.setMarginPainterPreferenceKeys( AbstractDecoratedTextEditorPreferenceCon stants.EDITOR_PRINT_MARGIN, AbstractDecoratedTextEditorPreferenceCon stants.EDITOR_PRINT_MARGIN_COLOR, AbstractDecoratedTextEditorPreferenceCon stants.EDITOR_PRINT_MARGIN_COLUMN + "With6"); } } /* (??Javadoc) * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createAnno tationAccess() */ protected IAnnotationAccess createAnnotationAccess() {

// XXX ???????????????\?b?h?X?^?u return super.createAnnotationAccess(); } /** * Decides the reference format for the editor.It returns the IDE format . * @param input the editor input * @return format for the editor */ protected String decideFormat() { try { IPreferenceStore store = CBDTUiPlugin.getDefault().getPr eferenceStore(); fRefFormat = store.getString(/*COBOLEditorPreferencePage */COBOLEditorPreferenceFormatBlock.REFERENCE_FORMAT); } catch (NullPointerException e) { CBDTUiPlugin.logError(e); } return fRefFormat; } /** * Returns the current source viewer associated with the editor * * @return the source viewer */ //This method is called from renumber dialog for renumbering, //since the getSourceViewer() is protected method,we cannot call the //method directly from outside public ISourceViewer getCurrentSourceViewer() { return getSourceViewer(); } /** * Returns the Cobol Sequence Number area * @return the sequence number area */ //This method is called from renumber dialog for renumbering public COBOLSequenceNumberArea getSequenceNumberArea() { try { return fCblSequenceNumberArea; } catch (NullPointerException e) { CBDTUiPlugin.logError(e); return null; } } /** * Returns reference format of the editor * @return the reference format */ //This method is called from renumber dialog and horizontal ruler public String getReferenceFormat() { return fRefFormat; } /** * Handles a property change event describing a change of the editor's

* preference store and updates the preference related editor properties * @param event the preoperty change event */ protected void handlePreferenceStoreChanged(PropertyChangeEvent event) { ISourceViewer sourceViewer = getSourceViewer(); if (sourceViewer == null) { return; } String property = event.getProperty(); //if (fSourceViewerDecorationSupport != null && fOverviewRuler ! = null && OVERVIEW_RULER.equals(property)) { // if (isOverviewRulerVisible()) // showOverviewRuler(); // else // hideOverviewRuler(); // return; //} fTextFactory.adaptToPreferenceChange(event); if(property.equals(COBOLEditorPreferenceFormatBlock.RESERVED_WOR D)) { sourceViewer.invalidateTextPresentation(); } // // of // // // // // // // // reference */ else if (/*COBOLEditorPreferencePage*/COBOLEditorPreferenceFormatBloc k.TABWIDTH_VALUE_KEY.equals(property)) { final int currentValue = Integer.parseInt(event.getNewVa lue().toString()); final int oldValue = Integer.parseInt(event.getOldValue( ).toString()); // if (currentValue != oldValue) { if (getSourceViewer() != null) { getSourceViewer().getTextWidget().setTab s(currentValue); //this is called to refresh the pid area coloring after //changing the tab width sourceViewer.invalidateTextPresentation( ); //update the status field after changing /* * when there is change in the font preoperty ,call the set font * vetical,horizontal ruler and resize the component */ if (JFaceResources.TEXT_FONT.equals(property)) { super.handlePreferenceStoreChanged(event); setFont(); } /* * Updates the tab value whenever there is any change from the p

the tab updateStatusField(ITextEditorActionConst ants.STATUS_CATEGORY_INPUT_POSITION); } } } // else { // sourceViewer.invalidateTextPresentation(); // } if ( showHRuler != COBOLEditorPreferenceGeneralBlock.isHorizonta lRoulerShow()) { showHRuler = !showHRuler; GridData pGridData = new GridData(); pGridData.horizontalAlignment = GridData.FILL; pGridData.grabExcessHorizontalSpace = true; if(! showHRuler) { pGridData.heightHint = 0; } fHRulerComposite.setLayoutData(pGridData); fHRulerComposite.getParent().layout(); } super.handlePreferenceStoreChanged(event); if (JFaceResources.TEXT_FONT.equals(property)) { setFont(); } } // // // // // // /** Main component from the parent */ private Composite fParent = null; /** The layout used to manage the regular and the status page */ private StackLayout fStackLayout; /** The status page */ private Control fStatusControl; /** Main canvas from the parent Composite */ //private Canvas fMainCanvas = null; /** Parent component from the main composite */ private Composite fParentComp = null; private boolean fIgnoreDocumentEvents = false; // Added by Hiten //private RulerLayout fRulerLayout = null; // Added by Hiten - end /** * Creates the vertical ruler,horizontal ruler and source viewer * @param parent the parent control */ public void createPartControl(Composite Parent) { //fParent = Parent; //fParentComp = new Composite(Parent, SWT.NONE); fParentComp = Parent; //create Horizontel ruler createHorizontalRuler(fParentComp); // ). String defaultId= EditorsPlugin.getDefault().getPreferenceStore(

// getString(AbstractDecora tedTextEditorPreferenceConstants.QUICK_DIFF_DEFAULT_PROVIDER); // String customId =COBOLQuickDiffSupport.getCustomProvider(default Id); // if(customId!=null) { // IPreferenceStore store = CBDTUiPlugin.getDefault().getPr eferenceStore(); // store.setValue(AbstractDecoratedTextEditorPreferenceCons tants.QUICK_DIFF_DEFAULT_PROVIDER,customId); // } super.createPartControl(fParentComp); // if(customId!=null) { // IPreferenceStore store = CBDTUiPlugin.getDefault().getPr eferenceStore(); // store.setToDefault(AbstractDecoratedTextEditorPreference Constants.QUICK_DIFF_DEFAULT_PROVIDER); // } //if (fSourceViewerDecorationSupport != null) // fSourceViewerDecorationSupport.install(getPreferenceStor e()); //fStackLayout= new StackLayout(); //fParent.setLayout(fStackLayout); //fVRuler = getVerticalRuler(); //ReLayout the whole editor composite to accomadate the sequence area styled //text. Control controls[] = fParentComp.getChildren(); //fMainCanvas = (Canvas) controls[1]; controls = ((Composite)controls[1]).getChildren(); controls = ((Composite)controls[0]).getChildren(); Canvas fMainCanvas = (Canvas) controls[0]; //fMainCanvas.setLayout(null); fMainCanvas.setLayout(/*fRulerLayout =*/ new RulerLayout(GAP_SIZ E)); fSequenceAreaText = fCblSequenceNumberArea.createSequenceNumberA rea(fMainCanvas, SWT.NO_FOCUS | SWT.READ_ONLY | SWT.SHADOW_NONE); fSequenceAreaText.setEnabled(false); //setting the height of the horizontal ruler based on the font h eight GC gc = new GC(getSourceViewer().getTextWidget()); GridData hGridData = new GridData(); hGridData.horizontalAlignment = GridData.FILL; hGridData.grabExcessHorizontalSpace = true; hGridData.heightHint = gc.getFontMetrics().getHeight(); fHRuler.setLayoutData(hGridData); gc.dispose(); SourceViewer sViewer = (SourceViewer) getSourceViewer(); Control canvas = sViewer.getControl(); GridData cGridData = new GridData(); cGridData.verticalAlignment = GridData.FILL; cGridData.grabExcessVerticalSpace = true; cGridData.horizontalAlignment = GridData.FILL;

cGridData.grabExcessHorizontalSpace = true; cGridData.grabExcessVerticalSpace = true; canvas.setLayoutData(cGridData); canvas = canvas.getParent(); GridLayout layout = new GridLayout(); layout.horizontalSpacing=layout.verticalSpacing=0; layout.marginHeight=layout.marginWidth=0; ((Composite)canvas).setLayout(layout); cGridData = new GridData(); cGridData.verticalAlignment = GridData.FILL; cGridData.grabExcessVerticalSpace = true; cGridData.horizontalAlignment = GridData.FILL; cGridData.grabExcessHorizontalSpace = true; cGridData.grabExcessVerticalSpace = true; canvas.setLayoutData(cGridData); canvas = canvas.getParent(); layout = new GridLayout(); layout.horizontalSpacing=layout.verticalSpacing=0; layout.marginHeight=layout.marginWidth=0; ((Composite)canvas).setLayout(layout); cGridData = new GridData(); cGridData.verticalAlignment = GridData.FILL; cGridData.grabExcessVerticalSpace = true; cGridData.horizontalAlignment = GridData.FILL; cGridData.grabExcessHorizontalSpace = true; cGridData.grabExcessVerticalSpace = true; canvas.setLayoutData(cGridData); //Set the Text Widget to the horizontel ruler for tracking the //cursor fHRuler.setSourceViewer(getSourceViewer()); //Add the sequence numbers and the handlers for fixed format if (fRefFormat.equals(IReferenceFormatConstants.FIXED_FORMAT)) { setSequenceNumbers(); } //3/09/02 - Added for Variable format support else if (fRefFormat.equals(IReferenceFormatConstants.VARIABLE_FO RMAT)) { setSequenceNumbers(); } //styled text for printing the fixed format file styledTextPrinter = new StyledText(fParentComp, SWT.NONE); //avoiding the spaces consumed by this dummy style text GridData printData = new GridData(); printData.heightHint = 1; styledTextPrinter.setLayoutData(printData); styledTextPrinter.setEditable(false); styledTextPrinter.setVisible(false); JFaceResources.getFontRegistry().addListener(fFontPropertyChange Listener); //This has to be done a the fonts for Editor Styled //text and VerticalRuler,HorizontalRuler are different setFont(); PlatformUI.getWorkbench().getHelpSystem().setHelp(fParentComp, I COBOLHelpContextId.COBOL_EDITOR_BOOKMARK_ACTION);

//Call to check the status of the input. //This is fix for avoiding the failure of the opening the COBOL editor if the //file doesn't exist in the physical location updatePartControl(getEditorInput()); } /* * @see org.eclipse.ui.texteditor.ITextEditorExtension3#showChangeInform ation(boolean) */ public void showChangeInformation(boolean show) { final String CVSReferenceProvider_FOR_FORMAL = "org.eclipse.quic kdiff.providers.CVSReferenceProvider"; final String CVSReferenceProvider_FOR_COBOL = "org.eclipse.cobol .ui.editor.quickdiff.COBOLCVSReferenceProvider"; final String LastSaveReferenceProvider_FOR_NORMAL = "org.eclipse .ui.internal.editors.quickdiff.LastSaveReferenceProvider"; final String LastSaveReferenceProvider_FOR_COBOL = "org.eclipse. cobol.ui.editor.quickdiff.COBOLLastSaveReferenceProvider"; String QUICK_DIFF_DEFAULT_PROVIDER=AbstractDecoratedTextEditorPr eferenceConstants.QUICK_DIFF_DEFAULT_PROVIDER; IPreferenceStore store= CBDTUiPlugin.getDefault().getPreferenceS tore(); if (store != null) { String defaultId=EditorsUI.getPreferenceStore().getStrin g(QUICK_DIFF_DEFAULT_PROVIDER); if(defaultId.equals(CVSReferenceProvider_FOR_FORMAL)) { defaultId=CVSReferenceProvider_FOR_COBOL; try { IEditorInput input= getEditorInput(); if (input != null) { IFile file = ResourceUtil.getFile(input); if(file == null || ! CVSWorkspaceRoot.isSharedWi thCVS(file)) { defaultId=LastSaveRefere nceProvider_FOR_NORMAL; } } } catch (Exception e) { defaultId=LastSaveReferenceProvider_FOR_ NORMAL; } } if(defaultId.equals(LastSaveReferenceProvider_FOR_NORMAL )) { defaultId=LastSaveReferenceProvider_FOR_COBOL; } if(!store.getString(QUICK_DIFF_DEFAULT_PROVIDER).equals( defaultId)) { store.setValue(QUICK_DIFF_DEFAULT_PROVIDER,defau ltId); } } super.showChangeInformation(show); } // // /** * Checks if the status of the given input is OK. If not the

// * status control is shown rather than the default control. // * // * @param input the input whose status is checked // */ // public void updatePartControl(IEditorInput input) { // // if (fStatusControl != null) { // fStatusControl.dispose(); // fStatusControl= null; // } // // Control front= null; // if (fParent != null && input != null) { // if (getDocumentProvider() instanceof IDocumentProviderEx tension) { // IDocumentProviderExtension extension= (IDocument ProviderExtension) getDocumentProvider(); // IStatus status= extension.getStatus(input); // if (status.isOK()) { // front = fParentComp; // } else { // fStatusControl = createStatusControl(fPa rent, status); // front= fStatusControl; // } // } // } // // if (fStackLayout.topControl != front) { // fStackLayout.topControl= front; // fParent.layout(); // super.updateStatusFields(); // } // } // /** // * Creates the status control for the given status. May be overridden by subclasses. // * // * @param parent the parent control // * @param status the status // */ // protected Control createStatusControl(Composite parent, IStatus status) { // InfoForm infoForm= new InfoForm(parent); // infoForm.setHeaderText(""); // infoForm.setBannerText(""); // infoForm.setInfo(status.getMessage()); // return infoForm.getControl(); // } /** * Returns a header for the given status * * @param status the status whose message is returned * @return a header for the given status */ protected String getStatusHeader(IStatus status) { if (fEncodingSupport != null) { String message= fEncodingSupport.getStatusHeader(status)

; if (message != null) return message; } return super.getStatusHeader(status); } /** * Returns a banner for the given status. * * @param status the status whose message is returned * @return a banner for the given status */ protected String getStatusBanner(IStatus status) { if (fEncodingSupport != null) { String message= fEncodingSupport.getStatusBanner(status) ; if (message != null) return message; } return super.getStatusBanner(status); } /** * Returns a message for the given status. * * @param status the status whose message is returned * @return a message for the given status */ protected String getStatusMessage(IStatus status) { if (fEncodingSupport != null) { String message= fEncodingSupport.getStatusMessage(status ); if (message != null) return message; } return super.getStatusMessage(status); } /** * Creates the status line message instance */ private void createStatusLineMessageProvider() { if (fStatusLineMsg == null) { IEditorActionBarContributor contributor = getEditorSite( ).getActionBarContributor(); if (contributor != null) { IStatusLineManager statusLineManager = ((EditorA ctionBarContributor) contributor).getActionBars().getStatusLineManager(); fStatusLineMsg = COBOLStatusLineMessages.getInst ance(statusLineManager); } } } /** * Sets the sequence numbers to the sequence number area and also sets t he

* handler to the sequence number area. */ private void setSequenceNumbers() { //Sets the sequence number buffer and the corresponding style te xt if (fCblSequenceNumberArea != null) { if (fRefFormat.equalsIgnoreCase(IReferenceFormatConstant s.FIXED_FORMAT)) { StringBuffer sequenceBuffer = fSeqFormatDocument Provider.getSequenceNumberBuffer(); if(sequenceBuffer != null){ fCblSequenceNumberArea.setSequenceNumber sControl(sequenceBuffer); } //The preserved text should be set to the last s aved //sequence buffer.This will be used by the //undo manager StringBuffer lastSequenceBuffer = fSeqFormatDocu mentProvider.getLastSavedSequenceNumberBuffer(); if(lastSequenceBuffer != null){ fCblSequenceNumberArea.setPreservedText( lastSequenceBuffer.toString()); } //once the sequence area text is set , the top index //should also be set to the current editors //top index int topPixel = getSourceViewer().getTextWidget() .getTopPixel(); if (topPixel != fCblSequenceNumberArea.getSequen ceNumberAreaText().getTopPixel()) fCblSequenceNumberArea.getSequenceNumber AreaText().setTopPixel(topPixel); //For a revert to saved operation, which is a sp l case , the //preserved text should be set to one just befor e //revert and not the last saved sequence number buffer. if (fRevertOSavedText != null) { fCblSequenceNumberArea.setPreservedText( fRevertOSavedText); fRevertOSavedText = null; } //Setting Pattern fCblSequenceNumberArea.setPatternFlag(fSeqFormat DocumentProvider.isPatternB()); //set the handler if (fFixedFormatEventHandler != null) { ((COBOLFixedFormatEventHandler) fFixedFo rmatEventHandler).setCOBOLSequenceNumberHandler(fCblSequenceNumberArea, fCblSequ

enceNumberArea.isNewFile()); } //set the sequence area to the undo manager if (fFixedFormatSourceViewerConfiguration != nul l) { ((COBOLFixedFormatUndoManager) (fFixedFo rmatSourceViewerConfiguration.getUndoManager(getSourceViewer()))).connectSequenc eArea(fCblSequenceNumberArea); } } //3/09/02 - Added for Variable format support else if (fRefFormat.equalsIgnoreCase(IReferenceFormatCon stants.VARIABLE_FORMAT)) { StringBuffer sequenceBuffer = fSeqFormatDocument Provider.getSequenceNumberBuffer(); if(sequenceBuffer != null){ fCblSequenceNumberArea.setSequenceNumber sControl(sequenceBuffer); } //The preserved text should be set to the last s aved //sequence buffer.This will be used by the //undo manager StringBuffer lastSequenceBuffer = fSeqFormatDocu mentProvider.getLastSavedSequenceNumberBuffer(); if(lastSequenceBuffer != null){ fCblSequenceNumberArea.setPreservedText( lastSequenceBuffer.toString()); } //once the sequence area text is set , the top index //should also be set to the current editors //top index int topPixel = getSourceViewer().getTextWidget() .getTopPixel(); if (topPixel != fCblSequenceNumberArea.getSequen ceNumberAreaText().getTopPixel()) fCblSequenceNumberArea.getSequenceNumber AreaText().setTopPixel(topPixel); //For a revert to saved operation, which is a sp l case , the //preserved text should be set to one just befor e //revert and not the last saved sequence number buffer. if (fRevertOSavedText != null) { fCblSequenceNumberArea.setPreservedText( fRevertOSavedText); fRevertOSavedText = null; } //Setting Pattern fCblSequenceNumberArea.setPatternFlag(fSeqFormat DocumentProvider.isPatternB()); //set the handler

if (fVariableFormatEventHandler != null) { ((COBOLVariableFormatEventHandler) fVari ableFormatEventHandler).setCOBOLSequenceNumberHandler(fCblSequenceNumberArea, fC blSequenceNumberArea.isNewFile()); } //set the sequence area to the undo manager if (fVariableFormatSourceViewerConfiguration != null) { ((COBOLVariableFormatUndoManager) (fVari ableFormatSourceViewerConfiguration.getUndoManager(getSourceViewer()))).connectS equenceArea(fCblSequenceNumberArea); } } } } /** * Creates the horizontal ruler for displaying the current cursor positi on. * * @param parent the parent control */ private void createHorizontalRuler(Composite parent) { //set the grid layout to parent GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 1; gridLayout.marginHeight = 0; gridLayout.marginWidth = 0; //fixed the bug reported by client regarding, extra //space coming before the horizontal scrollbar //in the editor gridLayout.horizontalSpacing=0; gridLayout.verticalSpacing=0; parent.setLayout(gridLayout); fHRulerComposite = new Composite(parent, SWT.NO_FOCUS); GridData pGridData = new GridData(); pGridData.horizontalAlignment = GridData.FILL; pGridData.grabExcessHorizontalSpace = true; if(! COBOLEditorPreferenceGeneralBlock.isHorizontalRoulerShow()) { pGridData.heightHint = 0; showHRuler = false; } fHRulerComposite.setLayoutData(pGridData); GridLayout hGridLayout = new GridLayout(); hGridLayout.numColumns = 2; hGridLayout.verticalSpacing = 0; hGridLayout.horizontalSpacing = 0; hGridLayout.marginWidth = 0; hGridLayout.marginHeight = 0; fHRulerComposite.setLayout(hGridLayout); fHRulerSpacer = new Label(fHRulerComposite, SWT.NO_FOCUS); GridData lGridData = new GridData(); lGridData.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINN ING;

lGridData.widthHint = VERTICAL_RULER_WIDTH + GAP_SIZE; fHRulerSpacer.setLayoutData(lGridData); //create the horizontal ruler fHRuler = new COBOLHorizontalRuler(fHRulerComposite, this); //Label thinLineSpace = new Label(sParent, SWT.NO_FOCUS); //GridData thinLineGridData = new GridData(GridData.FILL_HORIZON TAL); //thinLineGridData.horizontalSpan=2; //thinLineGridData.heightHint = 5; //thinLineSpace.setLayoutData(thinLineGridData); //Set the mode for Horizontal Scale also fHRuler.setMode(fRefFormat); //return fHRuler; } /** * Creates the editor's standard actions and connects them with the glob al * workbench actions. */ protected void createActions() { try { super.createActions(); // if the editor input is not IFileEditorInput then simp ly return if(false == getEditorInput() instanceof IFileEditorInput ) return; ResourceAction action= new AddTaskAction(COBOLEditorMess ages.getResourceBundle(), "Editor.AddTask.", this); //$NON-NLS-1$ action.setHelpContextId(IAbstractTextEditorHelpContextId s.ADD_TASK_ACTION); action.setActionDefinitionId(ITextEditorActionDefinition Ids.ADD_TASK); setAction(ITextEditorActionConstants.ADD_TASK, action); fContentAssistAction = new COBOLContentAssistantAction(C OBOLEditorMessages.getResourceBundle(), CONTENT_ASSIST_RESOURCE_KEY_PREFIX, this, ISourc eViewer.CONTENTASSIST_PROPOSALS); fContentAssistAction.setActionDefinitionId(ITextEditorAc tionDefinitionIds.CONTENT_ASSIST_PROPOSALS); setAction(CONTENT_ASSIST_ACTION_ID, fContentAssistAction ); markAsStateDependentAction("ContentAssistProposal", true ); //$NON-NLS-1$ fGotoLineAction = new COBOLGotoLineAction(COBOLEditorMes sages.getResourceBundle(), this); fGotoLineAction.setActionDefinitionId(ITextEditorActionD efinitionIds.LINE_GOTO); if (fGotoLineAction != null) { setAction(ITextEditorActionConstants.GOTO_LINE,

null); // Remove the earlier contribution setAction(ITextEditorActionConstants.GOTO_LINE, fGotoLineAction); } fCOBOLBreakpointRulerAction = new COBOLBreakpointRulerAc tion(getVerticalRuler(), this); setAction("ManageCobolBreakpoints", fCOBOLBreakpointRule rAction); //$NON-NLS-1$ setAction(ITextEditorActionConstants.RULER_DOUBLE_CLICK, getAction("ManageCobolBreakpoints")); //$NON-NLS-1$ //adding the printer action if(SWT.getPlatform().equalsIgnoreCase("motif") || SWT.getPlatform().equalsIgnoreCase("gtk") ) { setAction(ITextEditorActionConstants.PRINT, null ); } else { fPrintAction = new COBOLPrintAction(COBOLEditorM essages.getString("Print"), this); //$NON-NLS-1$ setAction(ITextEditorActionConstants.PRINT, fPri ntAction); } //adding the break point action fCOBOLBreakpointActionPopup = new COBOLBreakpointActionP opup(this); setAction(ADD_BREAKPOINT, fCOBOLBreakpointActionPopup); //adding the renumbering action. Note: This is specifically added fo r editor context menu actions renumberAction = new COBOLRenumberAction(COBOLDialogProp erties.getString("renumberMenuItem")); //$NON-NLS-1$ renumberAction.setEditor(this); setAction(RENUMBER, renumberAction); createStatusLineMessageProvider(); try { ClassLoader classloader = Platform.getPluginRegi stry().getPluginDescriptor("org.eclipse.cobol.debug.ui").getPluginClassLoader(); //$NON-NLS-1$ if ( classloader != null ){ fAddVariableAction = (TextEditorAction) classloader.loadClass(VARIABLEACTION_CLASS).newInstance(); fAddVariableAction.setText(COBOLEditorMe ssages.getString("AddWatch.label")); fAddVariableAction.setId(VARIABLEACTION_ ID); fAddVariableAction.setEnabled(false); fAddVariableAction.setEditor(this); fAddVariableAction.setImageDescriptor(CO BOLPluginImages.DESC_IMG_ADD_WATCH); ((IEditorActionDelegate)fAddVariableActi on).setActiveEditor(fAddVariableAction, this); setAction(VARIABLEACTION_ID, fAddVariabl eAction); fChangeExecutionpointAction = (TextEdito rAction) classloader.loadClass(CHANGEEXECUTIONPOINT_CLASS).newInstance(); fChangeExecutionpointAction.setText(COBO

LEditorMessages.getString("ChangeExecutionPoint.label")); fChangeExecutionpointAction.setId(CHANGE EXECUTIONPOINT_ID); fChangeExecutionpointAction.setEnabled(f alse); fChangeExecutionpointAction.setEditor(th is); setAction(CHANGEEXECUTIONPOINT_ID, fChan geExecutionpointAction); ((IEditorActionDelegate)fChangeExecution pointAction).setActiveEditor(fChangeExecutionpointAction, this); fRuntoLineAction = (TextEditorAction) cl assloader.loadClass(RUNTOLINE_CLASS).newInstance(); fRuntoLineAction.setText(COBOLEditorMess ages.getString("RunToLine.label")); fRuntoLineAction.setId(RUNTOLINE_ID); fRuntoLineAction.setEnabled(false); fRuntoLineAction.setEditor(this); ((IEditorActionDelegate)fRuntoLineAction ).setActiveEditor(fRuntoLineAction, this); setAction(RUNTOLINE_ID, fRuntoLineAction ); } fEncodingSupport= new DefaultEncodingSupport(); fEncodingSupport.initialize(this); } catch (InstantiationException e) { CBDTUiPlugin.logError(e); } catch (IllegalAccessException e) { CBDTUiPlugin.logError(e); } catch (ClassNotFoundException e) { CBDTUiPlugin.logError(e); } } catch (NullPointerException e) { CBDTUiPlugin.logError(e); } } /** * If the editor can be saved, all marker ranges have been changed accor ding to * the text manipulations. However, those changes are not yet propagated to the * marker manager. Thus, when opening a marker, the marker's position in the editor * must be determined as it might differ from the position stated in the marker. * * @param marker the marker instance */ public void gotoMarker(IMarker marker) { try { if (marker == null) { return; } else if (marker.getType().equals(IMarker.PROBLEM)) { DependencyModelManipulation.initializeProblemMar

kers(); } } catch (CoreException e) { CBDTUiPlugin.logError(e); } //call to go to marker try { super.gotoMarker(marker); //Set the top pixels only for FIXED FORMAT and VARIABLE FORMAT if(false == fRefFormat.equalsIgnoreCase(IReferenceFormat Constants.FREE_FORMAT)) { int topPixel = getSourceViewer().getTextWidget() .getTopPixel(); int seqPixel = fCblSequenceNumberArea.getSequenc eNumberAreaText().getTopPixel(); if (seqPixel > 0 && topPixel != seqPixel) { getSourceViewer().getTextWidget().setTop Pixel(fCblSequenceNumberArea.getSequenceNumberAreaText().getTopPixel()); } else if(seqPixel == 0) { //this is fix for format change and call to a marker at the //last line fCblSequenceNumberArea.getSequenceNumber AreaText().setTopPixel(topPixel); } } /*fVRuler*/getVerticalRuler().update(); } catch (NullPointerException ne) { CBDTUiPlugin.logError(ne); } } /* * Sets the focus on this * @return void */ /* Everytime the focus is * Preserved Text,Pattern * the document provider. * controls so that it is * provider values. */ public void setFocus() { editor as the active editor recieved set the Sequence number, of the latest editor in Also reset sequence number in sync with the document

/*The following step should be done if the focus is on a * a different editor from the previous one.This will * reduce unwanted settings to the sequence area styled * text and help reduce flickering */ String previousFilePath = fOpenFilePath; setOpenFilePath(); if (!fOpenFilePath.equals(previousFilePath)) { if (fRefFormat.equals(IReferenceFormatConstants.FIXED_FO RMAT) ||fRefFormat.equals(IReferenceFormatConstants.VARIABLE _FORMAT)) { Object element = getEditorInput(); if (element != null) {

fSeqFormatDocumentProvider.setLatestEdit orInfo(element); setSequenceNumbers(); } } } super.setFocus(); //initialize the problem marker if any DependencyModelManipulation.initializeProblemMarkers(); updateStatusField(ITextEditorActionConstants.STATUS_CATEGORY_INP UT_POSITION); //Fix for error showing even after editor deativated and activat ed if(fStatusLineMsg != null) fStatusLineMsg.setErrorMessageText(""); //$NON-NLS-1$ } /** * Returns the styled text used for printing * * @return the styled text for printing */ public StyledText getPrinterStyledText() { return styledTextPrinter; } /** * This method is called when the contents of this editor have changed s ince * the last save operation. This method is overriden to reflect the chan ges * in sequence number area after renumbering the sequence numbers. * @return true if the sequence numbers or file in editor are changed . */ public boolean isDirty() { if (fRefFormat.equals(IReferenceFormatConstants.FIXED_FORMAT)) { if (fCblSequenceNumberArea != null) { if (fCblSequenceNumberArea.isDirty()) { return true; } } } else if (fRefFormat.equals(IReferenceFormatConstants.VARIABLE_ FORMAT)) { if (fCblSequenceNumberArea != null) { if (fCblSequenceNumberArea.isDirty()) { return true; } } } return super.isDirty(); } /** * Saves the document.And this method is overridden to reset the isDirty flag in * sequence number area. * @param progressMonitor Progress Monitor

* @return void */ public void doSave(IProgressMonitor progressMonitor) { COBOLMarkerAnnotationModel model = ((COBOLMarkerAnnotationModel) getDocumentProvider().getAnnotationModel(getEditorInput())); if (model != null) model.setDirtyFlag(false); IFileEditorInput fileInput = (IFileEditorInput) getEditorInput() ; IPath path = fileInput.getFile().getFullPath(); IWorkspace wr = CBDTUiPlugin.getWorkspace(); /* * All the search markers attribute is set to true. * This is because on save , the createPositionFromMarker * is called, which will update all the markers. For * a file that is going from dirty to saved state, the * marker positions are already updated and should not * be computed again. */ if (wr != null && wr instanceof Workspace) { Workspace workspace = (Workspace) wr; ResourceInfo ri = workspace.getResourceInfo(path, false, false); if (ri != null) { MarkerSet marker = ri.getMarkers(); if (marker != null) { IMarkerSetElement[] markers = marker.ele ments(); for (int i = 0; i < markers.length; i++) { MarkerInfo markerInfo = (MarkerI nfo) markers[i]; String type = markerInfo.getType (); if (type.equals(SearchUI.SEARCH_ MARKER)) { markerInfo.setAttribute( "Save", new Boolean(true)); //$NON-NLS-1$ } } } } } if (fFixedFormatEventHandler != null) { if (fFixedFormatEventHandler instanceof COBOLFixedFormat EventHandler) { ((COBOLFixedFormatEventHandler) fFixedFormatEven tHandler).setModelUpdateFlag(); } } if (fVariableFormatEventHandler != null) { if (fVariableFormatEventHandler instanceof COBOLVariable FormatEventHandler) { ((COBOLVariableFormatEventHandler) fVariableForm atEventHandler).setModelUpdateFlag();

} } try { if (fRefFormat.equals(IReferenceFormatConstants.FIXED_FO RMAT)) { fCblSequenceNumberArea.reSetIsDirty(); } else if (fRefFormat.equals(IReferenceFormatConstants.V ARIABLE_FORMAT)) { fCblSequenceNumberArea.reSetIsDirty(); } super.doSave(progressMonitor); /* * reset all the search markers save attribute * back to false */ if (wr != null && wr instanceof Workspace) { Workspace workspace = (Workspace) wr; ResourceInfo ri = workspace.getResourceInfo(path , false, false); if (ri != null) { MarkerSet marker = ri.getMarkers(); if (marker != null) { IMarkerSetElement[] markers = ma rker.elements(); for (int i = 0; i < markers.leng th; i++) { MarkerInfo markerInfo = (MarkerInfo) markers[i]; String type = markerInfo .getType(); if (type.equals(SearchUI .SEARCH_MARKER)) { markerInfo.setAt tribute("Save", new Boolean(false)); //$NON-NLS-1$ } } } } } } catch (NullPointerException e) { CBDTUiPlugin.logError(e); } } /** * Returns the content outline page. * @return Cobol outline page */ public COBOLContentOutlinePage getOutlinePage() { return fPage; } /** * This method is called from sequence number area after the renumber * function to indicate to the editor that the text has been changed by * renumbering. *

* @return void */ public void fireChanges() { //update the pattern of the file to the document //provider also,as the pattern might have //changed after renumbering. if (fRefFormat.equalsIgnoreCase(IReferenceFormatConstants.FIXED_ FORMAT) || fRefFormat.equalsIgnoreCase(IReferenceFormatConstants.VA RIABLE_FORMAT)) { fSeqFormatDocumentProvider.updatePattern(fCblSequenceNum berArea.isPatternB(), getEditorInput()); } // if more than one window is open //update this change to all the windows IWorkbenchWindow windows[] = getEditorSite().getWorkbenchWindow( ).getWorkbench().getWorkbenchWindows(); if (windows.length > 1) { Display display = getSite().getShell().getDisplay(); display.asyncExec(getRunnable()); } //call to this method directly from the other class is protect ed firePropertyChange(PROP_DIRTY); } /** * Reverts to the last saved document. * @return void */ /* * This method is overridden to reflect the revert change in the sequence number area * for the fixed/variable format. */ public void doRevertToSaved() { if (!fRefFormat.equalsIgnoreCase(IReferenceFormatConstants.FREE_ FORMAT)) { StringBuffer lastSavedSeqBuffer = null; if (fRefFormat.equalsIgnoreCase(IReferenceFormatConstant s.FIXED_FORMAT) || fRefFormat.equalsIgnoreCase(IReferenceFormatCons tants.VARIABLE_FORMAT)) { lastSavedSeqBuffer = fSeqFormatDocumentProvider. getLastSavedSequenceNumberBuffer(); } if (lastSavedSeqBuffer != null) { //before revert set th e preserved seq text fCblSequenceNumberArea.setPreservedText(); //thi s has to be done as while reverting a file,the //previous sequence number has to be saved. This is a special //case.This preserved text will be later used in //setSequenceNumbers() to set the preserved text

. //Provides bug fix for case : Change a file,pres s enter, //do revert,press undo. fRevertOSavedText = fCblSequenceNumberArea.getPr eservedText(); fCblSequenceNumberArea.resetSequenceNumberArea(l astSavedSeqBuffer.toString()); } else { //for new file buffer will be null .so update t he sequence area with the empty string //before revert set the preserved seq text fCblSequenceNumberArea.setPreservedText(); fRevertOSavedText = fCblSequenceNumberArea.getPr eservedText(); fCblSequenceNumberArea.resetSequenceNumberArea(" "); //$NON-NLS-1$ } //after renumbering revert was does not work. the //following line solves it. fCblSequenceNumberArea.reSetIsDirty(); } super.doRevertToSaved(); } /** * Returns an object which is an instance of the given class associated * with this object. * This method is overridden to adapt the customized outline page for co bol. * * @param key the adapter class to look up * @return a object castable to the given class, or null if this object does not have an adapter for the given class */ public Object getAdapter(Class key) { if (IEncodingSupport.class.equals(key)) return fEncodingSupport; if (key.equals(IContentOutlinePage.class)) { IEditorInput input = getEditorInput(); ISourceViewer iSourceViewer = getSourceViewer(); if (input instanceof IFileEditorInput) { fPage = new COBOLContentOutlinePage(((IFileEdito rInput) input).getFile(), this, iSourceViewer); return fPage; } //This below code will come into place when the .cob fil e is opened //from the CVS Resource history view else if(input instanceof IStorageEditorInput) { fPage = new COBOLContentOutlinePage(iSourceViewe r.getDocument(), this, iSourceViewer); return fPage; } } return super.getAdapter(key); } /**

* Sets the font for the editor. */ protected void setFont() { try { fSequenceAreaText.setFont(getSourceViewer().getTextWidge t().getFont()); fHRuler.setFont(getSourceViewer().getTextWidget().getFon t()); //set the font to the StyledText which is used to print when the format is Fixed/Variable styledTextPrinter.setFont(getSourceViewer().getTextWidge t().getFont()); styledTextPrinter.setBackground(getSourceViewer().getTex tWidget().getBackground()); styledTextPrinter.setForeground(getSourceViewer().getTex tWidget().getForeground()); reLayout(); } catch (NullPointerException e) { CBDTUiPlugin.logError(e); } } /** * Sets the font for the editor. * * @param font */ protected void setFont(Font font) { try { fSequenceAreaText.setFont(font); fHRuler.setFont(font); reLayout(); } catch (NullPointerException e) { CBDTUiPlugin.logError(e); } } /** * This method relayouts the whole editor area. This * is done when ever the font changes, or when * the format of the editor changes between fixed,variable or free form ats * * @return void */ protected void reLayout() { GC gc = new GC(getSourceViewer().getTextWidget()); FontMetrics fm = gc.getFontMetrics(); final int height = fm.getHeight(); gc.dispose(); //relayout the horizontal ruler,vertical ruler,editor after the font changes ((GridData) fHRuler.getLayoutData()).heightHint = height + GAP_ SIZE; //fVRuler.getControl().getParent().layout(true); //getSourceViewer().getTextWidget().getParent().getParent().layo ut(true); fParentComp.layout(true);

//this will solve a bug which states that the sequence number ar ea does not scroll //properly when the font is changed in the Preference Page. setSequenceNumbers(); // should not create problems in other sce narios pls check } /** * Sets the input to the editor.And this method decides the format of th e file * at the time of reusing the editor and checks for the reuseablity of t he * editor. * @param input IEditorInput * @throws CoreException - if number of opened editor exceeds the prefer ence set * @return void */ protected void doSetInput(IEditorInput input) throws CoreException { try { if (input == null) { super.doSetInput(input); } else { String oldFormat = fRefFormat; //Store the old format fRefFormat = decideFormat(); IEditorInput oldInput = getEditorInput(); if (oldInput != null) { //Means we are reusing //Since we are reusing - check if Editor has to be //Changed to support a different format boolean needToChangeEditor = true; if (oldFormat != null) { needToChangeEditor = (oldFormat. equalsIgnoreCase(fRefFormat) ? false : true); } if (needToChangeEditor) { getDocumentProvider().disconnect (oldInput); oldInput = null; fTextFactory.setFormat(fRefForma t); if (fRefFormat.equals(IReference FormatConstants.FIXED_FORMAT)) { if(oldFormat.equals(IRef erenceFormatConstants.VARIABLE_FORMAT)) { //remove the var iable format key listeners getSourceViewer( ).getTextWidget().removeVerifyKeyListener(fVariableFormatEventHandler); getSourceViewer( ).getTextWidget().removeVerifyListener(fVariableFormatEventHandler);

} //set the fixed format k ay listeners getSourceViewer().getTex tWidget().addVerifyKeyListener(fFixedFormatEventHandler); getSourceViewer().getTex tWidget().addVerifyListener(fFixedFormatEventHandler); setDocumentProvider(fSeq FormatDocumentProvider); //configure the source v iewer with the changed source viewer configuration getSourceViewer().config ure(fFixedFormatSourceViewerConfiguration); super.doSetInput(input); setSequenceNumbers(); //Set the mode for Horiz ontal Scale also fHRuler.setMode(fRefForm at); //set the sequence area to the undo manager ((COBOLFixedFormatUndoM anager) (fFixedFormatSourceViewerConfiguration.getUndoManager(getSourceViewer()) )).connectSequenceArea(fCblSequenceNumberArea); //set the customized tab stop for fixed format try { //((StyledText2) (getSourceViewer().getTextWidget())).setTabStopMode("Customize", 6); //$NON-NLS1$ ((StyledText2)(g etSourceViewer().getTextWidget())).setStartColumn(6); } catch (Exception e) { //no need to catch the exception } } else if (fRefFormat.equals(IRe ferenceFormatConstants.VARIABLE_FORMAT)) { if(oldFormat.equals(IRef erenceFormatConstants.FIXED_FORMAT)) { //remove the fix ed format key listeners getSourceViewer( ).getTextWidget().removeVerifyKeyListener(fFixedFormatEventHandler); getSourceViewer( ).getTextWidget().removeVerifyListener(fFixedFormatEventHandler); } //set the variable forma t kay listeners getSourceViewer().getTex tWidget().addVerifyKeyListener(fVariableFormatEventHandler); getSourceViewer().getTex tWidget().addVerifyListener(fVariableFormatEventHandler); setDocumentProvider(fSeq FormatDocumentProvider); //configure the source v iewer with the changed source viewer configuration

getSourceViewer().config ure(fVariableFormatSourceViewerConfiguration); super.doSetInput(input); setSequenceNumbers(); //Set the mode for Horiz ontal Scale also fHRuler.setMode(fRefForm at); //set the sequence area to the undo manager ((COBOLVariableFormatUn doManager) (fVariableFormatSourceViewerConfiguration.getUndoManager(getSourceVie wer()))).connectSequenceArea(fCblSequenceNumberArea); try { //((StyledText2) (getSourceViewer().getTextWidget())).setTabStopMode("Customize", 6); //$NON-NLS1$ ((StyledText2)(g etSourceViewer().getTextWidget())).setStartColumn(6); } catch (Exception e) { } } else if (fRefFormat.equals(IRe ferenceFormatConstants.FREE_FORMAT)) { //configure the source viewer with the ch anged source viewer configuration if(oldFormat.equals(IRef erenceFormatConstants.VARIABLE_FORMAT)) { //remove the var iable format key listeners getSourceViewer( ).getTextWidget().removeVerifyKeyListener(fVariableFormatEventHandler); getSourceViewer( ).getTextWidget().removeVerifyListener(fVariableFormatEventHandler); } else if(oldFormat.equa ls(IReferenceFormatConstants.FIXED_FORMAT)) { //remove the fix ed format key listeners getSourceViewer( ).getTextWidget().removeVerifyKeyListener(fFixedFormatEventHandler); getSourceViewer( ).getTextWidget().removeVerifyListener(fFixedFormatEventHandler); } getSourceViewer().config ure(fFreeFormatSourceViewerConfiguration); setDocumentProvider(fFre eFormatDocumentProvider); super.doSetInput(input); //Set the mode for Horizontal Scale also fHRuler.setMode(fRefForm at); try { //reset the tab fo rmat to default //((StyledText2) (getSourceViewer().getTextWidget())).setTabStopMode("Default", 0); //$NON-NLS-1$ ((StyledText2)(g etSourceViewer().getTextWidget())).setStartColumn(0); } catch (Exception e) { //no need to catch the exception } } } else {

//We are resuing the Editor for a file in the same format //Do nothing super.doSetInput(input); //Set the sequence nos here for fixed format. if (fRefFormat.equals(IReference FormatConstants.FIXED_FORMAT)) { setSequenceNumbers(); } else if (fRefFormat.equals(IRe ferenceFormatConstants.VARIABLE_FORMAT)) { setSequenceNumbers(); } } } else { //First time - no need to check if we h ave to change Editor fTextFactory.setFormat(fRefFormat); if (fRefFormat.equals(IReferenceFormatCo nstants.FIXED_FORMAT)) { setDocumentProvider(fSeqFormatDo cumentProvider); setSourceViewerConfiguration(fFi xedFormatSourceViewerConfiguration); } else if (fRefFormat.equals(IReferenceF ormatConstants.VARIABLE_FORMAT)) { setDocumentProvider(fSeqFormatDo cumentProvider); setSourceViewerConfiguration(fVa riableFormatSourceViewerConfiguration); } else if (fRefFormat.equals(IReferenceF ormatConstants.FREE_FORMAT)) { setDocumentProvider(fFreeFormatD ocumentProvider); setSourceViewerConfiguration(fFr eeFormatSourceViewerConfiguration); } super.doSetInput(input); } } if (fEncodingSupport != null) fEncodingSupport.reset(); } catch (NullPointerException e) { CBDTUiPlugin.logError(e); } } /* * @see AbstractTextEditor#createVerticalRuler() */ //protected IVerticalRuler createVerticalRuler() { // CompositeRuler ruler = new CompositeRuler(); // ruler.addDecorator(0, new AnnotationRulerColumn(VERTICAL_RULER_W IDTH)); // //} return ruler;

/** * Returns the reference format handler. * @return the reference format handler */ public IReferenceFormatHandler getReferenceFormatHandler() { if(fRefFormat.equals(IReferenceFormatConstants.FIXED_FORMAT)) { return fFixedFormatEventHandler; } if(fRefFormat.equals(IReferenceFormatConstants.VARIABLE_FORMAT)) { return fVariableFormatEventHandler; } return null; } /** * Returns the editor's mode.The mode is Overwrite/Insert. * And also informs the event listener, whenever there is a change * in the mode. * @return <code>true</code> if editr is in insert mode, * <code>false</code> for overwrite mode */ protected boolean isInInsertMode() { try { //informs only to the fixed format event listener if (fRefFormat.equalsIgnoreCase(IReferenceFormatConstant s.FIXED_FORMAT)) { ((COBOLFixedFormatEventHandler) fFixedFormatEven tHandler).setInsertModeFlag(super.isInInsertMode()); } else if(fRefFormat.equalsIgnoreCase(IReferenceFormatCo nstants.VARIABLE_FORMAT)){ ((COBOLVariableFormatEventHandler) fVariableForm atEventHandler).setInsertModeFlag(super.isInInsertMode()); } } catch (NullPointerException e) { CBDTUiPlugin.logError(e); } return super.isInInsertMode(); } /** * Updates the status field with the current column position. * * @param category type of category */ protected void updateStatusField(String category) { try { if (ITextEditorActionConstants.STATUS_CATEGORY_INPUT_POS ITION.equals(category)) { IStatusField field = getStatusField(ITextEditorA ctionConstants.STATUS_CATEGORY_INPUT_POSITION); if (field != null) { field.setText(getCursorPosition()); } } else {

super.updateStatusField(category); } } catch (NullPointerException e) { CBDTUiPlugin.logError(e); } } /** * Gets the cursor position for the fixed format.(The cursor position fo r fixed/variable * format starts from 7th column) * * @return cursor position */ protected String getCursorPosition() { int column = 0; int line = -1; try { ISourceViewer svr = getSourceViewer(); StyledText styledText = svr.getTextWidget(); final int offset = svr.getVisibleRegion().getOffset(); final int caret = offset + styledText.getCaretOffset(); final IDocument document = svr.getDocument(); line = document.getLineOfOffset(caret); final int lineOffset = document.getLineOffset(line); final int tabWidth = styledText.getTabs(); int increment = 1; int adjust = 0; if (fRefFormat.equalsIgnoreCase(IReferenceFormatConstant s.FIXED_FORMAT)) { adjust = 6; } else if(fRefFormat.equalsIgnoreCase(IReferenceFormatCo nstants.VARIABLE_FORMAT)) { adjust = 6; } for (int i = lineOffset; i < caret; i++) { if (TAB == document.getChar(i)) { while ((column + increment + adjust) % t abWidth != 0) { increment++; } column += increment; increment = 1; } else { /* * Multi byte chars are increased by the ir bytes to * calculate the column numbers. */ char[] ch = new char[] {document.getChar (i)}; byte[] by = new String(ch).getBytes(); column += by.length; } } //Now add 6 with the column for the sequence number area if (fRefFormat.equalsIgnoreCase(IReferenceFormatConstant

s.FIXED_FORMAT)||(fRefFormat.equalsIgnoreCase(IReferenceFormatConstants.VARIABLE _FORMAT))) { column += 6; } return ((line + 1) + " : " + (column + 1)); //$NON-NLS-1 $ } catch (BadLocationException x) { CBDTUiPlugin.logError(x); return "??"; //$NON-NLS-1$ } catch (NullPointerException e) { CBDTUiPlugin.logError(e); return "??"; //$NON-NLS-1$ } } /** * Jumps to the next error according to the given direction. * @param forward true for next error and false for prev. error * @return void */ public void gotoError(boolean forward) { try { ISelectionProvider provider = getSelectionProvider(); if (fStatusLineClearer != null) { provider.removeSelectionChangedListener(fStatusL ineClearer); fStatusLineClearer = null; } ITextSelection s = (ITextSelection) provider.getSelectio n(); IMarker nextError = getNextError(s.getOffset(), forward) ; if (nextError != null) { gotoMarker(nextError); IWorkbenchPage page = getSite().getPage(); IViewPart view = view = page.findView( // IPageLayout.ID_TASK_LIST //"o rg.eclipse.ui.views.TaskList" IPageLayout.ID_PROBLEM_VIEW ); if (view instanceof TaskList) { StructuredSelection ss = new StructuredS election(nextError); ((TaskList) view).setSelection(ss, true) ; } fStatusLineMsg.setErrorMessageText(nextError.get Attribute(IMarker.MESSAGE, "")); //$NON-NLS-1$ fStatusLineClearer = new ISelectionChangedListen er() { public void selectionChanged(SelectionCh angedEvent event) { getSelectionProvider().removeSel ectionChangedListener(fStatusLineClearer); fStatusLineClearer = null; fStatusLineMsg.setErrorMessageTe

xt(""); //$NON-NLS-1$ } }; provider.addSelectionChangedListener(fStatusLine Clearer); } else { fStatusLineMsg.setErrorMessageText(""); //$NON-N LS-1$ } } catch (NullPointerException e) { CBDTUiPlugin.logError(e); } } /** * Returns the next error marker. * @param offset the offset * @param forward true for forward and false for backward * @return IMarket the next error marker */ private IMarker getNextError(int offset, boolean forward) { IMarker nextError = null; IDocument document = getDocumentProvider().getDocument(getEditor Input()); final int endOfDocument = document.getLength(); int distance = 0; IAnnotationModel model = getDocumentProvider().getAnnotationMode l(getEditorInput()); Iterator e = model.getAnnotationIterator(); while (e.hasNext()) { Annotation a = (Annotation) e.next(); if (a instanceof MarkerAnnotation) { MarkerAnnotation ma = (MarkerAnnotation) a; IMarker marker = ma.getMarker(); if (MarkerUtilities.isMarkerType(marker, IMarker .PROBLEM)) { Position p = model.getPosition(a); if (!p.includes(offset)) { int currentDistance = 0; if (forward) { currentDistance = p.getO ffset() - offset; if (currentDistance < 0) currentDistance = endOfDocument - offset + p.getOffset(); } else { currentDistance = offset - p.getOffset(); if (currentDistance < 0) currentDistance = offset + endOfDocument - p.getOffset(); } if (nextError == null || current Distance < distance) { distance = currentDistan ce; nextError = marker;

} } } } } return nextError; } /** * Adds the actions to the context menu . * @param menu the menu manager */ //This method is overridden to add the break point action in the //context menu protected void editorContextMenuAboutToShow(IMenuManager menu) { super.editorContextMenuAboutToShow(menu); menu.add(new Separator("group.debug")); //$NON-NLS-1$ addAction(menu, "group.debug", VARIABLEACTION_ID); //$NON-NLS-1$ addAction(menu, "group.debug", CHANGEEXECUTIONPOINT_ID); //$NONNLS-1$ addAction(menu, "group.debug", RUNTOLINE_ID); //$NON-NLS-1$ IAction action = getAction(VARIABLEACTION_ID); if (action != null && action instanceof IUpdate){ ((IUpdate)action).update(); } action = getAction(CHANGEEXECUTIONPOINT_ID); if (action != null && action instanceof IUpdate){ ((IUpdate)action).update(); } action = getAction(RUNTOLINE_ID); if (action != null && action instanceof IUpdate){ ((IUpdate)action).update(); } try { //Adding the Renumber action for Fixed and Variable form at boolean isReadOnly = isEditorInputReadOnly(); //Add renumber action only if the editor is writable if(false == isReadOnly) { if(fRefFormat.equalsIgnoreCase(IReferenceFormatC onstants.FIXED_FORMAT) ||(fRefFormat.equalsIgnoreCase(IReferenceFormatC onstants.VARIABLE_FORMAT))) { if(menu != null) { if(renumberAction != null) renumberAction.setEnable d(true); getAction(RENUMBER).setEnabled(t rue); menu.add(new Separator(RENUMBER) ); addAction(menu, RENUMBER); }

} } IContributionItem[] items = menu.getItems(); for (int i = 0; i < items.length; i++) { if (items[i].getId() != null) { if (ITextEditorActionConstants.GROUP_ADD .equals(items[i].getId())) { MenuManager bMenu = (MenuManager ) menu.findMenuUsingPath(items[i].getId()); // Added by zenil - Fix for bug if Apide00000759 if(bMenu!=null) { bMenu.add(new Separator( ITextEditorActionConstants.GROUP_ADD)); addAction(bMenu, ADD_BRE AKPOINT); } break; } } } } catch (NullPointerException e) { CBDTUiPlugin.logError(e); } } /** * Disposes all components after closing the editor. */ public void dispose() { try { //Reset the search markers to its original values //on close of the editor resetMarkers(fRefFormat, true); IWorkbenchPage page = CBDTUiPlugin.getActivePage(); if (page != null) { //update the structure view only incase of edito r is dirty and called for close. //this is to avoid unnecessary updation to the s tructure view if(true == isDirty()) { IViewPart fPart = page.findView(COBOLEdi torMessages.getString("StructuredView.label")); //$NON-NLS-1$ if (fPart != null) { IFile file = ((IFileEditorInput) getEditorInput()).getFile(); if (file != null) { //remove the model from the model registry CBDTUiPlugin.getDefault( ).getCOBOLParserRegistry().remove(file); ViewsTreeModel.getInstan ce().refreshStructuresViewAndUpdateModel(file); } } if (fPart != null) { StructuresView structuresView =

(StructuresView) fPart; structuresView.refresh(); } } } //remove the listener added from this editor to the styl ed text if (getSourceViewer().getTextWidget() != null) { getSourceViewer().getTextWidget().removeVerifyLi stener(fFixedFormatEventHandler); getSourceViewer().getTextWidget().removeVerifyKe yListener(fFixedFormatEventHandler); fFixedFormatEventHandler.handleDispose(); fFixedFormatEventHandler = null; getSourceViewer().getTextWidget().removeVerifyLi stener(fVariableFormatEventHandler); getSourceViewer().getTextWidget().removeVerifyKe yListener(fVariableFormatEventHandler); fVariableFormatEventHandler.handleDispose(); fVariableFormatEventHandler = null; } //remove the view port list if(fViewportListener != null) { getSourceViewer().removeViewportListener(fViewpo rtListener); getSourceViewer().removeTextListener(fViewportLi stener); fViewportListener = null; } //remove the rulers if (fHRuler != null) { fHRuler.handleDispose(); fHRuler.dispose(); fHRuler = null; } if (fTextFactory != null) { fTextFactory.dispose(); fTextFactory = null; } if (styledTextPrinter != null) { styledTextPrinter.dispose(); styledTextPrinter = null; } if (fStatusLineMsg != null) { fStatusLineMsg.handleDispose(); fStatusLineMsg = null; } //remove the element processer if(fAnalyzer != null) { fAnalyzer.dispose(); fAnalyzer = null; }

if(fPage != null) { fPage.dispose(); fPage = null; } if (fFixedFormatSourceViewerConfiguration != null) { fFixedFormatSourceViewerConfiguration.handleDisp ose(); fFixedFormatSourceViewerConfiguration = null; } if(fVariableFormatSourceViewerConfiguration != null) { fVariableFormatSourceViewerConfiguration.handleD ispose(); fVariableFormatSourceViewerConfiguration = null; } if (fFreeFormatSourceViewerConfiguration != null) { fFreeFormatSourceViewerConfiguration.handleDispo se(); fFreeFormatSourceViewerConfiguration = null; } fStatusLineClearer = null; fRunnable = null; //clear the actions created if(fAddVariableAction != null) { fAddVariableAction.setEditor(null); fAddVariableAction = null; } if(fChangeExecutionpointAction != null) { fChangeExecutionpointAction.setEditor(null); fChangeExecutionpointAction = null; } if(fRuntoLineAction != null) { fRuntoLineAction.setEditor(null); fRuntoLineAction = null; } if(fCOBOLBreakpointActionPopup != null) { fCOBOLBreakpointActionPopup.setEditor(null); fCOBOLBreakpointActionPopup = null; } if(fCOBOLBreakpointRulerAction != null) { fCOBOLBreakpointRulerAction = null; } if(fCOBOLBreakpointRulerAction != null) { ((COBOLBreakpointRulerAction)fCOBOLBreakpointRul erAction).dispose(); fCOBOLBreakpointRulerAction = null; } if(renumberAction != null) { renumberAction.setEditor(null); renumberAction = null; } if(fPrintAction != null) { fPrintAction.cleanUp(); fPrintAction = null;

} if(fContentAssistAction != null) { fContentAssistAction.setEditor(null); fContentAssistAction = null; } if(fGotoLineAction != null) { fGotoLineAction.setEditor(null); fGotoLineAction = null; } // // // // // // // // // // // // // // if (this.fVRuler != null){ this.fVRuler = null; } if (this.fRulerLayout != null ){ this.fRulerLayout = null; } if (this.fMainCanvas != null){ this.fMainCanvas.dispose(); this.fMainCanvas = null; } if(this.fParentComp != null) { this.fParentComp.dispose(); this.fParentComp = null; } if (this.fSequenceAreaText != null){ this.fSequenceAreaText.dispose(); this.fSequenceAreaText = null; } if (this.fCblSequenceNumberArea != null){ this.fCblSequenceNumberArea.handleDispose(); this.fCblSequenceNumberArea = null; } if (this.fSeqFormatDocumentProvider != null ){ this.fSeqFormatDocumentProvider.removeDocumentCh angedListener(); this.fSeqFormatDocumentProvider.disconnect(this) ; } if (this.fFreeFormatDocumentProvider != null ){ this.fFreeFormatDocumentProvider.disconnect(this ); } if (fFontPropertyChangeListener != null) { JFaceResources.getFontRegistry().removeListener( fFontPropertyChangeListener); fFontPropertyChangeListener= null; } if (fEncodingSupport != null) { fEncodingSupport.dispose(); fEncodingSupport= null;

} //if (fSourceViewerDecorationSupport != null) { // fSourceViewerDecorationSupport.dispose(); // fSourceViewerDecorationSupport= null; //} //fAnnotationPreferences= null; //fAnnotationAccess= null; super.dispose(); } catch (NullPointerException e) { CBDTUiPlugin.logError(e); } } /** * Resetting the format after Apply button clicked on the editor prefere nce page. * This method is called from the performOK() of the cobol editor prefer ence * page class * * @param format the reference format * @param needToSave whether to save the file or not */ public void resetFormat(String newformat, boolean needToSave) { try { if (needToSave && isDirty()) { doSave(null); } if (!newformat.equals(fRefFormat)) { IEditorInput input = getEditorInput(); //reset all the other markers resetMarkers(newformat, false); //reset the search markers resetMarkers(newformat, true); doSetInput(input); //set the editor on top getSourceViewer().getTextWidget().setTopPixel(0) ; //set the sequence number area on top incase of Fixed/Variable format if (!newformat.equalsIgnoreCase(IReferenceFormat Constants.FREE_FORMAT)) { fCblSequenceNumberArea.getSequenceNumber AreaText().setTopPixel(0); } reLayout(); //update the outline view after changing the for mat. if (fPage != null) { fPage.update(); } //update structure and dependency view ViewsTreeModel.getInstance().refreshStructuresVi ew(); IWorkbenchWindow windows[] = CBDTUiPlugin.getDef ault().getWorkbench().getWorkbenchWindows(); if (windows.length > 0) {

Display.getDefault().asyncExec(getRunnab leForViews()); } //update the status field updateStatusField(ITextEditorActionConstants.STA TUS_CATEGORY_INPUT_POSITION); //update all the undo manager with the latest fo rmat COBOLAbstractUndoManager fixedUndoMngr = (COBOLA bstractUndoManager)fFixedFormatSourceViewerConfiguration.getUndoManager(getSourc eViewer()); fixedUndoMngr.setCurrentFormat(newformat); COBOLAbstractUndoManager freeUndoMngr = (COBOLAb stractUndoManager)fFreeFormatSourceViewerConfiguration.getUndoManager(getSourceV iewer()); freeUndoMngr.setCurrentFormat(newformat); COBOLAbstractUndoManager varUndoMngr = (COBOLAbs tractUndoManager)fVariableFormatSourceViewerConfiguration.getUndoManager(getSour ceViewer()); varUndoMngr.setCurrentFormat(newformat); } } catch (CoreException e) { CBDTUiPlugin.logError(e); } catch (Exception e) { CBDTUiPlugin.logError(e); } } /** * This method reset the markers based on the changed reference format. * @param newformat * @param includeSearch */ private void resetMarkers(String newformat, boolean includeSearch) { // check the editor input, if the input is not File editor input then return simply. //Note: This change was made due to bug Fix for IKS-SE262 //When the file is opened from the CVS histry then it will throu gh exception IEditorInput input = getEditorInput(); if(false == input instanceof IFileEditorInput) return; //Reset all the markers based on the format IFileEditorInput fileInput = (IFileEditorInput) input; IPath path = fileInput.getFile().getFullPath(); IWorkspace wr = CBDTUiPlugin.getWorkspace(); if (wr != null && wr instanceof Workspace) { Workspace workspace = (Workspace) wr; ResourceInfo ri = workspace.getResourceInfo(path, false, false); if (ri != null) { MarkerSet markers = ri.getMarkers(); if (markers != null) { IMarkerSetElement[] matching = markers.e lements(); if (includeSearch) { resetSearchMarkers(matching); } else { resetTextMarkers(matching, newfo rmat); }

} } } } /** * Layout for editor components. */ private class RulerLayout extends Layout { protected int fGap; protected RulerLayout(int gap) { fGap = gap; } protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) { Control[] children = composite.getChildren(); Point s = children[children.length - 1].computeSize(SWT. DEFAULT, SWT.DEFAULT, flushCache); IVerticalRuler verticalRuler = getVerticalRuler(); if (verticalRuler != null /*&& fIsVerticalRulerVisible*/ ) s.x += verticalRuler.getWidth() + fGap; return s; } protected void layout(Composite composite, boolean flushCache) { Rectangle clArea = composite.getClientArea(); IVerticalRuler verticalRuler = getVerticalRuler(); if (verticalRuler != null /*&& fIsVerticalRulerVisible*/ ) { Rectangle trim= getSourceViewer().getTextWidget( ).computeTrim(0, 0, 0, 0); int scrollbarHeight= trim.height; int verticalRulerWidth= verticalRuler.getWidth() ; int overviewRulerWidth= 0; if (fOverviewRuler != null && isOverviewRulerVis ible()) { overviewRulerWidth= fOverviewRuler.getWi dth(); fOverviewRuler.getControl().setBounds( clArea.width - overviewR ulerWidth -1, scrollbarHeight, overviewRulerWidth, clAr ea.height - 3*scrollbarHeight); fOverviewRuler.getHeaderControl().setBou nds( clArea.width - overviewR ulerWidth -1, 0, overviewRulerWidth, scro llbarHeight); } int sequenceAreaWidth = getSequenceAreaWidth();

//int adjust = 0; //This is for fixing the breakpoint marker posit ioning //wrt sequence number area and editor //if (!SWT.getPlatform().equalsIgnoreCase(PLATFO RM)) { // adjust = -4; //} else { // adjust = -2; //} //Draw the vertical ruler verticalRuler.getControl().setBounds( 0, 0 + /*adjust*/0, verticalRule rWidth, clArea.height - scrollbarHeight - /*adjust*/0); //adjust = 0; //This is for the difference in height between t he //seq area and editor in Linux. //if (!SWT.getPlatform().equalsIgnoreCase(PLATFO RM)) { // //} . if (fRefFormat.equalsIgnoreCase(IReferenceFormat Constants.FIXED_FORMAT) || (fRefFormat.equalsIgnoreCase(IReferenceFormat Constants.VARIABLE_FORMAT))) { fSequenceAreaText.setBounds( verticalRulerWidth + fGa p, /*adjust*/0, sequenceAreaWidth, clAre a.height - scrollbarHeight - /*adjust*/0); } try { if(fHRulerSpacer!=null && fHRulerSpacer.getDisplay()!=null) { GridData lGridData = new GridDat a(); lGridData.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; lGridData.widthHint = verticalRu lerWidth + fGap; fHRulerSpacer.setLayoutData(lGri dData); fHRulerSpacer.getParent().layout (); } } catch (Exception e) { } catch (Error e) { } try { if(fHRuler!=null adjust = 3;

//For Fixed format files, draw the sequence area

&& fHRuler.getDisplay()!=null) { fHRuler.redraw(); } } catch (Exception e) { } catch (Error e) { } //Draw the editor area getSourceViewer().getTextWidget().setBounds( verticalRulerWidth + sequenceAre aWidth + fGap, 0, clArea.width - verticalRulerWidt h - sequenceAreaWidth - overviewRulerWidth - 2*fGap, clArea.height); } else { getSourceViewer().getTextWidget().setBounds(0, 0 , clArea.width, clArea.height); } } }; /** * Returns the sequence area width based on the current font of the edit or * @return the sequence area width. */ public int getSequenceAreaWidth() { int sequenceAreaWidth = 0; if (fRefFormat.equalsIgnoreCase(IReferenceFormatConstants.FIXED_ FORMAT) || fRefFormat.equalsIgnoreCase(IReferenceFormatConstants.VARIABL E_FORMAT)) { GC gc = new GC(getSourceViewer().getTextWidget()); FontMetrics fm = gc.getFontMetrics(); sequenceAreaWidth = fm.getAverageCharWidth() * /*7*/6; gc.dispose(); } else { sequenceAreaWidth = 0; } return sequenceAreaWidth; } /* * Listener for cursor movements and view port changes in the editor. * Based on this events the sequence area styled text is drawn. */ private class InternalViewPortListener implements IViewportListener, ITe xtListener { /* * @see IViewportListener#viewportChanged */ public void viewportChanged(int verticalPosition) { //equalizing the sequence area with the source area StyledText editorStyledText = getSourceViewer().getTextW idget(); if (editorStyledText != null) { if (fSequenceAreaText != null) {

if (fRefFormat.equals(IReferenceFormatCo nstants.FIXED_FORMAT) || fRefFormat.equals(IReferenceFormatCon stants.VARIABLE_FORMAT)) { fSequenceAreaText.setTopPixel(ed itorStyledText.getTopPixel()); if (fSequenceAreaText.getTopPixe l() != editorStyledText.getTopPixel()) { editorStyledText.setTopP ixel(fSequenceAreaText.getTopPixel()); } } } } } /* * @see ITextListener#textChanged */ public void textChanged(TextEvent e) { StyledText editorStyledText = getSourceViewer().getTextW idget(); if (editorStyledText != null) { if (fSequenceAreaText != null) { if (fRefFormat.equals(IReferenceFormatCo nstants.FIXED_FORMAT) || fRefFormat.equals(IReferenceFormatCon stants.VARIABLE_FORMAT) ) { fSequenceAreaText.setTopPixel(ge tSourceViewer().getTextWidget().getTopPixel()); } } } } } /** * Resets the markers based on Fixed/Free/variable format * * @param markers list of all the markers * @param format the latest format * @return void */ private void resetTextMarkers(IMarkerSetElement[] markers, String newfor mat) { if (markers.length == 0) return; int number = IReferenceFormatConstants.NUMBER_LENGTH; for (int i = 0; i < markers.length; i++) { MarkerInfo markerInfo = (MarkerInfo) markers[i]; String type = markerInfo.getType(); if (type.equals(SearchUI.SEARCH_MARKER)) continue; Object charStart = ((MarkerInfo) markers[i]).getAttribut e(IMarker.CHAR_START); final Object line = ((MarkerInfo) markers[i]).getAttribu te(IMarker.LINE_NUMBER); Object charEnd = ((MarkerInfo) markers[i]).getAttribute(

IMarker.CHAR_END); int currentLine = ((Integer) line).intValue(); String startFormat = (String) ((MarkerInfo) markers[i]). getAttribute(START_FORMAT); if (startFormat == null) { startFormat = fRefFormat;//newformat.equalsIgnor eCase(IReferenceFormatConstants.FIXED_FORMAT) ? IReferenceFormatConstants.FREE_F ORMAT : IReferenceFormatConstants.FIXED_FORMAT; ((MarkerInfo) markers[i]).setAttribute(START_FOR MAT, startFormat); } // Hiten - 2003/09/22 To shift the markers based on form at. int endPos = 0; int startPos = 0; try { endPos = getSourceViewer().getDocument().getLine Length(currentLine-1); startPos = getSourceViewer().getDocument().getLi neOffset(currentLine-1); endPos = startPos + endPos; } catch (BadLocationException e) { continue; } if ( startFormat.equals(IReferenceFormatConstants.FREE_F ORMAT) && (newformat.equalsIgnoreCase(IReferenceFormatCons tants.FIXED_FORMAT) || newformat.equalsIgnoreCase(IReferenceFormatConst ants.VARIABLE_FORMAT))){ endPos = endPos - ((currentLine) * number); startPos = startPos - ((currentLine - 1) * numbe r); /* * End position for every line should minus the line feed(New line chars) * But for the last line should not minus the li ne feed as it will not * have any new line chars. * Note: This is bug fix for breakpoints not pla cing properly if the format changes * from one to other */ if ( getSourceViewer().getDocument().getNumberOf Lines() != currentLine ){ endPos = endPos - 2; } } else if ( newformat.equals(IReferenceFormatConstants.F REE_FORMAT) && (startFormat.equalsIgnoreCase(IReferenceFormatCo nstants.FIXED_FORMAT) || startFormat.equalsIgnoreCase(IReferenceFormatCon stants.VARIABLE_FORMAT))){ endPos = endPos + ((currentLine) * number); startPos = startPos + ((currentLine - 1) * numbe r); /* * End position for every line should minus the line feed(New line chars).

* But for the last line should not minus the li ne feed as it will not * have any new line chars. * Note: This is bug fix for breakpoints not pla cing properly if the format changes * from one to other */ if ( getSourceViewer().getDocument().getNumberOf Lines() != currentLine ){ endPos = endPos - 2; } } charStart = new Integer(startPos); ((MarkerInfo) markers[i]).setAttribute(IMarker.CHAR_STAR T, charStart); charEnd = new Integer(endPos); ((MarkerInfo) markers[i]).setAttribute(IMarker.CHAR_END, charEnd); ((MarkerInfo) markers[i]).setAttribute(START_FORMAT, new format); } } /** * Resets the search markers based on Fixed/Free/Variable format * * @param markers list of all the markers * @param path of the current file * @param format the latest format * @return void */ private void resetSearchMarkers(IMarkerSetElement[] markers) { if (markers.length == 0) return; IAnnotationModel m = getDocumentProvider().getAnnotationModel(ge tEditorInput()); final COBOLMarkerAnnotationModel c = (COBOLMarkerAnnotationModel ) m; if (c == null) return; boolean flag = c.getIsMarkerPropertyChanged(); for (int i = 0; i < markers.length; i++) { final MarkerInfo markerInfo = (MarkerInfo) markers[i]; Object currentLine = markerInfo.getAttribute(IMarker.LIN E_NUMBER); if ( currentLine == null ) return; int line = ((Integer) currentLine).intValue(); String type = markerInfo.getType(); int number = IReferenceFormatConstants.NUMBER_LENGTH; if (type.equals(SearchUI.SEARCH_MARKER)) { if (flag) { Object charStart = markerInfo.getAttribu te(IMarker.CHAR_START); Object charEnd = markerInfo.getAttribute (IMarker.CHAR_END); int start = ((Integer) charStart).intVal ue();

start += line * number; charStart = new Integer(start); markerInfo.setAttribute(IMarker.CHAR_STA RT, charStart); int end = ((Integer) charEnd).intValue() ; end += line * number; charEnd = new Integer(end); markerInfo.setAttribute(IMarker.CHAR_END , charEnd); } } } } /** * The following is posts a an asynchronous runnable to the UI thread * for updating the sequence area styled text when more than * one active window is opened.This method is called * from verifykey listener when any change to the * sequence area styled text occurs. This is also * called when renumbering occurs. * * @return runnable */ public Runnable getRunnable() { if (fRunnable == null) { fRunnable = new Runnable() { public void run() { boolean found = false; IWorkbenchWindow windows[] = getEditorSi te().getWorkbenchWindow().getWorkbench().getWorkbenchWindows(); IWorkbenchWindow activeWindow = getEdito rSite().getWorkbenchWindow(); for (int i = 0; i < windows.length; i++) { if (activeWindow == windows[i]) continue; IEditorReference editorPart[] = windows[i].getActivePage().getEditorReferences(); found = false; IEditorPart part = null; for (int j = 0; j < editorPart.l ength; j++) { part = editorPart[j].get Editor(false); if (part instanceof COBO LEditor) { COBOLEditor edit or = (COBOLEditor) part; if (getEditorInp ut().equals(editor.getEditorInput())) { found = true; StringBu ffer tempBuffer = editor.getSequenceNumberArea().getSequenceNumbersBuffer(); if (temp Buffer != null) {

editor.getSequenceNumberArea().setSequenceNumbersControl(tempBuffer); } editor.g etSequenceNumberArea().setPreservedText(fCblSequenceNumberArea.getPreservedText( )); editor.g etSequenceNumberArea().setPatternFlag(fCblSequenceNumberArea.isPatternB()); } } if (found) break; } } } }; //End of runnable } return fRunnable; } /** * This method refreshes all the Dependency and Structures Views of the different windows */ public Runnable getRunnableForViews() { try { if (fRunnable == null) { fRunnable = new Runnable() { public void run() { IWorkbenchWindow windows[] = CBD TUiPlugin.getDefault().getWorkbench().getWorkbenchWindows(); for (int i = 0; i < windows.leng th; i++) { IViewReference viewRefer ences[] = windows[i].getActivePage().getViewReferences(); IViewPart viewPart = nul l; for (int j = 0; j < view References.length; j++) { viewPart = viewR eferences[j].getView(false); if (viewPart ins tanceof StructuresView) { Structur esView sView = (StructuresView) viewPart; sView.re fresh(); } } } } }; //End of runnable } return fRunnable; } catch (Exception e) { CBDTUiPlugin.logError(e); return null; } }

/** * This method inserts the template into the editor. */ public void pasteIntoEditor(String fTemplateStr) { try { int fCaret =0; StyledText styledText = getCurrentSourceViewer().getText Widget(); IDocument document = getCurrentSourceViewer().getDocumen t(); final int offset= getCurrentSourceViewer().getVisibleReg ion().getOffset(); fCaret= offset + getCurrentSourceViewer().getTextWidget( ).getCaretOffset(); int lineLimit = 0; int noOfLines = 0; String strDelimiter = styledText.getLineDelimiter();//De limiter int startOffset = document.getLineOffset(document.getLin eOfOffset(fCaret)); if(startOffset != fCaret) { fTemplateStr = findEndOfWhiteSpaceString(documen t,styledText,startOffset,fCaret,new StringBuffer(fTemplateStr)); } String strFinal = addDelimiter(strDelimiter, fTemplateSt r); //finding the no of lines selected while (true) { lineLimit = fTemplateStr.indexOf(LINE_DELIMITER, lineLimit); if (lineLimit == -1) { break; } //next time start should be after new line strin g lineLimit += 1; noOfLines++; } if(styledText != null && strFinal != null && !strFinal.e quals("")){ Point point = styledText.getSelection(); int length = 0; if(point.x != point.y) { fCaret = point.x; length = point.y - point.x; } styledText.replaceTextRange(fCaret,length,strFin al); //set the focus to the current editor setFocus(); //set the current cursor position at the end of the pasted string styledText.setCaretOffset(fCaret+strFinal.length ()); fTemplateStr = ""; strFinal = ""; }

} catch(NullPointerException e){ CBDTUiPlugin.logError(e); }catch(IndexOutOfBoundsException e) { CBDTUiPlugin.logError(e); }catch(Exception e){ CBDTUiPlugin.logError(e); } } /** * This method adds the delimiters into the template string at the end * of the line if the template string is multi line string. * * @param strDelimiter the delimiter to be added at end of the line * @return Template string with delimiter added at the end of line */ public String addDelimiter(String strDelimiter, String fTemplateStr) { int index1 =0; StringBuffer strTmpPattern = new StringBuffer(fTemplateStr); index1 = strTmpPattern.toString().indexOf(strDelimiter,index1); if(index1 != -1) { return strTmpPattern.toString(); } else { index1 = 0; } while(true) { index1 = strTmpPattern.toString().indexOf(LINE_DELIMITER ,index1); if(index1 != -1){ strTmpPattern.deleteCharAt(index1); strTmpPattern.insert(index1,strDelimiter ); index1 +=2; } else { break; } } return strTmpPattern.toString(); } /** * Finds end of white space * * @param document the document * @param sText the text widget * @param offset start of the line * @param end current cursor position * @param addString the string buffer to be inserted in the editor * * @return String * @throws BadLocationException */ public String findEndOfWhiteSpaceString(IDocument document,StyledText sT ext, int offset, int end,StringBuffer addString) throws BadLocationException { int start = 0; String spaceStr = "";

try { start = offset; while (start < end) { char c= document.getChar(start); if (c != ' ' && c != '\t') { break; } start++; } if(start != offset) { spaceStr = document.get(offset,start-offset); int index = 0; while(index != -1) { index = addString.toString().indexOf(LIN E_DELIMITER,index); if(index == -1) { break; } index ++; addString.insert(index,spaceStr); } } } catch(Exception e) { CBDTUiPlugin.logError(e); } return addString.toString(); } /** * Returns the element analyzer associated with this editor. * @return COBOLElementAnalyzer */ public COBOLElementAnalyzer getElementAnalyzer() { return fAnalyzer; } /** * Sets the open file path after retrieving the editor input. */ private void setOpenFilePath(){ IEditorInput editorInput = getEditorInput(); if(editorInput instanceof RemoteFileEditorInput){ fOpenFilePath = ((RemoteFileEditorInput)editorInput).get File().getFullPath().toString(); }else if(editorInput instanceof IStorageEditorInput) { try { fOpenFilePath = ((IStorageEditorInput)editorInpu t).getStorage().getFullPath().toString(); } catch (CoreException e) { CBDTUiPlugin.logError(e); } } else{ fOpenFilePath = ((FileEditorInput) getEditorInput()).get File().getFullPath().toString(); } }

/** * @see org.eclipse.ui.texteditor.ITextEditor#selectAndReveal(int, int) */ public void selectAndReveal(int offset, int length) { super.selectAndReveal(offset, length); //once the text is selected update the Vertical Ruler and //Sequence number area for Fixed and Variable formats if(false == fRefFormat.equals(IReferenceFormatConstants.FREE_FOR MAT)) { int topPixel = getSourceViewer().getTextWidget().getTopP ixel(); //set the top pixels to the sequence number area fCblSequenceNumberArea.getSequenceNumberAreaText().setTo pPixel(topPixel); //update the ruler /*fVRuler*/getVerticalRuler().update(); } } /* (non-Javadoc) * @see org.eclipse.ui.part.WorkbenchPart#setTitleImage(org.eclipse.swt. graphics.Image) */ public void setTitleImage(Image arg0) { /** * Sets the title image of the opened editors.If there there is problem marker * associtated with the editor then title image need to be set with this otherwise * cobol source file icon will be set. */ Image fileIcon = null; if ( (fileIcon = getProblemMarker()) != null){ arg0 = fileIcon; } super.setTitleImage(arg0); } /** * Gets the PROBLEM OR WARNING marker if it is associated associated * with the file. * @return Image, the problem marker image associated with the file. */ private Image getProblemMarker(){ if (getEditorInput() instanceof IFileEditorInput){ IFile file = ((IFileEditorInput)getEditorInput()).getFil e(); //IProject will be null for External folder so do a chec k before getting the name IProject project = file.getProject(); String projectName; if(project != null){ projectName = project.getName(); }else{ projectName = file.getName(); } String location = file.getFullPath().toString(); if (IPath.SEPARATOR == location.charAt(0)){ location = location.substring(1); }

TreeElement projectNode = ViewsTreeModel.getInstance().g etProjectNode(projectName); if (projectNode != null){ TreeElement sourceFolderNode = projectNode.getCh ildFromType(IViewConstants.SOURCE_FOLDER_NAME); TreeElement sourceFile = null; if (sourceFolderNode != null && BuildUtil.isCobolFileExtn(file.getName()) && (sourceFile = sourceFolderNode.getChildFromLo cation(location)) != null){ if( IMarker.SEVERITY_ERROR == sourceFile .getMarker()){ // Return the PROBLEM marker ima ge return COBOLPluginImages.get(COB OLPluginImages.IMG_PROBLEM_SOURCE_FILE); }else if(IMarker.SEVERITY_WARNING == sou rceFile.getMarker()){ // Return the WARNING marker ima ge return COBOLPluginImages.get(COB OLPluginImages.IMG_WARNING_SOURCE_FILE); } } } } return null; } /** * Internal property change listener for handling COBOLEditor font chang es. * @since 2.1 */ class FontPropertyChangeListener implements IPropertyChangeListener { /* * @see IPropertyChangeListener#propertyChange(org.eclipse.jface .util.PropertyChangeEvent) */ public void propertyChange(PropertyChangeEvent event) { FontData data= null; Font font = null; IPreferenceStore store = getPreferenceStore(); if (store.contains(JFaceResources.TEXT_FONT)){ data = PreferenceConverter.getFontData(store, JF aceResources.TEXT_FONT); if ( data != null){ font = new Font(getSourceViewer().getTex tWidget().getDisplay(), data); } if (font == null){ font= JFaceResources.getTextFont(); } setFont(font); }

} } /** * @see org.eclipse.ui.texteditor.AbstractTextEditor#updatePropertyDepen dentActions() */ protected void updatePropertyDependentActions() { super.updatePropertyDependentActions(); //{{ V7.0 if (fEncodingSupport != null) fEncodingSupport.reset(); //}} V7.0 } // // // // // // // // ; // /** * Creates the annotation access for this editor. * * @return the created annotation access * @since 2.1 */ protected IAnnotationAccess createAnnotationAccess() { return new DefaultMarkerAnnotationAccess(fAnnotationPreferences) }

// /** // * Configures the decoration support for this editor's the source viewer . // * // * @since 2.1 // */ // protected void configureSourceViewerDecorationSupport() { // // Iterator e= fAnnotationPreferences.getAnnotationPreferences().it erator(); // while (e.hasNext()) // fSourceViewerDecorationSupport.setAnnotationPreference(( AnnotationPreference) e.next()); // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKey s(DefaultMarkerAnnotationAccess.UNKNOWN, UNKNOWN_INDICATION_COLOR, UNKNOWN_INDIC ATION, UNKNOWN_INDICATION_IN_OVERVIEW_RULER, 0); // // fSourceViewerDecorationSupport.setCursorLinePainterPreferenceKey s(CURRENT_LINE, CURRENT_LINE_COLOR); // fSourceViewerDecorationSupport.setMarginPainterPreferenceKeys(PR INT_MARGIN, PRINT_MARGIN_COLOR, PRINT_MARGIN_COLUMN); // fSourceViewerDecorationSupport.setSymbolicFontName(getFontProper tyPreferenceKey()); // } // /** // * @since 2.1 // */ // private void showOverviewRuler() { // if (getSourceViewer() instanceof ISourceViewerExtension) { // ((ISourceViewerExtension) getSourceViewer()).showAnnotat ionsOverview(true); // fSourceViewerDecorationSupport.updateOverviewDecorations

(); // //

} }

// /** // * Hides the overview ruler. // * // * @since 2.1 // */ // private void hideOverviewRuler() { // if (getSourceViewer() instanceof ISourceViewerExtension) { // fSourceViewerDecorationSupport.hideAnnotationOverview(); // ((ISourceViewerExtension) getSourceViewer()).showAnnotat ionsOverview(false); // } // } /** * Tells whether the overview ruler is visible. * * @since 2.1 */ /* (??Javadoc) * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#isOverview RulerVisible() */ /*protected*/public boolean isOverviewRulerVisible() { return super.isOverviewRulerVisible(); } /* (??Javadoc) * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#getOvervie wRuler() */ /*protected*/public IOverviewRuler getOverviewRuler() { return super.getOverviewRuler(); } }

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy