コード例 #1
0
  /**
   * Builds the panel. Initializes and configures components first, then creates a FormLayout,
   * configures the layout, creates a builder, sets a border, and finally adds the components.
   *
   * @return the built panel
   */
  public JComponent createContentPanel() {
    FormLayout layout =
        new FormLayout(
            "p,3dlu,p,3dlu", // cols //$NON-NLS-1$
            "p,10dlu,p,10dlu"); // rows //$NON-NLS-1$

    // Create a builder that assists in adding components to the container.
    // Wrap the panel with a standardized border.
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    builder.setDefaultDialogBorder();

    CellConstraints cc = new CellConstraints();
    JEditorPane l = new JEditorPane("text/html", Messages.getString("LicenseDialog.Email"));
    l.setEditable(false);
    l.setOpaque(false);
    l.setFont(l.getFont().deriveFont(Font.PLAIN));
    JLabel emailLabel = new JLabel(Messages.getString("LicenseDialog.EmailLabel") + ":");
    // emailLabel.setFont(emailLabel.getFont().deriveFont(Font.PLAIN));
    builder.add(l, cc.xyw(1, 1, 4));
    builder.nextLine(2);
    builder.append(emailLabel, email);
    builder.nextLine(2);

    JComponent result = builder.getPanel();
    return result;
  }
コード例 #2
0
  // private constructor initializes values.
  private DurationFormat(boolean showPlusSign) {
    this.showPlusSign = showPlusSign;
    String estimated = Messages.getString("Units.estimatedSymbolRegex"); // Like ?

    // a bunch of init code which reads the possible  values for durations from localized messages
    for (int i = 0; i < TYPE_COUNT; i++) {
      String singularNames = null;
      String pluralNames = null;
      for (int j = 0; j < multiple.length; j++) {
        String names = new String(Messages.getString("Units." + types[i] + multiple[j]));
        if (j == SINGULAR) singularNames = names;
        if (j == PLURAL) pluralNames = names;
        String[] units = names.split("\\|"); // index into the names list, getting string
        // split has a big memory cost so names are pre-splited
        for (int k = 0; k < NAME_COUNT; k++) typesArray[k][j][i] = units[k];
      }
      // The pattern represents the following:
      // Singular type OR Plural type, optinally followed by white space and the estimated symbol
      // (?)
      // Two groups are saved: Group 1 is the type, Group 2 is the estimated symbol
      pattern[i] =
          Pattern.compile(
              "((?:"
                  + singularNames
                  + ")"
                  + "|(?:"
                  + pluralNames
                  + "))?"
                  + "(\\s*"
                  + estimated
                  + "?)");
    }
  }
コード例 #3
0
ファイル: HelpDialog.java プロジェクト: sjaeckel/angelfalls
 private HelpDialog(Frame owner) {
   super(
       owner,
       Messages.getString("HelpDialog.About")
           + " "
           + Messages.getContextString("Text.ApplicationTitle"),
       true); //$NON-NLS-1$ //$NON-NLS-2$
 }
コード例 #4
0
 protected void checkServerVersion(String serverVersion) {
   String thisVersion = null;
   if (serverVersion != null) {
     thisVersion = VersionUtils.getVersion();
     if (thisVersion != null) thisVersion = VersionUtils.toAppletVersion(thisVersion);
     if (thisVersion == null || serverVersion.equals(thisVersion)) return; // ok
   }
   String jnlpUrl = "https://www.projity.com/web/jnlp/project-on-demand.jnlp";
   //		String jnlpUrl="http://192.168.0.2/web/jnlp/project-on-demand.jnlp";
   if (Alert.okCancel(Messages.getString("Text.newPODVersion"))) {
     try {
       Object basicService =
           ClassLoaderUtils.forName("javax.jnlp.ServiceManager")
               .getMethod("lookup", new Class[] {String.class})
               .invoke(null, new Object[] {"javax.jnlp.BasicService"});
       ClassLoaderUtils.forName("javax.jnlp.BasicService")
           .getMethod("showDocument", new Class[] {URL.class})
           .invoke(basicService, new Object[] {new URL(jnlpUrl)});
     } catch (Exception e) {
       // e.printStackTrace();
       // Not running in JavaWebStart or service is not supported.
       return;
       // Runtime.getRuntime().exec("javaws ");
     }
     //			try {
     //			BasicService basicService=(BasicService)ServiceManager.lookup("javax.jnlp.BasicService");
     //			basicService.showDocument(/*new URL(basicService.getCodeBase(),*/new URL(jnlpUrl));
     //			}catch (UnavailableServiceException e) {
     //			Runtime.getRuntime().exec("javaws ");
     //			}
     System.exit(0);
   }
 }
