Update of /cvsroot/squirrel-sql/sql12/plugins/syntax/src/net/sourceforge/squirrel_sql/plugins/syntax/oster
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32268/plugins/syntax/src/net/sourceforge/squirrel_sql/plugins/syntax/oster
Modified Files:
OsterTextControl.java
Log Message:
Gerd Wagners patch - use new parser in SQSC, show parse errors in tooltip, fix deadlock.
Index: OsterTextControl.java
===================================================================
RCS file: /cvsroot/squirrel-sql/sql12/plugins/syntax/src/net/sourceforge/squirrel_sql/plugins/syntax/oster/OsterTextControl.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** OsterTextControl.java 3 Feb 2004 10:52:24 -0000 1.8
--- OsterTextControl.java 4 Apr 2004 10:37:58 -0000 1.9
***************
*** 47,51 ****
import com.Ostermiller.Syntax.Lexer.SQLLexer;
import com.Ostermiller.Syntax.Lexer.Token;
!
import net.sourceforge.squirrel_sql.fw.gui.FontInfo;
import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
--- 47,55 ----
import com.Ostermiller.Syntax.Lexer.SQLLexer;
import com.Ostermiller.Syntax.Lexer.Token;
! import net.sourceforge.squirrel_sql.client.session.ISession;
! import net.sourceforge.squirrel_sql.client.session.SQLTokenListener;
! import net.sourceforge.squirrel_sql.client.session.SchemaInfo;
! import net.sourceforge.squirrel_sql.client.session.parser.ParserEventsAdapter;
! import net.sourceforge.squirrel_sql.client.session.parser.kernel.ErrorInfo;
import net.sourceforge.squirrel_sql.fw.gui.FontInfo;
import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
***************
*** 60,64 ****
import net.sourceforge.squirrel_sql.plugins.syntax.SyntaxStyle;
! class OsterTextControl extends JTextPane
{
/** Logger for this class. */
--- 64,77 ----
import net.sourceforge.squirrel_sql.plugins.syntax.SyntaxStyle;
! import javax.swing.*;
! import javax.swing.plaf.ComponentUI;
! import javax.swing.text.*;
! import java.awt.*;
! import java.awt.event.MouseEvent;
! import java.io.IOException;
! import java.io.Reader;
! import java.util.*;
!
! public class OsterTextControl extends JTextPane
{
/** Logger for this class. */
***************
*** 109,112 ****
--- 122,126 ----
private Vector _sqlTokenListeners = new Vector();
+ private Vector _currentErrorInfos = new Vector();
OsterTextControl(ISession session, SyntaxPreferences prefs)
***************
*** 133,137 ****
--- 147,187 ----
initDocument();
+ setToolTipText("Just to make getToolTiptext() to be called");
+
updateFromPreferences();
+
+ session.getParserEventsProcessor().addParserEventsListener(new ParserEventsAdapter()
+ {
+ public void errorsFound(ErrorInfo[] errorInfos)
+ {
+ onErrorsFound(errorInfos);
+ }
+ });
+ }
+
+ private void onErrorsFound(ErrorInfo[] errorInfos)
+ {
+ if(_currentErrorInfos.size() == errorInfos.length)
+ {
+ boolean errorsChanged = false;
+ for (int i = 0; i < errorInfos.length; i++)
+ {
+ if(false == errorInfos[i].equals(_currentErrorInfos.get(i)))
+ {
+ errorsChanged = true;
+ break;
+ }
+ }
+
+ if(false == errorsChanged)
+ {
+ return;
+ }
+
+ }
+
+ _currentErrorInfos.clear();
+ _currentErrorInfos.addAll(Arrays.asList(errorInfos));
+ colorAll();
}
***************
*** 214,218 ****
public void colorAll()
{
! color(0, document.getLength());
}
--- 264,268 ----
public void colorAll()
{
! color(0, document.getLength(), false);
}
***************
*** 227,233 ****
* at the starting point.
*/
! public void color(int position, int adjustment)
{
! colorer.color(position, adjustment);
}
--- 277,283 ----
* at the starting point.
*/
! public void color(int position, int adjustment, boolean fireTableOrViewFoundEvent)
{
! colorer.color(position, adjustment, fireTableOrViewFoundEvent);
}
***************
*** 467,474 ****
public int position;
public int adjustment;
! public RecolorEvent(int position, int adjustment)
{
this.position = position;
this.adjustment = adjustment;
}
}
--- 517,527 ----
public int position;
public int adjustment;
! private boolean fireTableOrViewFoundEvent;
!
! public RecolorEvent(int position, int adjustment, boolean fireTableOrViewFoundEvent)
{
this.position = position;
this.adjustment = adjustment;
+ this.fireTableOrViewFoundEvent = fireTableOrViewFoundEvent;
}
}
***************
*** 504,508 ****
* This method should be done inside a doclock.
*/
! public void color(int position, int adjustment)
{
// figure out if this adjustment effects the current run.
--- 557,561 ----
* This method should be done inside a doclock.
*/
! public void color(int position, int adjustment, boolean fireTableOrViewFoundEvent)
{
// figure out if this adjustment effects the current run.
***************
*** 522,526 ****
synchronized (lock)
{
! v.add(new RecolorEvent(position, adjustment));
if (asleep)
{
--- 575,579 ----
synchronized (lock)
{
! v.add(new RecolorEvent(position, adjustment, fireTableOrViewFoundEvent));
if (asleep)
{
***************
*** 539,542 ****
--- 592,596 ----
int position = -1;
int adjustment = 0;
+ boolean fireTableOrViewFoundEvent = true;
// if we just finish, we can't go to sleep until we
// ensure there is nothing else for us to do.
***************
*** 553,556 ****
--- 607,611 ----
position = re.position;
adjustment = re.adjustment;
+ fireTableOrViewFoundEvent = re.fireTableOrViewFoundEvent;
}
else
***************
*** 559,562 ****
--- 614,619 ----
position = -1;
adjustment = 0;
+ fireTableOrViewFoundEvent = false;
+
}
}
***************
*** 667,672 ****
--- 724,732 ----
{
type = IConstants.IStyleNames.TABLE;
+ if(fireTableOrViewFoundEvent)
+ {
fireTableOrViewFound(t.getContents());
}
+ }
else if (si.isColumn(data))
{
***************
*** 683,687 ****
}
! document.setCharacterAttributes(
t.getCharBegin() + change,
t.getCharEnd() - t.getCharBegin(),
--- 743,752 ----
}
! // document.setCharacterAttributes(
! // t.getCharBegin() + change,
! // t.getCharEnd() - t.getCharBegin(),
! // getMyStyle(type), true);
!
! setCharacterAttributes(
t.getCharBegin() + change,
t.getCharEnd() - t.getCharBegin(),
***************
*** 789,792 ****
--- 854,882 ----
if (!tryAgain)
{
+ synchronized (doclock)
+ {
+ ////////////////////////////////////////////////////////////
+ // If all coloring is done, we color errors
+ ErrorInfo[] errInfoClone = (ErrorInfo[]) _currentErrorInfos.toArray(new ErrorInfo[0]);
+ for (int i = 0; i < errInfoClone.length; i++)
+ {
+ int begin = errInfoClone[i].beginPos - 1;
+ int len = errInfoClone[i].endPos - errInfoClone[i].beginPos;
+ if(0 < len)
+ {
+ // document.setCharacterAttributes(begin,
+ // len + 1,
+ // getMyStyle(IConstants.IStyleNames.ERROR),
+ // true);
+ setCharacterAttributes(begin,
+ len + 1,
+ getMyStyle(IConstants.IStyleNames.ERROR),
+ true);
+ }
+ }
+ //
+ /////////////////////////////////////////////////////////
+ }
+
try
{
***************
*** 801,804 ****
--- 891,912 ----
}
}
+
+
+ private void setCharacterAttributes(final int offset, final int length, final AttributeSet s, final boolean replace)
+ {
+ SwingUtilities.invokeLater(new Runnable()
+ {
+ public void run()
+ {
+ // Though in API-Doc they say setCharacterAttributes() is thread save we
+ // received observed java.lang.Errors from Swing as well as dead locks.
+ // That's why we do changes synchron now.
+ document.setCharacterAttributes(offset, length, s, replace);
+ }
+ });
+ }
+
+
+
}
***************
*** 827,830 ****
--- 935,956 ----
}
+ public String getToolTipText(MouseEvent event)
+ {
+ int pos = viewToModel(event.getPoint());
+
+ for (int i = 0; i < _currentErrorInfos.size(); i++)
+ {
+ ErrorInfo errInfo = (ErrorInfo) _currentErrorInfos.elementAt(i);
+
+ if(errInfo.beginPos-1 <= pos && pos <= errInfo.endPos)
+ {
+ return errInfo.message;
+ }
+ }
+
+ return null;
+ }
+
+
/**
* Just like a DefaultStyledDocument but intercepts inserts and
***************
*** 845,849 ****
// {
super.insertString(offs, str, a);
! color(offs, str.length());
documentReader.update(offs, str.length());
// }
--- 971,975 ----
// {
super.insertString(offs, str, a);
! color(offs, str.length(), true);
documentReader.update(offs, str.length());
// }
***************
*** 855,859 ****
// {
super.remove(offs, len);
! color(offs, -len);
documentReader.update(offs, -len);
// }
--- 981,985 ----
// {
super.remove(offs, len);
! color(offs, -len, true);
documentReader.update(offs, -len);
// }
|