@Override
 public final void restoreSettings() {
   int type = GuiSettings.getShowFilenameInWindowTitle();
   if (type >= GuiSettings.SHOW_NO_FILENAME && type <= GuiSettings.SHOW_FULL_PATH) {
     this.windowTitleComboBox.setSelectedIndex(type);
   }
   this.showProfileGroup.setSelected(GuiSettings.getShowProfileGroupInWindowTitle());
   this.showWorkspace.setSelected(GuiSettings.getShowWorkspaceInWindowTitle());
   this.productAtEnd.setSelected(GuiSettings.getShowProductNameAtEnd());
   this.showUrl.setSelected(GuiSettings.getShowURLinWindowTitle());
   this.includeUser.setSelected(GuiSettings.getIncludeUserInTitleURL());
   this.includeUser.setEnabled(showUrl.isSelected());
   String enclose = GuiSettings.getTitleGroupBracket();
   if (enclose == null) {
     encloseChar.setSelectedIndex(0);
   } else {
     int count = encloseChar.getItemCount();
     for (int i = 1; i < count; i++) {
       String item = (String) encloseChar.getItemAt(i);
       if (item.startsWith(enclose.trim())) {
         encloseChar.setSelectedIndex(i);
         break;
       }
     }
   }
   checkShowProfile();
   this.titleGroupSep.setText(GuiSettings.getTitleGroupSeparator());
 }
 @Override
 public void saveSettings() {
   GuiSettings.setShowFilenameInWindowTitle(this.windowTitleComboBox.getSelectedIndex());
   GuiSettings.setShowProfileGroupInWindowTitle(showProfileGroup.isSelected());
   GuiSettings.setShowWorkspaceInWindowTitle(showWorkspace.isSelected());
   GuiSettings.setShowProductNameAtEnd(productAtEnd.isSelected());
   GuiSettings.setTitleGroupSeparator(titleGroupSep.getText());
   GuiSettings.setShowURLinWindowTitle(showUrl.isSelected());
   GuiSettings.setIncludeUserInTitleURL(includeUser.isSelected());
   int index = this.encloseChar.getSelectedIndex();
   if (index == 0) {
     GuiSettings.setTitleGroupBracket(null);
   } else {
     String bracket = (String) this.encloseChar.getSelectedItem();
     GuiSettings.setTitleGroupBracket(bracket.substring(0, 1));
   }
 }
 @Override
 public void executeAction(ActionEvent e) {
   if (client == null) return;
   final boolean respectColName =
       ((e.getModifiers() & ActionEvent.SHIFT_MASK) == ActionEvent.SHIFT_MASK)
           || GuiSettings.getIncludeHeaderInOptimalWidth();
   final int column = client.getPopupColumnIndex();
   Thread t =
       new WbThread("OptimizeCol Thread") {
         @Override
         public void run() {
           optimizer.optimizeColWidth(column, respectColName);
         }
       };
   t.start();
 }
 private void addCurrentProc() {
   if (currentStartToken != null && this.currentIdentifier != null) {
     String name = currentIdentifier;
     if (StringUtil.isNonEmpty(parameterList)) {
       name += "(" + parameterList + ")";
     }
     if (globalState == GlobalState.packageSpec) {
       name = GuiSettings.getBookmarksPkgSpecPrefix() + " " + name;
     }
     NamedScriptLocation bookmark =
         new NamedScriptLocation(name, currentStartToken.getCharBegin(), id);
     this.procedures.add(bookmark);
     parameterList = null;
     currentIdentifier = "";
     bracketCount = 0;
     currentStartToken = null;
   }
 }
  public String getWindowTitle(
      ConnectionProfile profile, String workspaceFile, String editorFile, String appName) {
    final StringBuilder title = new StringBuilder(50);

    String enclose = GuiSettings.getTitleGroupBracket();
    String sep = GuiSettings.getTitleGroupSeparator();

    if (appName != null && productNamePosition == NAME_AT_START) {
      title.append(appName);
      title.append(' ');
    }

    if (profile != null) {
      boolean showUser = includeUser || profile.getPromptForUsername();

      if (showURL) {
        String url = makeCleanUrl(profile.getUrl());
        if (showUser) {
          title.append(profile.getLoginUser());
          if (url.charAt(0) != '@') {
            title.append('@');
          }
        }
        title.append(url);
      } else {
        if (profile.getPromptForUsername()) {
          // always display the username if prompted
          title.append(profile.getLoginUser());
          title.append("- ");
        }
        if (showProfileGroup) {
          char open = getOpeningBracket(enclose);
          char close = getClosingBracket(enclose);

          if (open != 0 && close != 0) {
            title.append(open);
          }
          title.append(profile.getGroup());
          if (open != 0 && close != 0) {
            title.append(close);
          }
          if (sep != null) title.append(sep);
        }
        title.append(profile.getName());
      }
    } else if (showNotConnected) {
      if (title.length() > 0) title.append("- ");
      title.append(ResourceMgr.getString("TxtNotConnected"));
    }

    if (workspaceFile != null && showWorkspace) {
      File f = new File(workspaceFile);
      String baseName = f.getName();
      title.append(" - ");
      title.append(baseName);
      title.append(" ");
    }

    int showFilename = GuiSettings.getShowFilenameInWindowTitle();
    if (editorFile != null && showFilename != GuiSettings.SHOW_NO_FILENAME) {
      title.append(" - ");
      if (showFilename == GuiSettings.SHOW_FULL_PATH) {
        title.append(editorFile);
      } else {
        File f = new File(editorFile);
        title.append(f.getName());
      }
    }

    if (appName != null && productNamePosition == NAME_AT_END) {
      if (title.length() > 0) title.append(" - ");
      title.append(appName);
    }

    return title.toString();
  }
 public WindowTitleBuilder() {
   setShowProductNameAtEnd(GuiSettings.getShowProductNameAtEnd());
 }