コード例 #5
0
ファイル: HelpDialog.java プロジェクト: sjaeckel/angelfalls
  public static JPanel makeDonatePanel(boolean border) {
    FormLayout layout =
        new FormLayout(
            "250px", // cols //$NON-NLS-1$
            "p, 6dlu,  p"); // rows //$NON-NLS-1$
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    if (border) builder.setDefaultDialogBorder();

    JLabel msg = new JLabel(Messages.getString("Text.donateMessage"));

    builder.append(msg);
    builder.nextLine(2);
    ImageIcon icon = IconManager.getIcon("paypal.donate");
    JButton donate = new JButton(icon);
    donate.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

    builder.append(donate);
    donate.setEnabled(true);
    donate.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            BrowserControl.displayURL(donateUrl);
          }
        });

    return builder.getPanel();
  }
コード例 #6
0
   */ public Boolean verifyOpenWritable(Long projectId) {
    if (projectId == null || projectId == 0) return null;
    if (ProjectFactory.getInstance().isResourcePoolOpenAndWritable()) {
      Alert.warn(Messages.getString("Warn.resourcePoolOpen"));
      return null;
    }

    String locker = getLockerName(projectId);
    boolean openAs = false;
    if (locker != null) {
      openAs =
          (JOptionPane.YES_OPTION
              == Alert.confirmYesNo(Messages.getStringWithParam("Warn.lockMessage", locker)));
      if (openAs == false) return null;
    }
    return !openAs;
  }
コード例 #7
0
ファイル: HelpDialog.java プロジェクト: sjaeckel/angelfalls
  protected void initComponents() {
    link = new JButton(Messages.getString("HelpDialog.GoToOnlineHelp")); // $NON-NLS-1$
    link.setEnabled(true);
    link.setToolTipText(helpUrl);
    link.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            BrowserControl.displayURL(helpUrl);
          }
        });
    //		videos = new JButton(Messages.getString("HelpDialog.WatchHowToVideos")); //$NON-NLS-1$
    //		videos.setEnabled(true);
    //		videos.setToolTipText(helpUrl);
    //		videos.addActionListener(new ActionListener() {
    //			public void actionPerformed(ActionEvent arg0) {
    //				BrowserControl.displayURL(videosUrl);
    //			}
    //		});
    if (Environment.isOpenProj()) {
      tipOfTheDay = new JButton(Messages.getString("HelpDialog.ShowTipsOfTheDay")); // $NON-NLS-1$
      tipOfTheDay.setEnabled(true);
      tipOfTheDay.setToolTipText(Messages.getString("HelpDialog.ShowTipsOfTheDay")); // $NON-NLS-1$
      tipOfTheDay.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
              TipOfTheDay.showDialog(HelpDialog.this.getOwner(), true);
            }
          });
    }
    license = new JButton(Messages.getString("HelpDialog.ShowLicense")); // $NON-NLS-1$
    license.setEnabled(true);
    license.setToolTipText(Messages.getString("HelpDialog.ShowLicense")); // $NON-NLS-1$
    license.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            LicenseDialog.showDialog(GraphicManager.getFrameInstance(), true);
          }
        });

    super.initComponents();
  }
