Java Code Examples for net.sf.mpxj.ProjectFile#getCustomFields()

The following examples show how to use net.sf.mpxj.ProjectFile#getCustomFields() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProjectTreeController.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Add custom fields to the tree.
 *
 * @param parentNode parent tree node
 * @param file custom fields container
 */
private void addCustomFields(MpxjTreeNode parentNode, ProjectFile file)
{
   for (CustomField field : file.getCustomFields())
   {
      final CustomField c = field;
      MpxjTreeNode childNode = new MpxjTreeNode(field)
      {
         @Override public String toString()
         {
            FieldType type = c.getFieldType();

            return type == null ? "(unknown)" : type.getFieldTypeClass() + "." + type.toString();
         }
      };
      parentNode.add(childNode);
   }
}
 
Example 2
Source File: AstaReader.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Constructor.
 */
public AstaReader()
{
   m_project = new ProjectFile();
   m_eventManager = m_project.getEventManager();

   ProjectConfig config = m_project.getProjectConfig();

   config.setAutoTaskUniqueID(false);
   config.setAutoResourceUniqueID(false);

   config.setAutoCalendarUniqueID(false);

   m_project.getProjectProperties().setFileApplication("Asta");
   m_project.getProjectProperties().setFileType("PP");

   CustomFieldContainer fields = m_project.getCustomFields();
   fields.getCustomField(TaskField.TEXT1).setAlias("Code");
   fields.getCustomField(TaskField.NUMBER1).setAlias("Overall Percent Complete");
}
 
Example 3
Source File: SynchroReader.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Reads data from the SP file.
 *
 * @return Project File instance
 */
private ProjectFile read() throws Exception
{
   m_project = new ProjectFile();
   m_eventManager = m_project.getEventManager();

   m_project.getProjectProperties().setFileApplication("Synchro");
   m_project.getProjectProperties().setFileType("SP");

   CustomFieldContainer fields = m_project.getCustomFields();
   fields.getCustomField(TaskField.TEXT1).setAlias("Code");

   m_eventManager.addProjectListeners(m_projectListeners);

   processCalendars();
   processResources();
   processTasks();
   processPredecessors();

   return m_project;
}
 
Example 4
Source File: SDEFReader.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override public ProjectFile read(InputStream inputStream) throws MPXJException
{
   Context context = new Context();
   ProjectFile project = context.getProject();

   CustomFieldContainer fields = project.getCustomFields();
   fields.getCustomField(TaskField.TEXT1).setAlias("Activity ID");
   fields.getCustomField(TaskField.TEXT2).setAlias("Hammock Code");
   fields.getCustomField(TaskField.NUMBER1).setAlias("Workers Per Day");
   fields.getCustomField(TaskField.TEXT3).setAlias("Responsibility Code");
   fields.getCustomField(TaskField.TEXT4).setAlias("Work Area Code");
   fields.getCustomField(TaskField.TEXT5).setAlias("Mod of Claim No");
   fields.getCustomField(TaskField.TEXT6).setAlias("Bide Item");
   fields.getCustomField(TaskField.TEXT7).setAlias("Phase of Work");
   fields.getCustomField(TaskField.TEXT8).setAlias("Category of Work");
   fields.getCustomField(TaskField.TEXT9).setAlias("Feature of Work");
   fields.getCustomField(TaskField.COST1).setAlias("Stored Material");

   project.getProjectProperties().setFileApplication("SDEF");
   project.getProjectProperties().setFileType("SDEF");

   context.getEventManager().addProjectListeners(m_projectListeners);

   BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));

   try
   {
      while (processLine(context, reader.readLine()))
      {
         // empty block
      }
   }

   catch (IOException ex)
   {
      throw new MPXJException(MPXJException.READ_ERROR, ex);
   }

   return project;
}
 