/** @author Thomas Kellerer */
public class WindowTitleBuilder {
  private static final int NAME_AT_END = 1;
  private static final int NAME_AT_START = 2;

  private boolean showProfileGroup = GuiSettings.getShowProfileGroupInWindowTitle();
  private boolean showURL = GuiSettings.getShowURLinWindowTitle();
  private boolean includeUser = GuiSettings.getIncludeUserInTitleURL();
  private int productNamePosition = NAME_AT_START;
  private boolean showWorkspace = GuiSettings.getShowWorkspaceInWindowTitle();
  private boolean showNotConnected = true;

  public WindowTitleBuilder() {
    setShowProductNameAtEnd(GuiSettings.getShowProductNameAtEnd());
  }

  public void setShowProfileGroup(boolean flag) {
    this.showProfileGroup = flag;
  }

  public void setShowURL(boolean flag) {
    this.showURL = flag;
  }

  public void setIncludeUser(boolean flag) {
    this.includeUser = flag;
  }

  public void setShowProductNameAtEnd(boolean flag) {
    if (flag) {
      productNamePosition = NAME_AT_END;
    } else {
      productNamePosition = NAME_AT_START;
    }
  }

  public void setShowWorkspace(boolean flag) {
    this.showWorkspace = flag;
  }

  public void setShowNotConnected(boolean flag) {
    this.showNotConnected = flag;
  }

  public String getWindowTitle(ConnectionProfile profile) {
    return getWindowTitle(profile, null, null);
  }

  public String getWindowTitle(ConnectionProfile profile, String workspaceFile, String editorFile) {
    return getWindowTitle(profile, workspaceFile, editorFile, ResourceMgr.TXT_PRODUCT_NAME);
  }