コード例 #8
0
  public void init(BarFormat format) {
    if (format == null) return;
    FormFormat form = format.getForm();
    if (form == null) return;
    List boxes = form.getBoxes();
    if (boxes == null || boxes.size() == 0) {
      return;
    }
    FormBoxLayout formBoxLayout = form.getLayout(zoom);
    FormLayout layout = new FormLayout(formBoxLayout.getColumnGrid(), formBoxLayout.getRowGrid());
    /// DefaultFormBuilder builder = new DefaultFormBuilder(this,layout);
    DefaultFormBuilder builder = new DefaultFormBuilder(layout, this);
    if (formBoxLayout.getBorder() == null) builder.setDefaultDialogBorder();
    else builder.setBorder(Borders.createEmptyBorder(formBoxLayout.getBorder()));
    CellConstraints cc = new CellConstraints();
    for (Iterator i = boxes.iterator(); i.hasNext(); ) {
      FormBox box = (FormBox) i.next();
      if (zoom < box.getMinZoom()) return;
      JComponent component;
      if (box.getFieldId() == null) component = new JLabel(Messages.getString(box.getTextId()));
      else {
        if (editor && !box.getField().isReadOnly()) {
          component = new ChangeAwareTextField();
          component.setBorder(null);
          // component.setOpaque(false);
        } else component = new JLabel();

        // if (box.getRow()==1&&!editor)
        // ((JLabel)component).setHorizontalAlignment(SwingConstants.CENTER);
        // bug workaround, not possible to center with classic method when rowSpan>1

        fieldComponents.put(box.getFieldId(), component);
      }
      Font font = formBoxLayout.getFont(box.getFont());
      if (font != null) component.setFont(font);
      String ba = box.getAlignment();
      int bc = box.getColumn();
      int br = box.getRow();
      int bcs = box.getColumnSpan();
      int brs = box.getRowSpan();
      try {
        builder.add(
            component, (ba == null) ? cc.xywh(bc, br, bcs, brs) : cc.xywh(bc, br, bcs, brs, ba));
      } catch (IndexOutOfBoundsException e) {
        log.fatal("box.Column(): " + bc);
        log.fatal("box.Row(): " + br);
        log.fatal("box.ColumnSpan(): " + bcs);
        log.fatal("box.RowSpan(): " + brs);
        log.fatal("box.Alignment(): " + ba);
        log.fatal("Occur Error: ", e);
      }
    }
  }
コード例 #9
0
 public static String getStatusName(
     int
         status) { // used for display style in web, that's why I don't use dots - CSS wouldn't
                   // like it
   switch (status) {
     case TimesheetStatus.ENTERED:
       return Messages.getString("TimesheetHelper.Entered"); // $NON-NLS-1$
     case TimesheetStatus.INTEGRATED:
       return Messages.getString("TimesheetHelper.Integrated"); // $NON-NLS-1$
     case TimesheetStatus.NO_DATA:
       return Messages.getString("TimesheetHelper.New"); // $NON-NLS-1$
     case TimesheetStatus.REJECTED:
       return Messages.getString("TimesheetHelper.Rejected"); // $NON-NLS-1$
     case TimesheetStatus.VALIDATED:
       return Messages.getString("TimesheetHelper.Validated"); // $NON-NLS-1$
     case TimesheetStatus.MIXED:
       return Messages.getString("TimesheetHelper.Mixed"); // $NON-NLS-1$
     case TimesheetStatus.SAVED:
       return Messages.getString("TimesheetHelper.Saved"); // $NON-NLS-1$
   }
   return Messages.getString("TimesheetHelper.New"); // $NON-NLS-1$
 }
コード例 #10
0
  protected void retrieveResourcesForMerge(Project existingProject) throws Exception {
    ResourceMappingForm form = getResourceMapping();
    if (form == null) return;

    Vector projityResources = new Vector();
    // map the existint project resourse impls for later use
    _localResourceMap = new HashMap<Long, com.projity.pm.resource.Resource>();

    EnterpriseResourceData unassigned = new EnterpriseResourceData();
    unassigned.setUniqueId(EnterpriseResource.UNASSIGNED_ID);
    unassigned.setName(Messages.getString("Text.Unassigned")); // $NON-NLS-1$
    form.setUnassignedResource(unassigned);
    projityResources.add(unassigned);

    Serializer serializer = new Serializer();

    ProjectData projectData =
        (ProjectData) serializer.serialize(existingProject, ProjectData.FACTORY, null);
    if (existingProject.isForceNonIncremental()) projectData.setVersion(0);
    projectData.setMaster(existingProject.isMaster());

    // resources
    Map resourceMap = serializer.saveResources(existingProject, projectData);
    List<com.projity.pm.resource.Resource> existingResources =
        (List<com.projity.pm.resource.Resource>)
            existingProject.getResourcePool().getResourceList();
    for (com.projity.pm.resource.Resource resource : existingResources) {
      if (resource == null) continue;
      ResourceData r = (ResourceData) resourceMap.get(resource.getUniqueId());
      if (r != null) {
        EnterpriseResourceData er = r.getEnterpriseResource();
        er.setName(resource.getName());
        projityResources.add(er);
        _localResourceMap.put((Long) r.getUniqueId(), resource);
      }
    }

    form.setResources(projityResources);
  }