Example 5
Source File: SureTrakDatabaseReader.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override public ProjectFile read(File directory) throws MPXJException
{
   if (!directory.isDirectory())
   {
      throw new MPXJException("Directory expected");
   }

   try
   {
      m_projectFile = new ProjectFile();
      m_eventManager = m_projectFile.getEventManager();

      ProjectConfig config = m_projectFile.getProjectConfig();
      config.setAutoResourceID(true);
      config.setAutoResourceUniqueID(true);
      config.setAutoTaskID(true);
      config.setAutoTaskUniqueID(true);
      config.setAutoOutlineLevel(true);
      config.setAutoOutlineNumber(true);
      config.setAutoWBS(false);

      // Activity ID
      CustomFieldContainer customFields = m_projectFile.getCustomFields();
      customFields.getCustomField(TaskField.TEXT1).setAlias("Code");
      customFields.getCustomField(TaskField.TEXT2).setAlias("Department");
      customFields.getCustomField(TaskField.TEXT3).setAlias("Manager");
      customFields.getCustomField(TaskField.TEXT4).setAlias("Section");
      customFields.getCustomField(TaskField.TEXT5).setAlias("Mail");

      m_projectFile.getProjectProperties().setFileApplication("SureTrak");
      m_projectFile.getProjectProperties().setFileType("STW");

      m_eventManager.addProjectListeners(m_projectListeners);

      m_tables = new DatabaseReader().process(directory, m_projectName);
      m_definitions = new HashMap<>();
      m_calendarMap = new HashMap<>();
      m_resourceMap = new HashMap<>();
      m_wbsMap = new HashMap<>();
      m_activityMap = new HashMap<>();

      readProjectHeader();
      readDefinitions();
      readCalendars();
      readHolidays();
      readResources();
      readTasks();
      readRelationships();
      readResourceAssignments();

      return m_projectFile;
   }

   catch (IOException ex)
   {
      throw new MPXJException("Failed to parse file", ex);
   }

   finally
   {
      m_projectFile = null;
      m_eventManager = null;
      m_projectListeners = null;
      m_tables = null;
      m_definitions = null;
      m_wbsFormat = null;
      m_calendarMap = null;
      m_resourceMap = null;
      m_wbsMap = null;
      m_activityMap = null;
   }
}
 
Example 6
Source File: ProjectValueListsTest.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Test an individual project.
 *
 * @param file project file
 */
private void testProjectValueLists(File file) throws MPXJException
{
   ProjectReader reader = ProjectReaderUtility.getProjectReader(file.getName());
   if (reader instanceof MPDDatabaseReader)
   {
      assumeJvm();
   }

   DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
   ProjectFile project = reader.read(file);
   CustomFieldContainer container = project.getCustomFields();

   CustomField config = container.getCustomField(TaskField.COST1);
   CustomFieldLookupTable table = config.getLookupTable();
   assertEquals(3, table.size());
   assertEquals(1, ((Number) table.get(0).getValue()).intValue());
   assertEquals("Description 1", table.get(0).getDescription());
   assertEquals(2, ((Number) table.get(1).getValue()).intValue());
   assertEquals("Description 2", table.get(1).getDescription());
   assertEquals(3, ((Number) table.get(2).getValue()).intValue());
   assertEquals("Description 3", table.get(2).getDescription());

   config = container.getCustomField(TaskField.DATE1);
   table = config.getLookupTable();
   assertEquals(3, table.size());
   assertEquals("01/01/2015", df.format(table.get(0).getValue()));
   assertEquals("Description 1", table.get(0).getDescription());
   assertEquals("02/01/2015", df.format(table.get(1).getValue()));
   assertEquals("Description 2", table.get(1).getDescription());
   assertEquals("03/01/2015", df.format(table.get(2).getValue()));
   assertEquals("Description 3", table.get(2).getDescription());

   config = container.getCustomField(TaskField.DURATION1);
   table = config.getLookupTable();
   assertEquals(3, table.size());
   assertEquals("1.0d", table.get(0).getValue().toString());
   assertEquals("Description 1", table.get(0).getDescription());
   assertEquals("2.0d", table.get(1).getValue().toString());
   assertEquals("Description 2", table.get(1).getDescription());
   assertEquals("3.0d", table.get(2).getValue().toString());
   assertEquals("Description 3", table.get(2).getDescription());

   config = container.getCustomField(TaskField.NUMBER1);
   table = config.getLookupTable();
   assertEquals(3, table.size());
   assertEquals(1, ((Number) table.get(0).getValue()).intValue());
   assertEquals("Description 1", table.get(0).getDescription());
   assertEquals(2, ((Number) table.get(1).getValue()).intValue());
   assertEquals("Description 2", table.get(1).getDescription());
   assertEquals(3, ((Number) table.get(2).getValue()).intValue());
   assertEquals("Description 3", table.get(2).getDescription());

   config = container.getCustomField(TaskField.TEXT1);
   table = config.getLookupTable();
   assertEquals(3, table.size());
   assertEquals("Value 1", table.get(0).getValue());
   assertEquals("Description 1", table.get(0).getDescription());
   assertEquals("Value 2", table.get(1).getValue());
   assertEquals("Description 2", table.get(1).getDescription());
   assertEquals("Value 3", table.get(2).getValue());
   assertEquals("Description 3", table.get(2).getDescription());
}