  public String getWindowTitle(
      ConnectionProfile profile, String workspaceFile, String editorFile, String appName) {
    final StringBuilder title = new StringBuilder(50);

    String enclose = GuiSettings.getTitleGroupBracket();
    String sep = GuiSettings.getTitleGroupSeparator();

    if (appName != null && productNamePosition == NAME_AT_START) {
      title.append(appName);
      title.append(' ');
    }

    if (profile != null) {
      boolean showUser = includeUser || profile.getPromptForUsername();

      if (showURL) {
        String url = makeCleanUrl(profile.getUrl());
        if (showUser) {
          title.append(profile.getLoginUser());
          if (url.charAt(0) != '@') {
            title.append('@');
          }
        }
        title.append(url);
      } else {
        if (profile.getPromptForUsername()) {
          // always display the username if prompted
          title.append(profile.getLoginUser());
          title.append("- ");
        }
        if (showProfileGroup) {
          char open = getOpeningBracket(enclose);
          char close = getClosingBracket(enclose);

          if (open != 0 && close != 0) {
            title.append(open);
          }
          title.append(profile.getGroup());
          if (open != 0 && close != 0) {
            title.append(close);
          }
          if (sep != null) title.append(sep);
        }
        title.append(profile.getName());
      }
    } else if (showNotConnected) {
      if (title.length() > 0) title.append("- ");
      title.append(ResourceMgr.getString("TxtNotConnected"));
    }

    if (workspaceFile != null && showWorkspace) {
      File f = new File(workspaceFile);
      String baseName = f.getName();
      title.append(" - ");
      title.append(baseName);
      title.append(" ");
    }

    int showFilename = GuiSettings.getShowFilenameInWindowTitle();
    if (editorFile != null && showFilename != GuiSettings.SHOW_NO_FILENAME) {
      title.append(" - ");
      if (showFilename == GuiSettings.SHOW_FULL_PATH) {
        title.append(editorFile);
      } else {
        File f = new File(editorFile);
        title.append(f.getName());
      }
    }

    if (appName != null && productNamePosition == NAME_AT_END) {
      if (title.length() > 0) title.append(" - ");
      title.append(appName);
    }

    return title.toString();
  }

  private char getOpeningBracket(String settingsValue) {
    if (StringUtil.isEmptyString(settingsValue)) return 0;
    return settingsValue.charAt(0);
  }

  private char getClosingBracket(String settingsValue) {
    if (StringUtil.isEmptyString(settingsValue)) return 0;
    char open = getOpeningBracket(settingsValue);
    if (open == '{') return '}';
    if (open == '[') return ']';
    if (open == '(') return ')';
    if (open == '<') return '>';
    return 0;
  }