コード例 #11
0
  public Job getImportFileJob() {
    final Serializer serializer = new Serializer();
    final FileImporter importer = this;
    final Job job =
        new Job(
            importer.getJobQueue(),
            "importFile",
            Messages.getString("LocalFileImporter.Importing"),
            true); //$NON-NLS-1$ //$NON-NLS-2$
    job.addRunnable(
        new JobRunnable("Import", 1.0f) { // $NON-NLS-1$
          public Object run() throws Exception {
            // DataUtil serializer=new DataUtil();
            System.out.println(
                "Loading " + importer.getFileName() + "..."); // $NON-NLS-1$ //$NON-NLS-2$

            long t1 = System.currentTimeMillis();
            ObjectInputStream in =
                new ObjectInputStream(new FileInputStream(importer.getFileName()));
            Object obj = in.readObject();
            if (obj instanceof String) obj = in.readObject(); // check version in the future
            projectData = (ProjectData) obj;
            projectData.setMaster(false);
            projectData.setLocal(false);
            long t2 = System.currentTimeMillis();
            System.out.println(
                "Loading...Done in " + (t2 - t1) + " ms"); // $NON-NLS-1$ //$NON-NLS-2$

            Collection<ResourceData> rs = (Collection<ResourceData>) projectData.getResources();
            List<EnterpriseResourceData> ers = new ArrayList<EnterpriseResourceData>(rs.size());
            for (ResourceData r : rs) {
              ers.add(r.getEnterpriseResource());
            }

            ((ServerFileImporter) importer).prepareResources(ers, null, false);
            renumberProject();

            setProgress(1.0f);
            return null;
          }
        });

    job.addSwingRunnable(
        new JobRunnable("Import resources", 1.0f) { // $NON-NLS-1$
          public Object run() throws Exception {
            ResourceMappingForm form = getResourceMapping();
            if (form != null
                && form
                    .isLocal()) // if form==null we are in a case were have no server access. popup
              // not needed
              if (!job.okCancel(
                  Messages.getString("Message.ServerUnreacheableReadOnlyProject"),
                  true)) { //$NON-NLS-1$
                setProgress(1.0f);
                throw new Exception(ABORT);
              }

            if (!importResources()) {
              setProgress(1.0f);
              throw new JobCanceledException(ABORT);
            }
            setProgress(1f);
            return null;
          }
        });

    job.addRunnable(
        new JobRunnable("Import", 1.0f) { // $NON-NLS-1$
          public Object run() throws Exception {
            System.out.println("Deserializing..."); // $NON-NLS-1$
            long t1 = System.currentTimeMillis();
            ResourceMappingForm form = getResourceMapping();
            //
            // project=serializer.deserializeProject(projectData,false,true,resourceMap);
            // DEF165936:  Projity: .pod file import fails mapped to resource with modified calendar
            // pass the map into the serializer so it can grab the original impls
            //    	        serializer.SetStuffForPODDeserialization(form.getExistingProject(),
            // _localResourceMap); //claur
            Project project =
                serializer.deserializeProject(projectData, false, null, null, null, false);
            if (project != null && !Environment.getStandAlone()) project.setAllDirty();
            importer.setProject(project);
            long t2 = System.currentTimeMillis();
            System.out.println(
                "Deserializing...Done in " + (t2 - t1) + " ms"); // $NON-NLS-1$ //$NON-NLS-2$

            // project.setDistributionMap(null);
            project.setGroupDirty(!Environment.getStandAlone());
            /*if (!Environment.isNoPodServer())*/ project.setTemporaryLocal(true);

            project.setAccessControlPolicy(form.getAccessControlType());
            project.resetRoles(form.getAccessControlType() == 0);
            if (form.isLocal()) project.setLocal(true);
            //    			project.setWasImported(true);

            setProgress(1.0f);
            return null;
          }
        });

    return job;
  }
コード例 #12
0
/**
 * Instead of creating a true Duration type, I use unused bits of the long which stores durations.
 * The idea is that the algorithms will run faster because there is no object churn and fewer
 * function calls.
 */
public class DurationFormat extends Format {
  private boolean showPlusSign = false;
  private boolean isWork = false;
  private boolean canBeNonTemporal = false;
  private static Format instance = null;

  public static Format getInstance() {
    if (instance == null) instance = new DurationFormat(false);
    return instance;
  }

  private static Format signedInstance = null;

  public static Format getSignedInstance() {
    if (signedInstance == null) signedInstance = new DurationFormat(true);
    return signedInstance;
  }

  private static Format workInstance = null;

  public static Format getWorkInstance() {
    if (workInstance == null) {
      workInstance = new DurationFormat(false);
      ((DurationFormat) workInstance).isWork = true;
    }
    return workInstance;
  }

  private static Format nonTemporalWorkInstance = null;

  public static Format getNonTemporalWorkInstance() {
    if (nonTemporalWorkInstance == null) {
      nonTemporalWorkInstance = new DurationFormat(false);
      ((DurationFormat) nonTemporalWorkInstance).isWork = true;
      ((DurationFormat) nonTemporalWorkInstance).canBeNonTemporal = true;
    }
    return nonTemporalWorkInstance;
  }

  // these strings are themselves parts of string ids in properties file and as such must be hard
  // coded as below
  private static String[] types = {
    "minute",
    "hour",
    "day",
    "week",
    "month",
    "year",
    "percent",
    "eminute",
    "ehour",
    "eday",
    "eweek",
    "emonth",
    "eyear",
    "epercent"
  };

  private static final int SINGULAR = 0;
  private static final int PLURAL = 1;
  private static final String multiple[] = {".singular", ".plural"};
  private static int TYPE_COUNT = types.length;
  private static int NAME_COUNT = 4;
  private static String[][][] typesArray = new String[NAME_COUNT][multiple.length][TYPE_COUNT];
  private static Pattern[] pattern = new Pattern[TYPE_COUNT];
  private static String estimatedSymbol = Messages.getString("Units.estimatedSymbol");

  // private constructor initializes values.
  private DurationFormat(boolean showPlusSign) {
    this.showPlusSign = showPlusSign;
    String estimated = Messages.getString("Units.estimatedSymbolRegex"); // Like ?

    // a bunch of init code which reads the possible  values for durations from localized messages
    for (int i = 0; i < TYPE_COUNT; i++) {
      String singularNames = null;
      String pluralNames = null;
      for (int j = 0; j < multiple.length; j++) {
        String names = new String(Messages.getString("Units." + types[i] + multiple[j]));
        if (j == SINGULAR) singularNames = names;
        if (j == PLURAL) pluralNames = names;
        String[] units = names.split("\\|"); // index into the names list, getting string
        // split has a big memory cost so names are pre-splited
        for (int k = 0; k < NAME_COUNT; k++) typesArray[k][j][i] = units[k];
      }
      // The pattern represents the following:
      // Singular type OR Plural type, optinally followed by white space and the estimated symbol
      // (?)
      // Two groups are saved: Group 1 is the type, Group 2 is the estimated symbol
      pattern[i] =
          Pattern.compile(
              "((?:"
                  + singularNames
                  + ")"
                  + "|(?:"
                  + pluralNames
                  + "))?"
                  + "(\\s*"
                  + estimated
                  + "?)");
    }
  }

  private static NumberFormat DECIMAL_FORMAT = NumberFormat.getNumberInstance();