  public String makeCleanUrl(String url) {
    if (StringUtil.isEmptyString(url)) return url;

    int numColon = 2;
    if (url.startsWith("jdbc:oracle:") || url.startsWith("jdbc:jtds:")) {
      numColon = 3;
    }
    int pos = StringUtil.findOccurance(url, ':', numColon);
    if (pos > 0) {
      return url.substring(pos + 1);
    }
    return url;
  }
}
 public DropDownCellEditor(WbTable dataTable) {
   table = dataTable;
   input = new JComboBox();
   input.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
   input.setEditable(GuiSettings.getVariablesDDEditable());
 }
 public ProcedureBookmarks(String panelId) {
   this.id = panelId;
   reset();
   this.includeParameterNames = GuiSettings.getProcBookmarksIncludeParmName();
 }
  @Override
  public void restoreSettings() {
    appendResults.setSelected(GuiSettings.getDefaultAppendResults());
    rowHeightResize.setSelected(GuiSettings.getAllowRowHeightResizing());
    autoRowHeight.setSelected(GuiSettings.getAutomaticOptimalRowHeight());
    maxRowHeight.setText(Integer.toString(GuiSettings.getAutRowHeightMaxLines()));
    autoColWidth.setSelected(GuiSettings.getAutomaticOptimalWidth());
    includeHeaderWidth.setSelected(GuiSettings.getIncludeHeaderInOptimalWidth());
    ignoreEmptyRows.setSelected(GuiSettings.getIgnoreWhitespaceForAutoRowHeight());
    minColSizeField.setText(Integer.toString(GuiSettings.getMinColumnWidth()));
    maxColSizeField.setText(Integer.toString(GuiSettings.getMaxColumnWidth()));
    selectSummary.setSelected(GuiSettings.getShowSelectionSummary());
    multiLineThreshold.setText(Integer.toString(GuiSettings.getMultiLineThreshold()));
    wrapMultineRender.setSelected(GuiSettings.getWrapMultilineRenderer());
    wrapMultlineEdit.setSelected(GuiSettings.getWrapMultilineEditor());

    defMaxRows.setText(Integer.toString(GuiSettings.getDefaultMaxRows()));
    retrieveComments.setSelected(GuiSettings.getRetrieveQueryComments());
    showRowNumbers.setSelected(GuiSettings.getShowTableRowNumbers());
    showMaxRowsWarn.setSelected(GuiSettings.getShowMaxRowsReached());
    showMaxRowsTooltip.setSelected(GuiSettings.getShowMaxRowsTooltip());
    nullString.setText(GuiSettings.getDisplayNullString());
    showGeneratingSQL.setSelected(GuiSettings.getShowResultSQL());
    useTableName.setSelected(GuiSettings.getUseTablenameAsResultName());
    int align = GuiSettings.getNumberDataAlignment();
    if (align == SwingConstants.LEFT) {
      alignmentDropDown.setSelectedIndex(1);
    } else {
      alignmentDropDown.setSelectedIndex(0);
    }
    boldHeader.setSelected(GuiSettings.showTableHeaderInBold());
    fillLanguageDropDown();
  }
 @Override
 public void saveSettings() {
   int value = StringUtil.getIntValue(multiLineThreshold.getText(), -1);
   if (value > 0) GuiSettings.setMultiLineThreshold(value);
   GuiSettings.setAllowRowHeightResizing(rowHeightResize.isSelected());
   GuiSettings.setMaxColumnWidth(((NumberField) this.maxColSizeField).getValue());
   GuiSettings.setMinColumnWidth(((NumberField) this.minColSizeField).getValue());
   GuiSettings.setAutomaticOptimalWidth(autoColWidth.isSelected());
   GuiSettings.setIncludeHeaderInOptimalWidth(includeHeaderWidth.isSelected());
   GuiSettings.setAutomaticOptimalRowHeight(autoRowHeight.isSelected());
   GuiSettings.setAutRowHeightMaxLines(((NumberField) this.maxRowHeight).getValue());
   GuiSettings.setIgnoreWhitespaceForAutoRowHeight(ignoreEmptyRows.isSelected());
   GuiSettings.setShowSelectionSummary(selectSummary.isSelected());
   GuiSettings.setDefaultMaxRows(StringUtil.getIntValue(defMaxRows.getText(), 0));
   GuiSettings.setRetrieveQueryComments(retrieveComments.isSelected());
   GuiSettings.setShowTableRowNumbers(showRowNumbers.isSelected());
   GuiSettings.setShowMaxRowsReached(showMaxRowsWarn.isSelected());
   GuiSettings.setDisplayNullString(nullString.getText());
   GuiSettings.setShowResultSQL(showGeneratingSQL.isSelected());
   GuiSettings.setShowTableHeaderInBold(boldHeader.isSelected());
   GuiSettings.setWrapMultilineEditor(wrapMultlineEdit.isSelected());
   GuiSettings.setWrapMultilineRenderer(wrapMultineRender.isSelected());
   GuiSettings.setShowMaxRowsTooltip(showMaxRowsTooltip.isSelected());
   GuiSettings.setDefaultAppendResults(appendResults.isSelected());
   GuiSettings.setUseTablenameAsResultName(useTableName.isSelected());
   DisplayLocale dl = (DisplayLocale) localeDropDown.getSelectedItem();
   Settings.getInstance().setSortLocale(dl.getLocale());
   if (alignmentDropDown.getSelectedIndex() == 1) {
     GuiSettings.setNumberDataAlignment("left");
   } else {
     GuiSettings.setNumberDataAlignment("right");
   }
 }