  static {
    DECIMAL_FORMAT.setMaximumFractionDigits(2);
  }

  /* (non-Javadoc)
   * @see java.text.Format#parseObject(java.lang.String, java.text.ParsePosition)
   */
  public Object parseObject(String durationString, ParsePosition pos) {
    Object result = null;
    if (durationString.length() == 0) return null;

    if (durationString.charAt(pos.getIndex()) == '+') // if string begins with + sign, ignore it
    pos.setIndex(pos.getIndex() + 1);

    Number numberResult = DECIMAL_FORMAT.parse(durationString, pos);
    if (numberResult == null) return null;
    String durationPart = durationString.substring(pos.getIndex());
    durationPart = durationPart.trim();
    Matcher matcher;
    for (int i = 0; i < TYPE_COUNT; i++) { // find hte appropriate units
      matcher = pattern[i].matcher(durationPart);
      if (matcher.matches()) {
        int timeUnit =
            (matcher.group(1) != null)
                ? i
                : TimeUnit
                    .NONE; // first group is units.  If no units, then it will match, but should use
                           // default: NONE
        double value = numberResult.doubleValue();
        if (timeUnit == TimeUnit.PERCENT || timeUnit == TimeUnit.ELAPSED_PERCENT) value /= 100.0;
        if (timeUnit == TimeUnit.NONE && isWork) {
          if (canBeNonTemporal) timeUnit = TimeUnit.NON_TEMPORAL;
          else
            timeUnit =
                ScheduleOption.getInstance()
                    .getWorkUnit(); // use default work unit if work and nothing entered
        }
        long longResult = Duration.getInstance(value, timeUnit);
        if (Duration.millis(longResult) > Duration.MAX_DURATION) // check for too big
        return null;
        if (matcher.group(2).length() != 0) { // second group is estimated
          longResult = Duration.setAsEstimated(longResult, true);
        }

        result = new Duration(longResult);

        return result;
      }
    }

    return null;
  }
  /* (non-Javadoc)
   * @see java.text.Format#format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition)
   */
  public StringBuffer format(Object durationObject, StringBuffer toAppendTo, FieldPosition pos) {
    long duration = ((Duration) durationObject).getEncodedMillis();
    if (((Duration) durationObject).isWork()
        && Duration.getType(duration) != TimeUnit.NON_TEMPORAL) {
      duration = Duration.setAsTimeUnit(duration, ScheduleOption.getInstance().getWorkUnit());
    }

    double value = Duration.getValue(duration);
    int type = Duration.getEffectiveType(duration);
    if (value > 0D && showPlusSign) toAppendTo.append("+");
    boolean isPercent = Duration.isPercent(duration);
    if (isPercent) value *= 100.0;
    DECIMAL_FORMAT.format(value, toAppendTo, pos);

    String unit =
        formatTypeUnit(
            type,
            (Math.abs(value) == 1.0),
            EditOption.getInstance().isAddSpaceBeforeLabel(),
            Duration.isPercent(duration),
            Duration.isEstimated(duration),
            EditOption.getInstance().getViewAs(type));
    toAppendTo.append(unit);
    return toAppendTo;
  }

  public String formatCompact(Object durationObject) {
    StringBuffer toAppendTo = new StringBuffer();
    long duration = ((Duration) durationObject).getEncodedMillis();
    if (((Duration) durationObject).isWork()
        && Duration.getType(duration) != TimeUnit.NON_TEMPORAL) {
      duration = Duration.setAsTimeUnit(duration, ScheduleOption.getInstance().getWorkUnit());
    }

    double value = Duration.getValue(duration);
    int type = Duration.getEffectiveType(duration);
    if (value > 0D && showPlusSign) toAppendTo.append("+");
    boolean isPercent = Duration.isPercent(duration);
    if (isPercent) value *= 100.0;
    toAppendTo.append(DECIMAL_FORMAT.format(value));

    String unit =
        formatTypeUnit(
            type,
            (Math.abs(value) == 1.0),
            false,
            Duration.isPercent(duration),
            Duration.isEstimated(duration),
            3);
    toAppendTo.append(unit);
    return toAppendTo.toString();
  }

  public static String formatTypeUnit(
      int type,
      boolean isSingular,
      boolean addSpace,
      boolean isPercent,
      boolean isEstimated,
      int displayIndex) {
    StringBuffer toAppendTo = new StringBuffer();
    if (type == TimeUnit.NON_TEMPORAL) return "";
    if (addSpace && !isPercent) {
      toAppendTo.append(" ");
    }
    String unit =
        typesArray[displayIndex][isSingular ? SINGULAR : PLURAL][
            type]; // get either singular or plural names list
    toAppendTo.append(unit);
    if (isEstimated) toAppendTo.append(estimatedSymbol);
    return toAppendTo.toString();
  }

  public static String formatTypeUnit(int type) {
    DurationFormat.getInstance(); // make sure it is initialized
    return formatTypeUnit(
        type, true, false, false, false, EditOption.getInstance().getViewAs(type));
  }

  public static String format(long millis) {
    return getInstance().format(new Duration(millis)).toString();
  }

  public static String formatCompact(long millis) {
    return ((DurationFormat) getInstance()).formatCompact(new Duration(millis)).toString();
  }

  public static String formatWork(long millis) {
    return getWorkInstance().format(new Work(millis)).toString();
  }

  public static String formatWork(Object millis) {
    if (millis != null && millis instanceof Long) return formatWork(((Long) millis).longValue());
    return getWorkInstance().format(millis);
  }

  private static int getTypeUnit(String typeName) {
    for (int i = 0; i < TYPE_COUNT; i++) {
      if (types[i].equals(typeName)) return i;
    }
    return -1;
  }

  public static String formatTypeUnit(String typeName) {
    DurationFormat.getInstance();
    int type = getTypeUnit(typeName);
    if (type == -1) return null;
    return formatTypeUnit(type, true, false, false, false, 0);
  }
}
コード例 #13
0
public class SpreadSheetColumnMenu extends JPopupMenu {
  private static final long serialVersionUID = -8788124911790572547L;

  private JMenuItem insert =
      new JMenuItem(Messages.getString("SpreadSheetColumnMenu.InsertColumn")); // $NON-NLS-1$

  private JMenuItem hide =
      new JMenuItem(Messages.getString("SpreadSheetColumnMenu.HideColumn")); // $NON-NLS-1$
  private JMenuItem rename =
      new JMenuItem(Messages.getString("RenameDialog.Rename")); // $NON-NLS-1$
  private JMenuItem find = new JMenuItem(Messages.getString("LookupDialog.Find")); // $NON-NLS-1$

  /** @param col column that was clicked on */
  public SpreadSheetColumnMenu(CommonSpreadSheet spreadSheet, final int col) {
    super();
    // setLabel("");
    setBorder(new BevelBorder(BevelBorder.RAISED));
    final CommonSpreadSheet sp = spreadSheet;
    final SpreadSheetFieldArray fields = (SpreadSheetFieldArray) sp.getFieldArray();
    insert.setIcon(IconManager.getIcon("menu.insertColumn")); // $NON-NLS-1$
    insert.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            Field field = ColumnDialog.getFieldFromDialog(sp, sp.getAvailableFields(), fields);
            if (field != null) {
              int c = col;
              if (c == 0) // takes care of when adding off to right. openproj bug 1815404
              c = fields.size();
              sp.setFieldArray(fields.insertField(c, field));
            }
          }
        });
    hide.setIcon(IconManager.getIcon("menu.hideColumn")); // $NON-NLS-1$

    hide.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            if (fields.size()
                > 2) { // there is always the hidden Id field, so only allow delete if more than one
                       // other field
              sp.setFieldArray(fields.removeField(col));
            } else {
              Alert.warn(Messages.getString("Message.cantEmptySpreadsheet"), sp); // $NON-NLS-1$
            }
          }
        });

    final Field f = (Field) fields.get(col);

    rename.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {

            if (fields.size()
                > 2) { // there is always the hidden Id field, so only allow delete if more than one
                       // other field
              FieldAliasDialog.doRename(f);
              sp.setFieldArray(fields);
            } else {
              Alert.warn(Messages.getString("Message.cantEmptySpreadsheet"), sp); // $NON-NLS-1$
            }
          }
        });

    find.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent arg0) {
            GraphicManager.getInstance().doFind(sp, f);
          }
        });

    add(insert);
    add(hide);
    if (!Environment.isNoPodServer() && f.isCustom()) add(rename);
    add(find);
  }
}
コード例 #14
0
  public boolean doLogin(GraphicManager graphicManager) {

    if (Environment.isNoPodServer()) {
      Environment.setNewLook(true);
      log.info("Login POD Server.");
    }
    if (Environment.getStandAlone() || Environment.isNoPodServer()) {
      if (!Environment.isNoPodServer()) {
        Environment.setUser(new DefaultUser());
        log.info("Locale user.");
      }
      return true;
    }
    credentials.put("serverUrl", serverUrl);
    getCredentials();
    Environment.setNewLook(true);

    int badLoginCount = 0;
    while (true) { // until a good login or exit because of too many bad
      //			graphicManager.getFrame().setVisible(true);
      if (login == null || password == null || badLoginCount > 0) {
        URL loginUrl = null;
        if (login == null || password == null) {
          try {
            loginUrl = new URL(serverUrl + "/login");
            System.out.println("trying login at " + serverUrl + "/login");
          } catch (MalformedURLException e) {
          }
        }
        LoginForm form =
            LoginDialog.doLogin(graphicManager.getFrame(), loginUrl); // it's actually a singleton
        if (form.isCancelled()) System.exit(-1);
        if (form.isUseMenus()) Environment.setNewLook(false);

        login = form.getLogin();
        password = form.getPassword();
      }

      if ("_SA".equals(login) || Environment.getStandAlone()) { // for testing purposes!
        Environment.setStandAlone(true);
        Environment.setUser(new DefaultUser());
        break;
      } else {
        credentials.put("login", login);
        credentials.put("password", password);

        SessionFactory.getInstance().setCredentials(credentials);
        try {
          Session session = SessionFactory.getInstance().getSession(false);
          System.out.println("logging in");
          final GraphicManager gm = graphicManager;
          SessionFactory.callNoEx(
              session,
              "login",
              new Class[] {Closure.class},
              new Object[] {
                new Closure() {
                  public void execute(Object arg0) {
                    Map<String, String> env = (Map<String, String>) arg0;
                    if (env != null) {
                      String serverVersion = env.get("serverVersion");
                      checkServerVersion(serverVersion);
                    }
                    if (gm != null) gm.setConnected(true);
                  }
                }
              });
          if (!((Boolean) SessionFactory.callNoEx(session, "isLicensedToRunClient", null, null))
              .booleanValue()) {
            Alert.error(Messages.getString("Error.roleCantRunClient"));
            abort();
            return false;
          }

          //					System.out.println("Application started with args: credentials=" +
          // credentials.get("login") + " name " + session.getUser().getName() + " Roles " +
          // session.getUser().getServerRoles());
          break;
          //			TODO test if login is valid.  If not, reshow login dialog
        } catch (Exception e) {
          if (Session.EXPIRED.equals(e.getMessage())) {
            Alert.error(Messages.getString("Error.accountExpired"));
            abort();
            return false;
          }
          System.out.println("failure " + e);
          badLoginCount++;
          SessionFactory.getInstance().clearSessions();

          if (badLoginCount == NUM_INVALID_LOGINS) {
            Alert.error(Messages.getString("Login.tooManyBad"));
            abort();
            return false;
          } else {
            Alert.error(Messages.getString("Login.error"));
          }
        }
      }
    }
    return true;
  }
コード例 #15
0
 public static String getTimesheetStatusName(
     int
         status) { // used for display style in web, that's why I use underscores instead of dots
                   // for CSS compatibility
   return Messages.getString(getTimesheetStatusStyle(status));
 }
コード例 #16
0
 private UserInfoDialog(Frame owner) {
   super(
       owner,
       Messages.getContextString("Text.ApplicationTitle") + " Customer Information",
       true); //$NON-NLS-1$ //$NON-NLS-2$
 }